Thursday, May 22, 2014

Useful commands

This post summarizes few interesting and useful commands, some of them are from commandlinefu page.


Capture video of a linux desktop:
  • ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg
Watch Network Service Activity in Real-time
  • lsof -i
Close shell keeping all subprocess running
  • disown -a && exit
Sharing file through http 80 port
  • nc -v -l 80 < file.ext
Put a console clock in top right corner
  • while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done &
Send a message to everybody’s terminal
  • wall [message]
Add Password Protection to a file your editing in vim
  • vim -x <FILENAME>
How to copy CD/DVD to hard disk (.iso)
  • dd if=/dev/cdrom of=whatever.iso
  • readom dev=/dev/scd0 f=/path/to/image.iso
Create a pdf version of a manpage
  • man -t manpage | ps2pdf - filename.pdf
Remove security limitations from PDF documents using ghostscript
  • gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=OUTPUT.pdf -c .setpdfwrite -f
Run a file system check on your next boot
  • sudo touch /forcefsck
Print a specific line from a file
  • sed -n 5p <file>
Convert PDF to JPG
  • for file in `ls *.pdf`; do convert -verbose -colorspace RGB -resize 800 -interlace none -density 300 -quality 80 $file `echo $file | sed 's/\.pdf$/\.jpg/'`; done
Press Any Key to Continue
  • read -sn 1 -p "Press any key to continue..."
A child process which survives the parent's death (for sure)
  • ( command & )
Pretend to be busy in office to enjoy a cup of coffee
  • cat /dev/urandom | hexdump -C | grep "ca fe" (this is CPU consumming)
  • while [ true ]; do sleep 1; head -n 100 /dev/urandom | hexdump -C | grep "ca fe"; done
Guess the number...
  • A=1;B=100;X=0;C=0;N=$[$RANDOM%$B+1];until [ $X -eq $N ];do read -p "N between $A and $B. Guess? " X;C=$(($C+1));A=$(($X<$N?$X:$A));B=$(($X>$N?$X:$B));done;echo "Took you $C tries...";
Simple http server on 8080 (all interfaces)
  • python -m SimpleHTTPServer 8080
Currently mounted filesystems in nice layout
  • mount | column -t
Make 'less' behave like 'tail -f'
  • less +F somelogfile
  • Using +F will put less in follow mode. This works similar to 'tail -f'. To stop scrolling, use the interrupt. Then you'll get the normal benefits of less (scroll, etc.). Pressing SHIFT-F will resume the 'tailling'.
Display number of connections to MySQL DB
  • mysql -u root -p -BNe "select host,count(host) from processlist group by host;" information_schema

No comments:

Post a Comment