Last updated May 15, 2015. Created on October 14, 2005.
Edited by kdmarks, richardhayward, shamio, joebachana. Log in to edit this page.

References to Unix-like (*nix) commands in documentation or forum posts can be intimidating if you're not used to them, but sometimes "command line" is necessary for administering your system or fixing a problem.

Learning some of these *nix commands can help you be more productive, as well as give you insight into what your hosting control panel or GUI FTP client does.

Some Unix command you'll see used:

chmod
This command changes the permissions on files and directories. The '-R' (for recursive) option "switch changes" the permissions on subdirectories and files as well.

Examples:

chmod 777 sites
    This changes the permissions on the file (or folder) 'sites' so that everybody can read,
    write, and execute it.
chmod -R 644 sites
    This changes the folder <em>and</em> everything inside it. Everyone can read
    from it, and the owner can write to it.

These pages provide further details on file permissions:

mv
This command moves or renames files and directories. In general, to rename a file or a directory you 'move' it to its new name.

Examples:

mv default.settings.php settings.php
    This changes the name of the file 'default.settings.php' to
    'settings.php' in the same directory.</li>
mv * ..
    This will move all files (except those starting with a dot) in the current
    folder up one level.
rm
This command removes (i.e., deletes) files and/or directories. To remove a directory you need to use the '-r' (recursive) option.

Examples:

rm settings.php
    This deletes the settings.php file from the current directory.
rm -r *
    This deletes every file (except those starting with a dot) in the current
    directory.
cp
This command copies files and directories. The '-p' (for preserve) option switch also copies permissions, ownerships, etc. The '-r' (recursive) option switch also copies subdirectories and files. The '-a' (for archive) option switch includes both '-r' and '-p' options.

Example:

cp default/default.settings.php mysite/settings.php
    This copies the 'default.settings.php' file, which is in the 'default'
    directory to the 'mysite' directory, where it is renamed 'settings.php'.
mkdir
This command creates a directory. Directories are also known as 'folders' in the Windows and Macintosh world.

Example:

mkdir mysite
ln
This command creates a filesystem link. The one you will see mentioned most often is a 'symbolic link' (using the '-s' option switch), which behaves like a shortcut in Windows or an alias in the Macintosh Finder. You can create a link to a file or directory located somewhere else, and it will behave just like a copy of that file or directory. Since the shortcut/alias is linked, rather than just a copy of the file or directory, changes to one are reflected in the other.

Example:

ln -s . subdir
    This creates a symbolic link in the current directory to the directory
    'subdir'.
wget
This is a command to download web pages or files from the net and save them to disk.

Example:

wget http://ftp.drupal.org/files/projects/drupal-7.12.tar.gz
    This downloads the file at that URL (which happens to be
    version 7.12 of Drupal core).
tar
This is an archiving and unarchiving utility. It can use various compression options. Drupal core is most often downloaded as a compressed tar file. Tar files are more commonly known as 'tarballs.'

Example:

tar -xzvf project.tgz
    This uncompresses (-x) project.tgz from the gzip format (-z), lists all
    operations the command does on the screen ("verbose", -v), and
    specifies the file (-f).
mysql and mysqladmin
These are command line utilities for connecting to and managing a MySQL database. Just about anything they can do can also be done by phpmyadmin.
sudo
Sudo is a command used to precede other commands which need to be run with an escalated role. Normally the command is run with a user called 'root', which has god-like privileges on the system. Provided that your account is authorized to use the sudo command, you use your own password when prompted after executing the command.

Sudo may best be known in popular culture, due to this cartoon at xkcd.com:
sudo make me a sandwich from XKCD.com

Example:

sudo chmod 777 sites
    This will change the directory 'sites' to be readable by everyone, even
    if you did not have privileges to do so in your
    normal user role.
man
Most *nix commands have further documentation, which is available to you by typing 'man' in front of the command in question. These are also known as 'man pages.' You can normally move forward through the man pages using the spacebar and backwards by typing 'b.' Type 'q' to exit.
  • The man pages explain available options. For example, the '-r' option in the 'rm' command explains:
    -r, -R, --recursive
        remove directories and their contents recursively
  • The man pages often give examples for command usage.
    To remove a file whose name starts with a `-', for example `-foo', use one of these commands:
    rm -- -foo
    rm ./-foo

Special characters:

/
the Unix directory separator (just like with URLs) and also represents the root directory. When a path starts with / it is an absolute path (i.e., it starts with the root directory). A path ending in / is an optional way of explicitly referring to a directory rather than a file.
..
refers to the parent directory (just like in Windows). A path starting with this is relative to the current directory. Can be chained together (e.g., ../.. refers to the parent of the parent directory).
.
like '..' but refers to the current directory.
~
it refers to the user's current home directory (e.g., /home/username)
*
wildcard that matches any number of characters (like in Windows)
?
wildcard that matches just one character (like in Windows)

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.