When most people think of Arnold Schwarzenegger, they immediately think of the dreaded Terminator. However, his close friends probably don't- they think of happy Arnold the prankster (didn't know, did ya?). Similarly, when most people think of Linux, they immediately think of the dreaded command line. Most Linux system admins probably don't- they think of the happy, safe, and fun command line. If you are familiar with Windows and know how to open "My Computer", navigate to another folder, and then open a document, then you have already have all the basics down to learn to use the command line in under 5 minutes. The interface may be a little different, but you will soon understand that you are basically doing the same thing. In this tutorial, you will learn to operate the command line much like you operate "My Computer". We will cover the commands "pwd", "ls", "cd", and "pico" .
Lets start with opening a terminal. This is akin to clicking on "My Computer" in Windows. The main difference is the initial information that is presented to you. In windows, you immediately are presented with the name of the folder that you are in (In the Address Bar), and the contents of the folder (In the main window). Linux, by default, does not tell you this information right away. Rather, Linux tells you who you are, and on what machine you are currently logged into, like this:
You can safely (for now) ignore this. If the ideas of "who you are" and "what machine you are on" are foreign to you, then ignore them for now. If you want to know what directory you are in, then type "pwd", like this:
[[email protected]]$ pwd
And the command line will probably respond with something like this:
So now you know that you are in the directory "user" which is in the directory "home". This command is easy to remember if you know what it stands for: "Print Working Directory". This may seem hard to remember, but if you remember your seven-digit phone number, then you won't likely forget "pwd". Another command will show you the other bit of information that you are missing: the contents of the directory. Type "ls", and you should get something similar to this:
[[email protected]]$ ls Desktop file.txt otherfile.txt
This is the list of the contents of the directory. "Desktop" is a sub-directory, and "file.txt" and "otherfile.txt" are files in the current directory. Just like looking at the window in Windows, but with no pictures! On most systems, "Desktop" will be a different color, to show that it is a directory.
You may have guessed what "ls" stands for already: "List". Because I come from a Windows background, the first thing that I do when I open a terminal is "pwd" followed by "ls". On my home machine, it looks something like this:
[[email protected]]$ pwd /home/dotan/ [[email protected]]$ ls Desktop Work 1984.txt nin.mp3 ety.jpg [[email protected]]$
So you see that I have two directories ("Desktop" and "Work"), and three files: the book 1984 (A must-read), a NIN music file (For those who don't know what NIN stands for, shame on you), and a photo of my wife Ety.
Now we have gotten to the point where we can effectively open "My Computer" on Linux: we open a terminal, print the name of the directory, and then print its contents. If you never looked at the Address Bar in Windows, then you don't need to give the command "pwd". If you already know what is in the folder (or to which other folder you want to go), then you don't need to give the command "ls".
Great, now what? Usually you open "My Computer" when you want to navigate to a file and open it. lets learn how to do that in Linux. In Windows, when you want to go to a sub-folder, you double-click it. In Linux, when you want to go to a sub-directory, you use the "Change Directory" command:
[[email protected]]$ cd Desktop
And now, you are in the "Desktop" directory! Just to be sure, give a "pwd" command:
[[email protected]]$ cd Desktop [[email protected]]$ pwd /home/user/Desktop/
Excellent! But what is in the Desktop directory?
[[email protected]]$ ls Home Trash
Just two sub-directories, "Home" and "Trash". Pretty boring. Lets go back up a directory, to "/home/user/". This command is a little tricky at first: "cd ..", like this:
[[email protected]]$ cd .. [[email protected]]$ pwd /home/user/
I also gave the "pwd" command just to confirm that we really, really, made it back to "/home/user/". The two dots in the Change Directory command are the instruction to go up a directory. Just like pressing the Up Arrow button in Windows.
So now we know how to navigate the file system- how to move around in the directory structure and how to view the files in it. But how do we open them? In "My Computer" you can open a file by double-clicking on it. In Linux this is a bit more complicated. Windows guesses what type of file you are trying to open based upon the file name extension and opens the appropriate program. Linux makes no such guesses. Therefore, you must tell Linux which program to use to open the file. To keep this tutorial simple, we will deal only with text files, and then again only with the simplest text editor: Pico. We will create a simple text file, close it, and then open it again.
First off, to open Pico you just type its name:
[[email protected]]$ pico
Here, you are presented with a blank document. The menu on the bottom of the screen gives you more information on what you can do. To exit Pico, type
[[email protected]]$ ls
I don't know what you personally have on your system, but I'm willing to bet that you don't have a file called penguin.txt. So let's create one. Like every other Linux text editor, you can create a file in Pico by typing the name of the file you want after the program name. So for Pico we would type:
[[email protected]]$ pico penguin.txt
And once again we have a blank document. This is because the file penguin.txt did not exist when we gave the command. If it did, then the screen would show it. Now, lets type a friendly greeting to all who may open the file- type "Hello, World!". You can add anything else to the file that you want. The Pico text editor is very similar to Notepad for Windows. The arrow keys move the cursor as expected and you can enter text with the regular keys on the keyboard. To exit Pico, once again we type
[[email protected]]$ pico penguin.txt
Now, you should see the text that you had previously entered. You can make changes to the file and save them when exiting. Of course, there are other ways of saving a file in Pico, and you can of course exit without saving. There are many other things that you can do in Pico. They are all explained in the Pico Help file, which you can access with
Now that you know how to handle the command line in Linux like you handled "My Computer" in Windows, you will be amazed at how much of a time saver it is. The commands "ls", "cd", and many others have options that can save you time and stress when used properly. For instance, if you want to go directly to the folder "/usr/bin" you do not need to go up to the top directory and then back down through "usr" to "bin". You could just type "cd /usr/bin" and you're there! All that, and no need to clean the mouse!
: "pico" is not really a command- it is a program. However, the distinction will become important only after you have progressed to a more advanced proficiency level.
: This default behaviour can be changed.
: On Linux, folders are called directories. Same thing.
: There are other ways of determining which items are files and which are directories.
: File name extension is the part of the file name after the dot: file.txt has a "txt" extension, and picture.jpg has a "jpg" extension.
: You can ask Linux to guess with the "file" command. This only tells you what type of file it is, and not what program to use to open it.
: Hold the Control Key (The key at the bottom left corner of your keyboard) and press X. Now release both buttons.
Updated: 2011-12-04 with comments from Michael Klinosky
command line, linux, explorer, tutorial Really Simple Command Line Tutorial For Newbies. command line, linux, explorer, tutorial
[email protected] [email protected] [email protected] [email protected] [email protected]