10 Linux commands for beginners
24th Apr 2010 | 11:00
Master command line basics for free software heaven
Most Linux distributions include attractive graphical interfaces, but you can do a lot more from the command line interface once you know your way around.
For tasks like controlling and monitoring the distro's underlying system, the command line remains indispensable.
Using it, it's easy to configure and control everything from basic system setup, including network and boot, to graphical apps such as MPlayer.
Here are some commands that will elevate you from a total newbie to an informed command line user.
1. Monitor bootup
When you run into problems such as your graphics card not being detected or your network card not working, the bootup messages listed by dmesg are invaluable for helping you home in on the problem.
At the very least, they'll help you ascertain whether your Linux distro recognises the device attached to your machine. You can then probe these devices further with commands such as lspci and lsusb, depending on the port they're connected to.
2. Monitor system processes
Linux treats everything as a process. While you can use the top command to determine which process (or app) is using the most system resources, the ps command gives you much more information and can be used to control processes with precision.
3. Manipulate file permissions
For security, file permissions in Linux are divided into Users, Groups and Others. You can control the permissions assigned to users under each of these categories using the chmod command.
The permissions enable you to read, write or execute a file. This is handy when you want to run a script to install a package that isn't executable by default for security reasons.
The command chmod +x will make the script executable on your system.
4. Understand commands
The most useful tool for command line newbies is the man command, which provides a basic introduction to the various commands to help you understand their functions, and teaches you how best to use them.
When in doubt about which command to use, use the apropos command to search the man page descriptions for the specified keyword.
5. Manipulate archives
Linux offers many compression and archiving options other than good old ZIP. You'll often encounter Linux packages with '.tar', '.tar.gz' and '.tar.bz2' extensions. Try tar for a regular, uncompressed archive, while using gzip and bunzip2 will give you two different types of compressed archive.
6. Search on the CLI
When you can't remember where a particular config file is stored, or just want to search for a file, you can use either find or locate to determine where it is. While find traverses any specified directory, locate uses its updated database. Some commands are installed in non-standard directories, so use the whereis command to determine their installation directory.
7. Terminate processes
Linux apps sometimes fail to respond. If this happens, use the kill command to terminate the process. This requires the app's process ID, so you must use the ps command first to find this. You can then use this with kill to terminate the app.
For example, ps aux | grep firefox will give you the process ID for the Firefox browser (something like 18104), and kill 18104 will terminate it.
8. Root privileges
You'll often encounter these in tutorials. Only the root user has privileges allowing them to modify the system by installing or removing apps, configuring the network interface and so on. When you want to install an app as a normal user, you can use the sudo command to briefly acquire root user privileges.
9. Redirect output
While not a command, output redirection is an important skill to master when working on the command line. The tools required are the pipe (or |), and . These redirect output (normally printed on your screen) somewhere else, such as a text file or another app.
For example, the command ls | less redirects the output of the ls command onto less. Similarly, you can use the command ls > directory.txt to write the output of the ls command onto the 'directory.txt' file.
The redirection operative is used to write to the end of file.
10. Recall commands
You can use history to rerun a command. Entering this without any switches displays the history list with line numbers. You can also perform an incremental search of the history list.
Use [Ctrl]+[R] to perform a reverse search, or [Ctrl]+[S] for a forward search. As you type the first few letters, the last command from the history list that matches your string will be displayed.
First published in PC Plus Issue 293
Liked this? Then check out 8 of the best tiny Linux distros
Sign up for TechRadar's free Weird Week in Tech newsletter
Get the oddest tech stories of the week, plus the most popular news and reviews delivered straight to your inbox. Sign up at http://www.techradar.com/register