LinuxShort
Contents
- 1 Usefull short commands
- 1.1 Kill a process tree
- 1.2 Change sth inside file
- 1.3 Print rotated picture
- 1.4 Print in fixed width format with awk
- 1.5 Make a small size pdf out of several pdfs
- 1.6 Cut a portion of a pdf file saving resolution and sharpness
- 1.7 Make a series of single-page EPS files from various inputs
- 1.8 Cut a portion of a .pdf file
- 1.9 Extract particula pages from pdf file
- 1.10 Convert eps to jpg using native gs
- 1.11 Convert (e)ps to png or gif
- 1.12 Resize image
- 1.13 Screen command
- 1.14 Several images into one
- 1.15 Animation on .gif images
- 2 Some cool stuff
- 3 Install IRAF in Ubuntu 16 with Anaconda
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 from various inputs
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
Cut a portion of a .pdf file
Make a script named boundingBox.sh:
gs \ -q \ -dBATCH \ -dNOPAUSE \ -sDEVICE=bbox \ -dLastPage=1 \ $1 \ 2>&1 \ | grep %%BoundingBox
Call the script from the line with file_name as input:
./boundingBox.sh file.pdf
The result will be sth. like: %%BoundingBox: 42 510 305 746, where lower left img coords = (42,510) and upper right = (305,746). Finaly, to cut a box 305-42=263 px wide and 746-510=236 high, excluding 42 pixels from the left and 510 pixels from the bottom, make a script crop.sh:
gs \ -o out.png \ -sDEVICE=pngalpha \ -g$2x$3 \ -dLastPage=1 \ -c "<</Install {$4 $5 translate}>> setpagedevice" \ -f $1
where $1x$2=width x height and $4 $5 are the portion excluded from the left and bootom. In this example:
./crop.sh file.pdf 263 236 -42 -510
To make .pdf out try:
gs -o out.pdf -sDEVICE=pdfwrite -c "[/CropBox [42 510 305 746] /PAGES pdfmark" -f file.eps
Extract particula pages from pdf file
#!/bin/sh # # pdfsplit [input.pdf] [first_page] [last_page] [output.pdf] # # Example: pdfsplit big_file.pdf 10 20 pages_ten_to_twenty.pdf # # written by: Westley Weimer, Wed Mar 19 17:58:09 EDT 2008 # # The trick: ghostscript (gs) will do PDF splitting for you, it's just not # obvious and the required defines are not listed in the manual page.
if [ $# -lt 4 ] then echo "Usage: pdfsplit input.pdf first_page last_page output.pdf" exit 1 fi gs -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$4" -dFirstPage=$2 -dLastPage=$3 -sDEVICE=pdfwrite "$1"
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
name="imgName"; figdir="/home/..../Figures"; text="my image" 1. convert $name.ps -depth 8 -alpha off -density 600 2. convert $name.ps -depth 8 -alpha off -density 600 ${figdir}/${name}_large.gif 3. convert $name.ps -depth 8 -alpha off -density 600 -resize 320x240 ${figdir}/${name}_large.gif 4. convert $name.ps -depth 8 -alpha off -density 600 -gravity Southeast -font helvetica -pointsize 75 \ -draw "text 150,100 '$text'" ${figdir}/${name}_large.gif
1. Resulting image will be named as .eps and will end up at the same place.
2. Resulting image will be named imgName_large.gif and will be placed in \$figdir.
3. Additionally, image can be resized in the same step.
4. Put text into image
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 screen -S name -X quit # kill detached screen and return to a terminal ls -laR /var/run/screen/ # lists when the screens start running
Several images into one
montage img1.png img2.png img3.png img4.png img5.png img6.png -tile 2x3 -frame 2 -geometry +0+0 out.png
Animation on .gif images
convert -delay 50 img1.gif img2.gif -loop 0 anim.gif
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
Install IRAF in Ubuntu 16 with Anaconda
Source: https://www.anaconda.com/download/#_unix
First install the following libs:
sudo apt-get install libc6:i386 libz1:i386 libncurses5:i386 libbz2-1.0:i386 libuuid1:i386 libxcb1:i386 sudo apt-get install libxmu-dev:i386
Then download Anaconda from https://www.continuum.io/downloads
cd /home/<user_name>/ bash Anaconda2-4.4.0-Linux-x86_64.sh conda config --add channels http://ssb.stsci.edu/astroconda conda create -n iraf python=2.7 iraf-all pyraf-all stsci source activate iraf mkiraf <set to xgterm> cl ... source deactivate iraf
Pyraf also works in a standard way...