Posted: . At: 9:59 PM. This was 12 years ago. Post ID: 2745
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.

Linux commands that prove useful for your day to day workflow.

The UNIX tail command is very useful for viewing the last number of lines of a logfile.

As in this example. Showing the last 10 lines in the file /var/log/syslog.

|{~}-{Thu Feb 16 21:36:44}
-{john@deep-thought } $ tail -n 10 /var/log/syslog
Feb 16 21:31:01 deep-thought cron[1480]: (*system*anacron) WRONG FILE OWNER (/etc/cron.d/anacron)
Feb 16 21:31:29 deep-thought kernel: [34739.919485] device eth0 entered promiscuous mode
Feb 16 21:31:47 deep-thought kernel: [34758.095250] device eth0 left promiscuous mode
Feb 16 21:31:53 deep-thought kernel: [34764.193301] vboxnetflt: dropped 0 out of 7 packets
Feb 16 21:31:58 deep-thought kernel: [34769.069486] device eth0 entered promiscuous mode
Feb 16 21:32:01 deep-thought cron[1480]: (*system*anacron) WRONG FILE OWNER (/etc/cron.d/anacron)
Feb 16 21:33:01 deep-thought cron[1480]: (*system*anacron) WRONG FILE OWNER (/etc/cron.d/anacron)
Feb 16 21:34:01 deep-thought cron[1480]: (*system*anacron) WRONG FILE OWNER (/etc/cron.d/anacron)
Feb 16 21:35:01 deep-thought cron[1480]: (*system*anacron) WRONG FILE OWNER (/etc/cron.d/anacron)
Feb 16 21:36:01 deep-thought cron[1480]: (*system*anacron) WRONG FILE OWNER (/etc/cron.d/anacron)

The head(1) command will show the first ten lines in the file.

-{john@deep-thought } $ head -n 10 /var/log/dmesg
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Linux version 3.2.5-custom (root@deep-thought) (gcc version 4.6.2 (Ubuntu/Linaro 4.6.2-12ubuntu1) ) #1 SMP PREEMPT Tue Feb 7 21:54:11 EST 2012
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   NSC Geode by NSC
[    0.000000]   Cyrix CyrixInstead
[    0.000000]   Centaur CentaurHauls
[    0.000000]   Transmeta GenuineTMx86

I have also included some useful information here: http://www.securitronlinux.com/bejiitaswrath/using-redirection-on-the-command-unix-command-line/ discussing various tricks using redirection on the Linux command line.

Searching for a certain filename in your home folder. The locate command comes into its own for this when you need to find a certain file amongst all of the clutter that accumulates in your home directory.

|{~}-{Thu Feb 16 21:45:57}
-{john@deep-thought } $ locate freedoom
/home/thx/Doom2/freedoom.wad
/home/thx/Doom2/freedoomult.wad
/home/thx/Downloads/freedoom-iwad-latest.zip
/usr/share/app-install/desktop/freedoom:freedoom.desktop
/usr/share/app-install/icons/freedoom.png
/usr/share/games/freedoom
/usr/share/games/freedoom/freedm.wad

As seen in this example, I am searching for the freedoom wadfiles I have on my hard drive and I had forgotten where they were.

Generating a tree view in HTML of the current folder and subfolders.

|{~/Documents/CHASM}-{Thu Feb 16 21:55:03}
-{john@deep-thought } $ /usr/bin/tree -R -H ./

There are some more useful commands here: http://securitronlinux.com/linux-configurations/.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.