Command Line Essentials Part 1

Although Linux can be used without the command line and has been improving its graphical interface, the command line interface(CLI) is still an important and useful part of being a Linux user. These tutorials about the command line are centered on Ubuntu, that being my current distro of choice. However the command line is all but uniform across distributions and I will note when it is distro specific. To get the most out of these open up the terminal(note on how at bottom) and follow along. To be at all effective on the command line you need to know how to move around the file system and do basic file manipulations This is what Part 1 is about(Part 2, Part 3).



The ls command lists the files and folders inside the working directory. Ex:


foo.txt        pics


To move around in the command line the cd command is used. It is used in the following:

$cd targetfolder

You can use absolute folder name (the whole name i.e.. “/home/me/Documents”) or relative folder names (relative to the current folder i.e.”Pictures”), which leads to the next topic.

Basic Path Extension

“~/” expands to you home folder; “../” is the parent folder [of the working directory]; “/” is the root directory


pwd stands for print working directory. It has no arguments; simply type it in and it prints the folder/directory that you are in. This information is also usually in your prompt.

Making and Removing files/directories

Use ls to see the created folders or deleted files.


This command creates a directory. It is used as follows:

$mkdir newfolder


Alternatively, you can also remove a directory with rmdir. This only works with a empty folder(see rm -r).

$rmdir deleteThisDirectory


This removes a file. By default it will not prompt for confirmation. Nor will you be able to “undelete” the file.

$rm deletefile

rm -i file will prompt for confirmation and rm -r will delete a directory that is not empty.

Copy and Moving files

Like rm, copy and move can destroy files. This happens if you copy or move to a file that already exists. For prompting, like rm, use -i


cp makes a copy of a file.

$ cp file.txt copiedfile

$ ls

file.txt        copiedfile


mv moves a file. It can be used as a rename in the same directory or to move between folders.

$ mv file.txt file.move

$ ls

file.move        copiedfile

Help on commands

From the Command Line

You can use the man command to find info on a command.

$man ls

blah blah blah(not real)

You can also, on most programs, type command -h or command --help. Note that some Utilities such as ls do not work with -h.

$ls  --help

blah blah(not real)


Books, Internet(like googling ls), Friendly Linux users



Commands and terminal examples are in monospace. User typed input is in bold.

Getting to the Terminal/GUI

In most Desktop environments: Applications -> Accessories -> terminal. In Unity search for terminal.

You can also use run(alt-f2) and type in gnome-terminal or xterm or something similar.


Many(or maybe most) of these commands are also in Mac OS, but since I have no experience with Macs I do not know the specifics of how it differs.


The rest of this series: Part 2, Part 3


16 Responses to Command Line Essentials Part 1

  1. Xander314 says:

    In Ubuntu, one can also start the terminal with CTRL+ALT+T, I think.

    Two other things:
    1. Maybe you should mention the recursive and force options for rm:
    rm -r directory with contents
    rm -f blah blah blah
    to shut up any annoying messages about readonly files or whatever (though maybe the second one is a bad idea for careless beginners…)

    2. For me, ls -h doesn’t work, but ls –help does. That’s on Linux Mint, but I’m guessing it should be the same on Ubuntu.

    • Thanks for the input. I will add it to the post along with cp and mv.

    • I should have checked. For most utilities both work. For example: “apt-get -h” gives the help as does “apt-get –help”.

    • DCG says:

      I’ll edit out the ‘i’s

  2. Xander314 says:

    (Sorry for the mess, I thought [i]…[/i] would give me italic text.)

    • You can use regular HTML. This is in italics!

      • Xander314 says:

        Ah, okay – thanks! I guessed it might be possible after, but didn’t want to spam you with more comments. Feel free to delete all the failed ones now if you want to tidy your post up 😉

  3. Xander314 says:

    Also, in the final line, where it says “–help”. That is supposed to be a double hyphen, but WordPress broke that too :/

    • You could try the pre tag

      • Xander314 says:

        What about the sourcecode tags?
        ls –help
        Or were they code tags?
        ls --help

      • Xander314 says:

        Okay the “code” tag seems to do it. That’s just
        in angle brackets. I really don’t know why sourcecode is formatted with a different commant in comments than in posts…

    • Right- I used code tags in the post. Their HTML filter must show double hypens as single ones, although Through my admin view I see the --

      • I see. in admin all user tags are removed for some reason and the text is put in a blockquote.

  4. Xander314 says:

    The pain WordPress’ comment formatting system puts us through…

  5. Pingback: Command Line Essentials Part 2 « PC and Penguin

  6. Pingback: Command Line Essentials Part 2 « PC and Penguin

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: