Intermediate terminal usage

For basic file management, make sure to check the Basic terminal usage page.

The terminal can do more than just move files around; here are some additional useful things to do from the terminal.

Man

Most Linux programs have their own help files, called “man pages”, which explain all of their options and how to use them; these can be accessed with:

man <command>

This is a great way to learn additional abilities of these programs as well as to learn their proper syntax.

Tar

Many Linux programs and files are distributed as .tar.gz or .tar.bz2 files. These double file extensions come from a historical peculiarity of Unix: a different program was used to combine multiple files into one than the program used to compress files. This isn't important for modern users, though; if you need to to extract a .tar.gz or .tar.bz2 file, use the following command:

tar -xvf <file>

Or if you want to extract to a directory other than the one you're currently in,

tar -xvf <file> -C <directory>

Su and Sudo

When working in Linux, you usually run as your main user (the one you created when you first set up the computer); however, this user often doesn't have permission to run system-altering commands. To do this, you need to run commands as the so-called “root” user. This is best done by running:

sudo <command>

and then entering the password for your main user's account. Be careful when running commands with sudo; this will let you run any command on your system, up to and including commands to delete your entire hard drive.

File names and permissions

In general, Linux doesn't care about file extensions; the file's type is encoded in the file itself. Thus, most executables will just have descriptive names like “firefox” or “oowriter” (for OpenOffice Writer). Usually, configuration files will have the extension .conf, but these are just text files, and can be modified in any editor.

Each file has an owner (the originator of the file) and a group (further discussed on the Advanced page. Files have three categories of permissions: things the owner can do with the file, things that all members of the file's group can do, and things that everyone else can do. These “things” are reading the file, writing to the file, and executing the file (or viewing the contents of a directory, in the case of directories). When viewing files with ls -l, you will notice a segment which looks like ”-rwxr-xr-x”; this is that file's permissions. The initial dash gives you the file type (”-” is a regular file, while directories will have a “d” here instead; there are some additional types which are on the Advanced page). The next nine characters are the file's permissions; no spaces separate the sections, and dashes are part of the permissions, not spacers. The first three characters are the user's permissions, then the group's, then the world's. (In this example, the user can read, write, and execute the file [rwx], the group can only read and execute [r-x], and the world can also only read and execute [r-x]). To change a file's permissions, use the chmod command, discussed further on the Advanced page.

Directory structure

The directory structure of Linux is different from that found in Windows (though with Vista, Microsoft took a few steps towards Linux). First of all, in Linux forward slashes (/) are used to separate directories, not backslashes (\). The entire filesystem is based on the “root directory,” which is located at / ; all directories are under this root directory. Each user is given a “home directory,” located at /home/<username>. This is where the user will keep his or her files and personal settings. While logged in as a particular user, the character ~ can be used as a shorthand for that user's home directory; that is to say, if you are logged in as trimeta, and you want to access a file located at /home/trimeta/filename; you can just call it ”~/filename”.

Other commonly-used directories:

Directory Use
/ Root of the file system; all other directories are below this directory
/etc Holds most system configuration files
/tmp Holds temporary files (often deleted between reboots)
/media Holds additional storage devices attached to the system, such as USB thumb drives
/bin and /usr/bin Holds most executable files
/sbin and /usr/sbin Holds executables for administering the system
/lib and /usr/lib Holds most system libraries
/usr/share/doc Holds extra documentation for all installed programs

Usually you will not need to interact with these directly, but it is useful to know where they are.

.bashrc and aliases

There are some commands you might want to have run automatically whenever you start a new shell; you can easily do this by putting these commands in your .bashrc file, located at ~/.bashrc (~ is a shorthand for /home/<username>/). A common command you might want to put here is alias. It lets you easily create shorthands for commonly-used commands. These shorthands can either be replacements of dangerous commands (such as rm) or abbreviations. Here is an example .bashrc file:

#!/bin/bash
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
alias ll='ls -l'
alias la='ls -a'

The first line is just to make sure this file is interpreted properly; copy it exactly into your .bashrc (including the #! section). The next three lines replace the cp, mv, and rm commands with safe versions; as long as these are in your .bashrc (and you have rebooted the computer so the changes take effect), the -i option will always be used on these commands. The last two lines give helpful shorthands; ls -l and ls -a are used so often, it's convenient to run these commands with just two letters.

Advanced terminal usage

This covers most things one would need to do to interact with the local computer; for a discussion of how to control computers over the internet, and how to install programs from the command line, please read Advanced terminal usage.