Linux Commands

Created: October 28, 1998
Last updated: February 28, 2006

These commands will work with most (if not all) distributions of Linux as well as most implementations of Unix. They're the commands that everybody knows. To be able to survive in Linux, you should know these. There aren't always handy-dandy tools for X that shield you, especially if you're managing your own system. Things often go wrong and you're forced to work with the bare minimum. These are commands that will come in handy when all you've got is the command line.


  1. Navigation - how to get around
  2. File Management - who needs a graphical file manager?
  3. Editing - using text editors for those nasty configuration files
  4. Monitoring Your System - to satisfy your insatiable curiosity
  5. Shutting Down and Rebooting - you better know this, though you may not use it a lot


We all need to get around our filesystems with all the files and directories. Armed with just these basic commands for navigating the filesystem, it's possible to explore the rest of your Linux system.


As you might already have guessed, the cd command changes directories. It's a very common navigation command that you'll end up using, just like you might have done in MS-DOS or the Windows command prompt (cmd).

All you have to do is type cd <directory> to go to the directory of your choosing. For example, if you want to go to /etc/ you would type cd /etc.

When moving to the parent directory, you must put a space between cd and the ".." or else it won't work; Linux doesn't see the two dots as an extension to the cd command, but rather a different command altogether. It will eventually come to make sense if it doesn't already.

Running cd without any arguments will take you back to your home directory.


The ls letters stand for list. It basically works the same way as the dir command in DOS.

Typing ls will give you a listing of all the files in the current directory. If you're new to Linux, chances are that the directories you are commonly in will be empty, and after the ls command is run, you aren't given any information and will just be returned to the command prompt (the shell).

There are "hidden" files in Linux, too. Their file names start with a dot, and doing a normal ls won't show them in a directory. Many configuration files start with a dot on their file names because they would only get in the way of users who would like to see more commonly used items. To view hidden files, use the -a flag with the ls command, i.e. ls -a.

To view more information about the files in a directory, use the -l flag with ls. It will show the file permissions as well as the file size, which are probably what are the most useful things to know about files.

You might occasionally want to have a listing of all the subdirectories, also. A simple -R flag will do, so you could look upon ls -R as a rough equivalent of the dir /s command in MS-DOS.

You can put flags together, so to view all the files in a directory, show their permissions/size, and view all the files that way through the subdirectories, you could type ls -laR.


This command simply shows what directory you're in at the moment. It stands for "Print Working Directory." It's useful for scripting in case you might ever want to refer to your current directory.

File Management

To really get anything done, you should be able to copy, move, and remove files. There's also the idea of a symbolic link, which allows references to one file to access another file somewhere else on the filesystem.


Copying works very much the same as in MS-DOS or the Windows command prompt. The cp command can be used just like the MS-DOS copy command. Just remember that directories are separated with slashes (/) instead of backslashes (\). The basic syntax is just cp original_file new_file.

There are other options to the cp command. You can use the -f flag so that it does not prompt you each time it may overwrite an existing file. You can use the -p option to preserve the permissions.

You can also copy an entire directory to its new destination. Let's say you want to copy a directory old_directory (and all of its contents) from where you are to be /home/jack/new_directory/. You would type cp -rpf old_directory /home/jack/new_directory. To issue this command you would have to be in the directory where old_directory is actually located.


When running Linux and UNIX-like operating systems, you can link files together. This all works by "redirecting" a symbolic link to the actual file. For example, say you have a file /home/me/original_file and create a symbolic link to it, /home/me/symlink using the command ln -s /home/me/original_file /home/me/symlink. Whenever you edit /home/me/symlink, you'll actually be editing /home/me/original_file.

The most simple way that I've ever used ln to create symbolic links is ln -s existing_file link. You can also use the -f flag to force the command line to overwrite anything that might have the symbolic link's file name already.

To remove a symbolic link, simply type rm symbolic_link. It won't remove the file that it's linked to.


The mv command can be used both to move files and to rename them. The syntax is mv old_location new_location.

You can't move a directory that is located in one partition to another, unfortunately. You can copy it, though, using cp -rpf, and then remove it with rm -rf later on. If you have only a single partition that makes up your filesystem then you have very little to worry about in this area.


The rm command is used for removing files. You use it just like the del or delete command in MS-DOS. Let's say you want to remove a file called foobar in your current directory. To do that, simply type rm foobar. Note that there is no "Recycle Bin" like in Windows. So when you delete a file, it's gone for good.

To delete something in some other directory, use the full path as the file name. For example, if you want to delete a file called windows that's in the directory /usr/local/src/, you would type rm /usr/local/src/windows.

To remove an entire directory and its contents (as opposed to a single file), type rm -rf /directory where /directory is the path to the directory that you want to delete. If you're wondering, the rf stands for "recursive" and "force". Be very careful with this command, as it can easily wreak havoc if you delete important system directories.


There are a lot of features packed into Unix text editors, but for the sake of your sanity I'll discuss only the basic features you need to get going: opening up a file, saving the file, and exiting. There are a lot of good guides to particular text editors out there, but if all you need to do is get going, this is the place for you.

The basic syntax to invoke these text editors is the same. Type the name of the editor followed by the file you want to edit, separated by a space in between. Non-existent files will be blank. Blank files will be blank as well.


To use GNU Emacs (or its counterpart, XEmacs), there are really only two commands you need to know. Come to think of it, they're the only ones I know.

While you're editing a certain file with emacs or xemacs, you can save it with the [Ctrl]-x [Ctrl]-s keystrokes, in that order. Then to exit, type [Ctrl]-x [Ctrl]-c.


Most modern distributions include vim, derived from the infamously arcane Unix editor, vi. It's much more pleasant to use vim than vi, but in many cases you will only have vi available to you. The instructions I provide in this section should be work for both.

Using vim is different in that there are several modes in which you use it. To do actual editing of the files, press [ESC] i (both separately and in that order). Then to save it, press [ESC] : w. Escape, the colon, and "w" should be keyed in one after the other. Finally, to quit, type [ESC] : q. The same rules apply as in previous vim commands.

You can use "w" and "q" at the same time to enable yourself to write to the file and then quit right afterwards. Just press [ESC] : w q and hit enter.

To get a nice overview of vi(m) functionality, try the vimtutor command. Running through this simple tutorial generally takes 15-30 minutes at the most, and will give you a nice familiarity with vi(m) commands.

Monitoring Your System

An important part of system administration (especially with your own system) is being able to know what's going on.


The program tail allows you to follow a file as it is growing. Most often, I use it to follow /var/log/messages. I do that by typing tail -f /var/log/messages. Of course, you can use anything else, including the other logs in /var/log/. Another file you may want to keep an eye out for is /var/log/secure.

If you want to leave that running all the time, I recommend having some sort of terminal program in X, logged in as root through su.

Another program you may want to look at is head. It monitors the top of the file specified, instead of the bottom.


This program shows a lot of stuff that goes on with your system. In the program, you can type:

  1. M for memory usage information
  2. P for CPU information
  3. q to quit

These commands are case sensitive. Typing m is different from typing M, for example.


Typing w will tell you who is logged in. This can be helpful if you're the only one who uses your computer and you see someone logged in that's not supposed to be.

Another alternative is the who command.

Shutting Down and Rebooting

To shut down your system, type shutdown -h now, which tells the shutdown program to begin system halt immediately. You can also tell it to halt the system at a later time, I think, but you'll have to consult the shutdown manual page for that (man shutdown).

To do a reboot, you can either type reboot or shutdown -r. You can also use the famous Ctrl-Alt-Delete combination to reboot, which you may already be familiar with.

Shutting down and restarting properly (as described above) will prevent your filesystem from being damaged. At the exact moment that you shut down or restart the system improperly, there may be all sorts of temporary files floating around in the system's memory and on the filesystem, and they won't get dealt with properly. This may leave stale temporary files on your filesystem. Filesystem damage is the most obvious of the consequences, but there are probably other things out there that I don't know about. The point is just to shut down your system properly.

There are (rare) cases in which the machine might lock up entirely, and prevent you from being able to access a command prompt. Only then will your last resort be to do a forced reboot, which can be done by pressing the restart button on the computer's case.

Copyright © 1997-2006 Joshua Go (joshuago at users dot sourceforge dot net). All rights reserved. Permission to use, distribute, and copy this document is hereby granted. You may modify this document as long as credit to me is given.