An Introduction to the Linux Command Line

command line question mark   An Introduction to the Linux Command LineNow it’s time to discuss one of the most mysterious and confusing parts of Linux to a Windows user: the command line.

To most Windows users the prospect of typing in what you want your computer to do is completely foreign and thus intimidating. It’s so intimidating in fact that Linux developers have poured countless hours into designing GUIs (graphical user interfaces) to imitate and/or replace text-based commands. But sometimes the command line is still the fastest, easiest, or only way to get something done.

What is this “Linux Command Line”?

A command line is a method of interacting with your computer that involves typing commands (that is, words and phrases that have meaning to the computer) to make it do things. Command line interfaces replaced punch card systems back in the 1950′s and subsequently made room for GUIs. Today all three major operating systems –Windows, Mac OS X, and Linux– have command line interfaces to go along with their GUIs, although Linux tends to rely on the command line more than the other two. (That being said, you can still do plenty with your system without ever touching the command line.)

Why Should I Use it?

Everyone will agree that the command line was a great invention and it served many early PC users well. But with our constant rush for the latest technology, many regard the command line as archaic and useless as a steam powered automobile. I disagree and I’m certainly not alone. Here are a few reasons it may come in handy:

    1. It’s fast – “productivity” is a word that gets tossed around a lot by so-called power users, but the command line can really streamline your computer use, assuming you learn to use it right.

    2. It’s easier to get help – The command line may not be the easiest thing to use, but it makes life a whole lot easier for people trying to help you and for yourself when looking for help, especially over the internet. Many times it’s as simple as the helper posting a few commands and some instructions and the recipient copying and pasting those commands. Anyone who has spent hours listening to someone from tech support say something like, “OK, now click this” knows how frustrating the GUI alternative can be.

    3. It’s nearly universal – There are hundreds of Linux distros out there, each with a slightly different graphical environment. Thankfully, the various distros do have one common element: the command line. There are distro-specific commands, but the bulk of commands will work on any Linux system.

    4. It’s powerful – The companies behind those other operating systems try their best to stop a user from accidentally screwing up their computer. Doing this involves hiding a lot of the components and tools that could harm a computer away from novices. Linux is more of an open book, which is due in part to its prominent use of the command line.

OK, so what do I need to know?

Truly mastering the command line, like anything, takes plenty of time and practice. Entire books and websites have been written on the subject, but we can at least cover the basics here.

Navigate the file system – Like Windows, Linux uses a system of folders and files to organize data. When you first open a terminal you will be, by default, in the home folder. Enter the pwd (print working directory) command to make sure and it should output something like /home/user_name. Enter ls to list all the files and folders in your home folder. If you’ve been using your OS for a while your home folder is likely full of files and folders.

Rummage through the debris and you should find the Desktop folder. Let’s take a look at that. Type cd (change directory) and the directory name to go to any place on your computer. In this case we want to go to the Desktop directory, but there are three ways of writing its “address”: The long way, /home/user_name/Desktop, and the two shorthand ways, ~/Desktop, ./Desktop. The tilde (~) is shorthand for “/home/user_name,” while the period is shorthand for the current directory. Sound confusing? If so then I suggest just using the longhand way for now.

screenshot abrahamabraham desktop desktop   An Introduction to the Linux Command Line

A few simple tasks – Using the ls command in my Desktop directory returns that I have a couple of cute cat pictures there that I just downloaded. Well, I want to get them off my desktop and into their own folder. So first I’ll enter “mkdir ~/cats” to make a directory called “cats” in my home directory. Now to move the two pictures to the new cat directory I enter “mv ./Fluffy.jpg ./mr-jingles.jpg ~/cats”. It may seem confusing, but it simply tells the computer to move the two pictures (the .jpg files) from the desktop to the “cat” folder in the home folder. You can also use the cp command instead of mv to copy the pictures without changing the originals on the desktop. Should I ever feel the need, I can use the “rm /path/to/files/” command to remove them. Please note, however, that using this command does not put the file in the trash bin, but instead deletes it forever.

A little miscellaneous info – Most commands (if not all) have a variety of options you can use to change the way the command works. Enter “[command] -[option letter]” to use options. Enter “man [command]” to open a command’s manual page and learn a bit about what a specific command does as well as its particular options. Lastly is the concept of root user. Some commands (particularly ones that could harm your computer if used recklessly or with malice) require you to become root user beforehand, using either the su or sudo commands.

A warning – The command line is great, but as Uncle Ben from Spider-Man says, “With great power, comes great responsibility.” So please do not enter any commands that you know absolutely nothing about. Be wary of copying and pasting questionable commands off the internet. Be especially wary of the rm command since you may cause irrevocable damage to your system and data. I hope this doesn’t discourage you, but instead prompts you to use a bit of caution when dealing with the Linux command line.

Where do I go from here?

Those are the absolute basics, but there is still so much to learn. There are plenty of articles both on and off the internet that go much deeper into the subject and even reference guides that list every single command. I suggest you don’t look at them just yet. Instead, I suggest you spend a few weeks or even months getting used to the command line and picking up things as you go along. Gradually you will learn what is useful and what is not so useful, what works better on the command line than the GUI and what doesn’t. This in turn will help you get the most out of your Linux system and maybe even fall in love with computing all over again.

(By) Abraham Kurp was introduced to open source software a few years ago and it was love at first site. When not preaching the virtues of open source he enjoys reading classic science fiction, playing obscure video games, dabbling in programming, and of course writing.

Check out more about:

The comments were closed because the article is more than 180 days old.

If you have any questions related to what's mentioned in the article or need help with any computer issue, ask it on MakeUseOf Answers—We and our community will be more than happy to help.

17 Comments -

0 votes

Anonymous Coward

Very good, although basic, introduction.

Folks, the terminal (as it is known in the Unix world) is a powerful tool. Be careful when entering any commands, especially when you just copy & paste them off the web. There are people out there willing to screw you over. Just look at the thread from the Ubuntu forums. http://ubuntuforums.org/announcement.php?a=54

Also, most distributions (and OS X) use the same shell. It’s usually bash (bourne again shell) or, more rarely, tcsh (TENEX c shell).

Finally, there are some tutorials from the official Linux website. Mind you, I haven’t tried them myself, but they’re official.
http://www.linux.org/lessons/

0 votes

Diabolic Preacher

is there some way to disable pasting text onto a konsole or a gnometerm (or whatever the gnome version is called)? probably that’ll make people look thru what they are pasting from the web.

0 votes

command-line-browser-simulator

http://www.masswerk.at/jsuix/
Dont forget to thank them for making it and thank me for showing it ;-)
Seriously, this thing is cool.
(DISCLAIMER: I am not affiliated to masswerk in any way)

0 votes

webguyscott

“But sometimes the command line is still the fastest, easiest, or only way to get something done.”

Abraham , by the above statment , I believe you are referring to Linux. In all these years , working with Windows, there hasn’t been one instance where I had to use the command Prompt (Or maybe I just dont remember) ….

0 votes

Aibek

I frequently use Command Promt (Windows) for tasks that I am not able to do through GUI. One of them is traceroute command i.e. tracert domain. I don’t think there is a way to execute it from GUI.

0 votes

Clyde Booom

Excellent intro overview to Linux commands.

Watch out for the rm command!

And also see the first comment that’s posted above.

In a lot of Linux distros, there is an alias to the rm command that adds the -i option to the command so that you have to confirm that you want to run the command before it executes.

However, this isn’t the case for all users, including the root user, in all distros.

Some people like to learn Linux by watching Linux training videos.

You can watch some sample Linux training videos to see how to use Linux commands at:

http://www.iLearnLinux.com/Linux-Commands

Thanks for this Linux commands training post!

Clyde Boom, http://www.iLearnLinux.com
The Easy Linux Training Guy ;) – Easy, self-paced Linux training – in Plain English!

0 votes

Faust-C

I use zsh, here is a “.zshrc” that makes using a shell even more simple, it has command completion, w/ argument completion. Here “http://bsdtips.utcorp.net/mediawiki/index.php/ZSH_Config”

0 votes

Jim Dom

Wow dude, I am impressed on that one for sure.

JT
FireMe.To/udi

0 votes

Luke

I didn’t like using the command line now I use it a lot, I prefer to use it for MySQL as it is so much quicker.

0 votes

Omar Abid

I installed linux on my pc (i’m a windows user) and when i run it i found only a command line! Is this all linux, or i did something wrong help please!

0 votes

Aibek

yeah, probably u got a wrong version. Normally linux distros (packages) come with a decent graphical user interface. I have Ubuntu on my system and although I am not a power user, I am quite comfortable with it.

0 votes

Tony P

Just don’t ever rm -rf /, use rm -rfi /

0 votes

Desmond

Productivity? What if I have 100 files in a directory and I only want to copy 75 files out of it to another directory. Now tell me which is more productive: typing in terminal or select and drag in GUI? Command line is useful in some aspects but mostly it’s lame.

0 votes

binoy

yes its easier from the gui if you need to randomly pick 75 files, but if you have a pattern (which is usually the case for ) the command line would be faster than handpicking the 75 files.
I have been using linux for about 8 years now. I can defiantly say for sure, the command line and the gnu tools are by far the best thing about linux , and of course other *nix OS’s

0 votes

Norm

With some knowledge of basic shell scripting (not too advanced, mind you) you can write yourself a little prompt that will allow you to select files to copy. Here’s the pseudocode that comes to mind;

1 – prompt user for the command he wants to execute in this folder; cp? rm? mv?
2 – after the command is specified, ask the user if he/she want any switches appended to the command? display the man page if need be..
3 – after the command and the switches are determined, prompt for destination folder, mkdir default if folder does not exist
3 – ask the user the method of sorting through the files in the folder. are you going to use regular expressions? (that is really fast but requires extreme caution) are you going to apply this to the whole folder? (that doesn’t really need a script, but throw it in there for the sake of completeness) are you going to “ls” and apply it line by line? are you going to use wildcards? (i.e. cp ab*.jp* ~/blabla means copy all files that start their names with ab and start their extension with jp to the blabla folder)

and so on.. there are probably features and possible solutions I have overlooked.. Feel free to correct/complete it..

0 votes

perozzi

just a question: there is a way to control a linux server using command lines through windows?

a software or something similar: that would be useful for shared or remote hosting.

thanks and excuse me for the question, i’m a noob

0 votes

Norm

@perozzi

it’s called putty
you can initiate telnet sessions via putty and logon to the shell..
you might need sftp from time to time, to transfer files from-to your computer to the remote linux server. For that, I use Bitwise Tunnelier, but there many other alternatives out there with sftp feature