Various helpful one-liners

The commandline is an extremely powerful tool for doing a variety of useful things. This page provides a mixed list of these, that I use. The pipe (|) and redirection arrows (> and <) are also incredibly useful.

Listing files/directories ordered after size

This command list files/direcories (including subfolders) after their size. What directories hide uses a large disk-space?

du -sm *|sort -n

List files in reverse time order

Which file did I modify last in this directory?

ls -ltr

Which file did I modify last in this directory (show the last 20 files)

ls -ltr|tail -20

Using redirection

The redirection of output to a file can be done using one of the above commands and then send tthe data to a file.
Send the data to a file (if it exists all will be overwritten).

du -sm *|sort -n > /tmp/diskusage.txt

If we wish to append the data we use two greater than symbols (>>):

du -sm *|sort -n >> /tmp/diskusage.txt

Valid XHTML 1.0 Transitional