Cheat sheet
- script to execute a command in all subdirectories
- YOUR_TOP_LEVEL_FOLDER=$PWD
- for dir in `ls $YOUR_TOP_LEVEL_FOLDER`;
- do
- cd $YOUR_TOP_LEVEL_FOLDER/$dir
- echo $PWD
- # Command
- done
- To mount directory from a remote machine
- sshfs user@machine:absolute_path target_directory
- To unmount it
- fusermount -u directory
- To see a running process
- ps -ef |grep Process_name
- Kill all processes
- kill -9 -1
- To synchronize
- rsync -avz --exclude='files' source destination
- Finding files and processing
- find DIR -name 'file_name' -exec COMMAND {} \;
- Finding difference between two folders
- diff -rq folderA folderB
- sed examples
- Find and replace strings in a file using sed
- sed -i 's/text_old/text_new/g'
- Replacing text on specific line(s)
- sed -i '32c 5.0'
- printing a particular line
- sed -n '32p' file
- Deleting lines
- sed -i '1,3d' file
- Find and replace strings in a file using sed
- To avoid segmentation faults when running code with large arrays
- ulimit -s unlimited: sets the stack size to unlimited
- To dump the svn repository
- svnadmin dump /home/syed/svn > dump_file
- To add new file to a svn repository
- svn add file_name (after adding, a svn commit has to be done)
- Customizing shell prompt
- Shell prompt (e.g. [syed@mm24 src]$ ) is stored in the environmental variable PS1. Set it as you wish, e.g. PS1='[\u@\h \w]\$'
- Running a command with reduced priority(19(-19) lowest(highest))
nice -n 19 command-name
- To see hostname of a machine using ip-address use 'nslookup'
- To compress huge avi files
- mencoder old_file.avi -o new_file.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4:mbd=1:vbitrate=3800
- mencoder old_file.avi -o new_file.wmv -ovc copy -ovc lavc -lavcopts vcodec=wmv2:mbd=1:vbitrate=2800
- see http://wiki.quakeworld.nu/Mencoder_howto
- Embedding fonts in pdf file
- dvips -t a4 paper.dvi
- ps2pdf -dPDFSETTINGS=/prepress -dEmbedAllFonts=true paper.ps
- Merging pdf files (http://www.linux.com/archive/feed/36815)
- gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf file1.pdf file2.pdf
- extract frames from a movie
- ffmpeg -i inputfile.avi -r 1 -f image2 image-%3d.jpeg
- Delete all files inside remote directory using ssh
ssh HOSTNAME rm -rf "/path/to/the/directory/*"
- how to combine two seperate videos into one left-right video
- How to download all files from a website using wget
wget -A pdf,jpg -m -p -E -k -K -np http://site/path/
- Convert avi to gif
- mkdir frames
- ffmpeg -i Video\ 3.wmv frames/ffout%03d.png
- Delete if too many frames: find . -maxdepth 1 -not -iname "*1.png" -exec rm {} \;
- convert -delay 10 -loop 10 frames/ffout*.png output.gif
Gnuplot
Gnuplot
- "Fractions" in gnuplot for y axis labels: Put characters on top of each other using '~' and draw a line.
- set ylabel '{/Symbol ~{s}{1.2s}}_{~Y{1.5xy}}' rotate by -0 font 'Times-Italic'
- set arrow nohead from -6.27, 0. to -5.79,0.
- set ylabel "{/*1.2 { /Symbol,45 s_{qq}}}\n{\261\261\261\n}{/*1.2{/Symbol,1 s^\245}}" rotate by 0 offset 2
- set ylabel '{/Symbol ~{s}{1.2s}}_{~Y{1.5xy}}' rotate by -0 font 'Times-Italic'
- Gnuplot use of "every I:J:K:L:M:N" (from: http://t16web.lanl.gov/Kawano/gnuplot/datafile2-e.html