Linux command line cheat sheet

This post will be updated regularly with helpful linux command line .

Running short of disk space?

Finding those large files tucked away in some dark corner of your machine is easy with this command.

cd /path/to/where/you/want
du -hsx * | sort -rh | head -10

  • du command -h option : display sizes in human readable format (e.g., 1K, 234M, 2G).
  • du command -s option : show only a total for each argument (summary).
  • du command -x option : skip directories on different file systems.
  • sort command -r option : reverse the result of comparisons.
  • sort command -h option : compare human readable numbers. This is GNU sort specific option only.
  • head command -10 OR -n 10 option : show the first 10 lines.

Finding a string in a file

Simple one this but I always seem to forget the switches

grep -H -r -i "redeem reward" /home/gerbil

  • grep command -H option : do not print matching lines just file name
  • grep command -r option : recursive
  • grep command -i option : ignore case

Finding a string in a file with a specific extension

Grep specific file extensions for a string. The syntax for --exclude is identical.

grep pattern -r -i --include=\*.{cpp,h} rootdir

Stop crazy line overwriting when using putty terminal

shopt -s checkwinsize

Form not submitting using javascript method

It never ceases to amaze me that with all the time I have spent developing web pages new and mind boggling foibles are waiting to bite you in the rear.

I had a simple HTML form with a onchange=”this.form.submit()” on a select drop down which was not submitting when the value was changed. The form was structured correctly and the page was validated against the doctype. After a few minutes on Google I had my answer, do not name the form submit button “submit” because it conflicts with internal form properties. This page gives more detail in the “additional notes” section.

http://api.jquery.com/submit/#entry-longdesc