Flipping the Linux switch: New users guide to the terminal
All right, so maybe it's not horror movie material.
But it is intimidating for many new users. Navigating the command line might be a mystery to you, or maybe you've read a little about it and wonder: out of all those commands, which ones am I really going to use? Which ones are the most help in a given situation?
Either way, we've got you covered. These are the commands we've found are most useful to new users. They range from basic navigation to commands that are great for troubleshooting.
There are two major navigation commands. There are more, of course, but these two will have you tooling around your computer in no time.
cd is the change directory command. When you open a terminal, you're in your home directory. Typing cd Desktop at the prompt will move you into your Desktop directory. To move back to the home directory, you can type cd ../ at the prompt.
ls will list the files and folders in a given directory. You can list the contents of your home directory by simply typing ls at the prompt. Or, while still in your home directory, you can view the contents of another folder by typing ls /etc/X11/ at the prompt.
Not so scary, huh?
But wait, there's one more. While not exactly a navigation command, this does come in handy when looking for certain files:
grep is a great tool for searching text on your system. You can search individual files, using wildcards, or search directories recursively (all sub-directories under a given directory are searched). We don't use grep as much alone, we've found, as we do in conjunction with other commands.
grep -r Monster *
This command returns all of the files with the word Monster occurring in the present directory and all its subfolders.
grep -i "penguins rule" filename1 filename2
This searches for the text string "penguins rule" (case-insensitive) within the two supplied files.
These are some of our most loved troubleshooting commands. We don't use them every day, but they're a quick and easy way to get the diagnostic process rolling on something that's acting a little flaky. If you should need to ask for help on a forum or mailing list, it's often good to have the output of these commands ready to cut and paste into your post.
dmesg is the command that lists kernel messages. The kernel is the core of the operating system, and interacts closely with your hardware. When a piece of hardware is detected by the kernel, it logs a little bit about the hardware.
As you've probably guessed, this comes in really handy when troubleshooting devices. dmesg needs to be run with additional commands to tell it what you really want to see. Just running dmesg alone will get you every single kernel message. Great if you're totally obsessed with your kernel, but pretty frustrating when you're looking to see if your TV tuner or USB device has been recognized.
So how do we tell if our USB device has been recognized, and avoid a million lines of stuff we don't need? We use the pipe command (|) and the grep command with it.
dmesg | grep usb
If you want a case-insensitive search, add the -i argument to grep (not dmesg).
dmesg | grep -i usb
What if you don't really know what's going wrong, but want to see the whole of the dmesg file? You can access the file at /var/log/dmesg with a text editor. Or you can pipe the less command to dmesg.
dmesg | less
This will display dmesg in easy to read sections. Okay, it'll display dmesg in sections. Whether they're easy to read or not is up for debate.
lsmod lists kernel modules (sort of like drivers, in a loose sense) that are active on the system. If you have installed a new graphics card, for instance, and you're unsure of whether your new drivers loaded you can use the lsmod command to find out. lsmod can also be piped through less, but sometimes it does fit in a single terminal screen. Know the name of the module you're looking for? Pipe lsmod through grep: lsmod | grep -i nvidia
uname gives details about the operating system. There are a number of command arguments (additional commands) that can be added to uname, which return data about different aspects of the system. Using the -a argument will return all the data uname has about a system.
For instance, uname -a on our 64-bit Xubuntu computer returns this:
Linux shoe-desktop 2.6.22-14-generic #1 SMP Tue Dec 18 05:28:27 UTC 2007 x86_64 GNU/Linux
This is (in order) the name of the kernel, the name of the computer, the version of the running kernel, the processor type, and the name of the operating system.
This is useful when compiling applications from source. Sometimes, though, you'll need to know the kernel you're running for troubleshooting other issues.
The man pages are the first place to go when you're looking for help. The man command gives access to your computer's online documentation (manuals... get it?). If you need to see additional arguments for uname, for instance, open a terminal and type man uname. The man page will give you a basic run down on how to use the command, what package it is bundled with, and sometimes cross-references similar commands that may be useful.
The command line doesn't have to be a source of intimidation for the new user. It doesn't require memorizing a whole book's worth of commands to use effectively. Because it's fast, and gives a lot of valuable feedback, you'll even find (eventually) that you'll use it for certain tasks rather than using a GUI counterpart.
Command line anxiety could soon go the way of your other unfounded fears. The monster under the bed. The bogeyman in the closet. Clowns. (No, there are still lots of reasons to fear clowns.)