My Favourite Linux Commands

April 06, 2013
As a child of the DOS era, I've always been comfortable communicating with a computer without a mouse.  Most of my use of Linux is via a desktop environment (KDE and Xfce are my favourites), but I still like to be able to do certain tasks in a terminal window.  Here's a list of commands I use frequently, or just particularly enjoy:

blkid - Locate/print block device attributes. Sounds complex, but it lists the drives (block devices) connected to your computer.  Useful if you want to make a change to a drive and want to know its device designation, UUID, file format or label.  You must be root to see this.

cal - Displays a simple calendar in traditional format. With arguments, it can display past and future calendars:
[email protected]:~$ cal 08 1985
    August 1985 
Su Mo Tu We Th Fr Sa 
             1  2  3 
 4  5  6  7  8  9 10 
11 12 13 14 15 16 17 
18 19 20 21 22 23 24 
25 26 27 28 29 30 31
cat - Concatenates files and prints them to the standard output (screen). However, I usually use this command with /proc to query my memory and  cpu.  Try these at home:
[email protected]:~$ cat /proc/cpuinfo
[email protected]:~$ cat /proc/meminfo
free - Display amount of free and used memory in the system. Using -h makes it more "human readable" by showing output in  the shortest three digit unit:
[email protected]:~$ free -h
                   total  used  free  shared  buffers  cached
Mem:               3.9G   3.6G  248M      0B     179M    960M
-/+ buffers/cache:        2.5G  1.4G
Swap:              9.2G   258M  9.0G
The key info here is the slot where it shows 1.4 G free.  Linux actively borrows unused memory for disk caching to improve performance, so the number that includes the cache is the actual memory available.

grep - searches specified files for lines matching a given pattern. The Geek Stuff has some useful examples.

history - lists your 1000 most recently used  commands. Typing !(line number) repeats that command.  If you've typed the command very recently, there's no need to use the command for this list.  Just press your up arrow and the previous commands will appear in series on the line.

kill - kills a process (program) that's misbehaving or that otherwise needs to end ASAP.  Also see: top.

mlabel - Part of the mtools package, it's used for changing the label of MSDOS formatted devices, like your USB sticks.  When I need to add/change a thumb drive label, I become root, use blkid to check it's dev name, then use mlabel. Below, I label my new drive as Todd.
[email protected]:~# mlabel -i /dev/sdd1 ::Todd
top - lists (by amount of  cpu use) the  processes currently running. You can also use top to easily kill processes from its list by pressing K.

And lastly, I prefer package management from the CLI, App Stores and Software Centres be damned:

aptitude -  High-level interface to the Debian GNU/Linux package manager (also on Ubuntu and other variants). Here are a few examples of use:
aptitude update && aptitude upgrade
(refreshes the package list and updates all your OS and app software as necessary)
aptitude show foo
(shows description and other information about package "foo")
aptitude install foo
(installs package named "foo")
aptitude remove foo / aptitude purge foo
(removes package foo; purge will remove the package in addition to any configuration files that it produced).

To embark on your own adventure, LifeHacker has a plan for you to Master the Command Line This Weekend (or whenever else it's convenient).
Powered by Blogger.