Updated 19 hours ago

10 Linux commands for beginners

In Depth: Master command line basics for free software heaven

April 24th 2010 | Tell us what you think [ 4 comments ]

mayank-sharma

Mayank Sharma is a Linux expert who believes in free software and an easy life for all

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.

man command

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

Follow TechRadar on Twitter

 

Your comments (4) Click to add a new comment

nadanewb


April 26th 2010

4. Wow. No offense my friend, but this is exACTly why I stick with scripting in windows/dos command-line. Don't feel bad. It's nothing personal, and I like your writing style. But this is really just another assumptive Linux article. Your section "7. Terminate Process" was an amazing case in point. I'll paraphrase so you'll understand the way this reads to one who doesn't know how to do any of this yet:

...Just use "kill". Oh, you have to know the code. Just use "ps" to get that. Oh, you also have to know what "aux" and "grep" are, and how to use them. I won't tell you that, though, or how to find out. And that pipe, that you might know about already from other scripting, I'll tell you about that later...

This is why non-computer folk hate geeks.

Alert a moderator

yetanothergeek


April 26th 2010

3. "Linux treats everything as a process"

The word "everything" here seems like a stretch - /dev/sda1 is not a process. It might make more sense to say "Linux treats every running program as a process"

"you can use the top command to determine which process..."

The word "top" should be boldface, otherwise the newbie will see it as just another adjective.

"This is handy when you want to run a script to install a package that isn't executable by default for security reasons."

It's handy when you want to run a script that isn't executable, period. The part about "to install a package" just makes the sentence harder to understand.

"Try tar for a regular, uncompressed archive, while using gzip and bunzip2 will give you two different types of compressed archive."

gzip and bunzip2 are for compressed files, not necessarily archives. If you want to work with a '.tar.gz' or '.tar.bz2' file, it is much easier to simply use the -z or -j options

to the tar command. For newer versions of tar, the -a option can usually guess the compression format automatically.

BTW, slackware and archlinux now both use "tar.xz" as their default package format.

"Search on the CLI"

Should probably also mention the "which" and "type" commands.

"When you want to install an app as a normal user, you can use the sudo command to briefly acquire root user privileges. "

Not all distros have sudo installed by default, some even consider it a security risk. You should mention using "su" as an alternative to "sudo".

"The tools required are the pipe (or |), and ."

"The redirection operative is used to write to the end of file."

It looks like the "greater-than" symbols are missing here, I assume they were somehow mangled by some HTML sanitizer, but I doubt that any newbie would realize that.

I also think the actual meaning of appending a file could use a bit more explanation.

"The most useful tool for command line newbies is the 'man' command"

Oh dear, now they're really in trouble ;-)

Alert a moderator

mrmarks


April 26th 2010

2. yeah i agree, something like iwconfig for viewing wireless network data, dpkg -i [filename] or apt for installing packages.

just a thought :P

Alert a moderator

campbell2644


April 25th 2010

1. Sorry but I doubt that beginners will make any sense of this article at all.

Alert a moderator

Tell us what you think

You need to Log in or register to post comments

By submitting this form you agree to our Terms of Use and so are legally responsible for anything you submit. DO NOT submit anything which may violate the Terms of Use or another person's rights including copyrighted or offensive materials.