A guide to Java, Linux, and other Technology topics

Tips

Eclipse

  • A lot of people know that hitting ctrl-p while the cursor is at a brace will take the cursor to the matching brace, however, not that many people know that double clicking just to the right of an opening or closing curly brace will highlight all the text inside that brace.
  • Alt+up arrow/alt+down arrow will copy any highlighted block of text to the appropriate position.
  • Ctrl+alt+up arrow/ctrl+alt+down arrow will copy any highlighted block of text to the appropriate position.

Linux

  • A lot of command line parameters accept the "-h" switch to display output in human readable form, for example, "ls -lh" displays the sizes of the files in megabytes or gigabytes, as appropriate. This switch works with du (used to determine the disk usage of a directory), df (used to determine the free space of a partition) and many other commands.
  • Passing the "-S" switch to the "ls" command will sort the output by file size, extremely handy in combination with the "-h" switch from the previous tip. These two switches can be combined to display file sizes in human readable form and sort by file size, the command to do this is "ls -lSh".
  • To reverse the order of the output of the ls command, the "-r", switch can be passed to it. Again, this switch can be combined with others for maximum control, for example, to list all files in a directory, sorted by size from smallest to largest, the command would be "ls -larth".
  • To find files containing a specific string, the find and grep commands can be combined as follows: "find . -name '*.txt' |xargs grep -i 'foo'". In this example, the output would be all files ending in ".txt" containing the string "foo".
  • To find the 10 most CPU intensive processes, the following command will do the trick: ps -eo pcpu,vsz,args,time | sort -rn | head -11
  • To view all directories in a parent directory without listing these directories contents, ls -d */ will do the trick.