Ten essential commands for Linux tasks
Published: 07 Aug 2009 09:00 BST
To be an effective Linux admin, you must have a few useful commands at your fingertips, says Jack Wallen.
However reluctant you are to use the command line in Linux — or for that matter, any operating system — the truth is that to be a good administrator, you have to know how to use it. With Windows there are times when the command line is the only thing that can save your skin. With Linux, the command line is vast, reliable, flexible and fast.
Of the 2,119 commands from the /usr/bin directory in Mandriva, spring 2008, and the 388 commands from /usr/sbin/, a few are indispensable. Here are 10 that might make your Linux admin life — or your introduction to Linux — far simpler. Rather than choose the most used commands, such as cd, ls and rm, I am picking the most useful ones, while remaining as distribution-neutral as possible.
1. Top
The top tool lists tasks that are running, and is the first command Linux users turn to when they need to know what is using their memory, or even how much memory a system has.
I often leave the top tool running on my desktop so I can keep track of what is going on at all times. Sometimes, I will even open up a terminal — usually aterm — place the window where I want it, and then hide the border of the window. Without a border, the terminal cannot be moved, so I always have quick access to the information I need.
Top is a real-time reporting system, so as a process changes, it will immediately be reflected in the terminal window. Top does have some helpful arguments, such as the -p argument, which will have top monitor only user-specified process ID numbers (PIDs) but, running default, top will give you all the information you need on running tasks.
2. ln
To many administrators, links are an invaluable tool that not only make users' lives simpler, but also drastically reduce disk-space usage.
If you are unaware of how links can help you, let me set out this simple scenario: you have a number of users who have access throughout the day to a large directory filled with large files on a drive. The users are all on the same system, and you do not want to have to copy the entire directory to each user's ~/ directory.
Instead, just create a link in each user's ~/ directory to the target. You will not consume space, and the users will have quick access. Of course, when spanning drives, you will have to use symlinks.
Another outstanding use for links is linking various directories to the Apache doc root directory. Not only can this save space, it is often advantageous from a security standpoint.
3. Tar, zip, gzip
Tar, zip and gzip are archival and compression tools that make your life as an admin far easier. I bundle these together because the tools can handle similar tasks, even though they do so with distinct differences — just not different enough to warrant their own entry here.
Without these tools, installing from source would be difficult. Without tar, zip or gzip, creating backups would require more space than you might often have.
Read this
Comment: Ten tips for fine-tuning Firefox
You can customise the behaviour of the Firefox browser with a few simple hacks, says Jack Wallen
One of the least used but most useful features of these tools is their ability to extract single files from an archive.
Zip and gzip handle this task more easily than tar. With tar, to extract a single file, you have to know the exact size of the file to be extracted.
One area where these tools simplify administration is in creating shell scripts that automate a backup process. All three tools can be used with shell scripts and are hands down the best, most reliable backup tools you will find.
4. Nano, vi, emacs
I would not cite just one text editor here, for fear of stoking the fires of the vi vs emacs war. I also thought it was worth throwing my favourite editor — nano — into the mix. Many would argue that these tools are less commands than full-blown applications, but they qualify for mention here because they are used within the command line.
Without a good text editor, administering a Linux machine can become problematic. Imagine having to attempt to edit /etc/fstab or /etc/samba/smb.conf with OpenOffice. Some might say this should not be a problem, but OpenOffice tends to add hidden end-of-line characters to text files, which can really wreck a configuration file. For the editing of configuration or bash files, the only way to go is with an editor such as nano, vi or emacs.
5. Grep
Many people overlook this amazingly useful tool. Grep prints lines that match a user-specified pattern. Say, for instance, you are looking at an httpd.conf file of more than 1,000 lines and you are searching for the AccessFileName .htaccess entry.
You could comb through that file only to come across the entry at line 429. Alternatively, you can issue the command grep -n "AccessFileName .htaccess" /etc/httpd/conf/http.conf. You will see "439:AccessFileName .htaccess", which tells you the entry you are looking for is on line 439.
The grep command is also useful for piping other commands to. An example of this is using grep with the ps command, which takes a snapshot of any processes running. Suppose you want to know the PID of a crashed Firefox browser. You could issue ps aux and search through...
Full Talkback thread
3 comments







