Stjepan Groš

Unix tips & tricks

Stuff collected from different places. Majority of this came from the one Slashdot discussion. It occured to me that it would be very useful to add this stuff to a login screen, e.g. while waiting for a GNOME or KDE to fully load. I don't know if there is something already implemented, though I know that, at least for a command line, there is a program named fortune.

All your comments, criticisms and a like please send me on my e-mail address!

Shells and command line processing

Common to all shells

bash

Time and date

Fork bombs

Manipulating text files

Funny

Not sorted yet

Here are some tips that I didn't sort anywhere yet, but many of them are very usefull!

Monitoring file changes

Many times it happens that you have to watch log file to see new messages appearing. To do this you can use tail command. Monitor log /var/log/messages without showing anything that was logged before you started command:

# tail -f -n0 /var/log/messages

If you omit -n0 option, tail will show the last 10 lines from the file before waiting for new records. In case you want to monitor file that doesn't exist jet, use capital F like this:

# tail -F /var/log/somelogfile

You can also use less to do the same thing. Start less on a file and then press SHIFT+F.

Disk usage

To find out the sizes of directories in a current directory sorted in ascending order you have several options:

$ du -sk * | sort -k 1,1n
$ du -sk * | sort -n
$ du --max-depth=1 | sort -n

Periodically run commands

If you wish to run some command every N seconds use watch command, e.g.:

$ watch -n 3 ls -l

Will list current directory every 3 seconds. Note that this is specific to Linux.