LinuxShort
From MediaWiki
Usefull short commands
Kill a process tree
When some script is started from a command line in a for-loop and a process tree is made, one should find the parent process and its PID and then simply kill it:
$ pstree username -p sshd(19953)---bash(19954)---bash(22238)---idl(22323)-+-{idl}(22326) |-{idl}(22327) |-{idl}(22328) `-{idl}(22329) sshd(20096)---bash(20097) sshd(20762)---bash(20763) sshd(21087)---bash(21088)-+-grep(21309) `-top(21308) sshd(21736)---bash(21737) sshd(21780)---bash(21781)---pstree(22331)
Or if this tree is to long, one should grep the program (here:idl) with: $ pstree usrname -p | grep idl
$ kill 19953 $ pstree username -p sshd(20096)---bash(20097) sshd(20762)---bash(20763) sshd(21087)---bash(21088)-+-grep(21309) `-top(21308) sshd(21736)---bash(21737) sshd(21780)---bash(21781)---pstree(22332)
Change sth inside file
sed -i s/'\-9999'/'NaN'/g filename
This will change -9999 with NaN inside a file, without making some tmp file in between.
Print rotated picture
lp -o media=a4 -o orientation-requested=4 -o fitplot figure.ps
Print in fixed width format with awk
echo $a $b $c | awk '{for (i=1; i<=NF; i++) printf("%-20s ",$i);printf ("\n")}' > outfile.dat
where strings a,b,c may be entire lines.
Make a small size pdf out of several pdfs
gs -sDEVICE=pdfwrite -q -dNOPAUSE -dBATCH -sOutputFile=MajorFile.pdf SmallFiles*.pdf
Combined files can ba a mix of .pdf .ps and .eps files and output file can be a .ps also
Cut a portion of a pdf file saving resolution and sharpness
gs -g2700x3500 -sOUTPUTFILE=output.pdf -sDEVICE=pdfwrite -dBATCH -c "<< /PageOffset [-30 -120] >> setpagedevice" -f input.pdf
Where [-30 -120] means - shift the content of the old image to its left corner by (x,y)=(30,120) pixels (change the origin of the image) and 2700x3500 are the dimensions of the new image. Be careful - input.pdf should be a single page.
Make a series of single-page EPS files made up of pages from various input files
gs -sDEVICE=epswrite -q -dNOPAUSE -dBATCH -dSAFER -sOutputFile=p%08d.eps 5page-first.pdf 7page-second.ps 1page-third.eps
The resulting files will be nicely named as p00000001.eps .... p00000013.eps
Convert eps to jpg using native gs
gs -sDEVICE=jpeg -q -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r100 -sOutputFile=image.jpg image.eps # -r100 should be changed to -r50 for denser image
Convert (e)ps to png or gif
mogrify -format png -depth 8 -alpha off -density 600 -resample 150 image.(e)ps mogrify -format gif -depth 8 -alpha off -density 600 -resample 150 image.(e)ps
Resulting image will be named as .eps and will end up at the same place.
Resize image
mogrify -trim -resize 70% image.jpg # or -resize 800x600 for fixed width
Screen command
screen -S name # name a screen screen -ls # list all screens (those named will be easily read) Ctrl+a+d # detach screen screen -r name # attach to a screen Ctrl+a+k # kill screen and return to a terminal
Some cool stuff
- Very nice themes for Ubuntu 10.04
sudo add-apt-repository ppa:bisigi sudo aptitude update sudo aptitude install bisigi-themes
- Convert youtube .flv to .mp3 (FORUM)
sudo apt-get install youtube-dl sudo youtube-dl -U sudo youtube-dl -U sudo apt-get install ffmpeg libavcodec-unstripped-52 sudo apt-get install ubuntu-restricted-extras # Example: youtube-dl http://www.youtube.com/watch?v=Md7IhGYKncs ffmpeg -i Md7IhGYKncs.flv -acodec libmp3lame -ab 128 indiana.mp3