Ten essential commands for Linux tasks

Daily Newsletters

Sign up to ZDNet UK's daily newsletter.

COMMENT

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.

One of the least used but most useful features of these tools is their ability to extract single files from an archive.

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

Read more +

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...

Talkback

shutdown -h now
Remember, an off computer is a happy computer!
An off computer, will cause your users no problems at all.

openhgs 7 August, 2009 22:24
Reply

10 great new pizza toppings
10 tips on how to reconfigure your beard
10 tips on how to speak to girls
10 tips on how to tell users to &$%! off without them knowing

dogStar 10 August, 2009 09:45
Reply

The find command allows users to search a given file/directory/link name recursively into the Unix/Linux tree, from any starting location.

Find, through the -exec option, can also execute another command recursively. It is highly convenient with the grep one.

psh 17 August, 2009 09:26
Reply

Post your comment

In order to post a comment you need to be registered and logged in.

You can also log in with Facebook. Log in or create your ZDNet UK account below

  • Login

Will not be displayed with your comment

By signing up for this service, you indicate that you agree to our Terms and Conditions and have read and understood our Privacy Policy. Questions about membership? Find the answers in the Community FAQ

Get ZDNet UK's daily newsletter

Enter your email address to sign up

ZDNet UK Live

Roberto_Store

Now On Sale, Unlocked iPhone 4S / Galaxy Note In Factory Box. Roberto-Techie(UK) ”Now on Sales” Smartphone, Android,Tablets,Gadget &...

3 hours ago by Roberto_Store on Samsung Galaxy S III lined up for sale
Paul Smyth

Is this classic FUD? One thing I would definitely have notice is a Mozilla threat to stop supporting GNU/Linux.

5 hours ago by Paul Smyth via Facebook on Firefox rapid release improves Fedora Linux
UnderINK

I agree with the previous commenter wholeheartedly. I couldn't say it better myself. This is very 'Big Brother'. And while I agree with protecting...

9 hours ago by UnderINK on European e-identity plan to be unveiled this month
Simon Bisson and Mary Branscombe

Nice to see that Turing's idea of a general purpose computer doing once-hardware-powered tasks in software is now universal ;-) Mary

14 hours ago by Simon Bisson and Mary Branscombe on Software with everything
Jason Burchell

seriously now. I've only bothered to read a small bit of the comments. do me and the rest of the world a favour. stop saying it does not work or...

18 hours ago by Jason Burchell via Facebook on Music industry negotiating over 24-bit downloads
Philip Charles Cohen

Read about it and weep, John Donahoe ... In addition to Visa’s V.me, there is now MasterCard’s PayPass digital wallet soon to arrive; another...

22 hours ago by Philip Charles Cohen via Facebook on PayPal takes phone-based payments to the high street
apexwm

Leslie Satenstein : Where have you ever seen Mozilla even mention this? Firefox is the most popular browser in the GNU/Linux OS, so I don't see...

23 hours ago by apexwm on Firefox rapid release improves Fedora Linux
songmaster

SHleG: Do you remember building a clockwork scorpion kit (I'm pretty sure I have a photo of it somewhere) — I think it was called something like...

1 day ago by songmaster on Software with everything
Chris Wortman

Good I love Yahoo! Their search engine is getting better than Google as of late. I find more of what I want on the first page, and usually within...

1 day ago by Chris Wortman via Facebook on Linux Mint 13 ramps up for KDE release
PatrickG

openhgs has made the point for Windows 8 multiple monitors without realising it! With Windows 7 you have to switch the mouse and so your focus...

1 day ago by PatrickG on Windows 8 could speed multi-monitor uptake
Leslie Satenstein

Mozilla has threatened to stop supporting Linux. I guess that UBUNTU is going with another browser. I indicated that if Mozilla stops supporting...

1 day ago by Leslie Satenstein via Facebook on Firefox rapid release improves Fedora Linux
Andy Bolstridge

Much as I abhor Microsoft's licensing practices, this is almost certainly down to purchasing IT equipment via 3rd party consultants - you get the...

1 day ago by Andy Bolstridge via Facebook on 6 million wasted licences and £1,200 PCs: welcome to government IT
Jack Schofield

@openhgs Windows users have had multiple desktops since Linus started writing Linux. They just haven't shipped as standard because not enough...

2 days ago by Jack Schofield on Windows 8 could speed multi-monitor uptake
Jack Schofield

@Phil at Cloud4 What, Microsoft gets £1,200 per PC and £1,622 per server? Gosh, I'm amazed....

2 days ago by Jack Schofield on 6 million wasted licences and £1,200 PCs: welcome to government IT
craigsc

You guys have no idea what is going on at Autonomy. Autonomy could have been a much more profitable organization. The sales operations at Autonomy...

2 days ago by craigsc on HP cuts 27,000 staff as Autonomy chief Lynch leaves
Moley

How does this impact on dual or multi booting? Seems to me to more or less prohibit this, from Windows 8 anyway. Will Grub 2 recognise Windows 8,...

2 days ago by Moley on Windows 8 start-up speed forces USB boot workaround
apexwm

I don't understand why there cannot be a slight pause during the boot process so the user can press a key. Many operating systems do this, even if...

2 days ago by apexwm on Windows 8 start-up speed forces USB boot workaround
Gavin Goodman

You can now buy the Xi3 modular computer in the UK at http://www.ocdistribution.com . This can be bought with the Tand3m software, pricing and...

2 days ago by Gavin Goodman on CES 2012: Xi3 microSERV3R
Phil at Cloud4

I agree: Mike Lynch can clearly build a business and manage strategy. I suspect the exit of Mike is more likely the end of a planned handover...

2 days ago by Phil at Cloud4 on HP cuts 27,000 staff as Autonomy chief Lynch leaves
Phil at Cloud4

This is unbeleivable government wastage with only one winner... Microsoft 1 - Tax payer Nil!

2 days ago by Phil at Cloud4 on 6 million wasted licences and £1,200 PCs: welcome to government IT