> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Introduction to Linux commands

> Learn how to do basic tasks from the Linux command line, such as listing files and directories, moving and deleting files, and more.

This article is an introduction to some essential Linux commands. A basic understanding of the Linux command line environment (also commonly known as the "shell" or the "terminal") is important if you ever need to set up a special configuration, install an application manually, or you just want to have a better understanding of how your web site works.

<Note>
  This article assumes that you know how to access your account using SSH (Secure Shell). If you do not know how to do this, please read [this article](/docs/using-ssh-secure-shell) first.
</Note>

## The command line environment

When you log in to your account using SSH, the first thing you see is the Linux command line prompt:

```bash theme={null}
username@example.com [~]#
```

The tilde symbol **\~** indicates that you are in your home directory, which is usually **/home/username** (where *username* represents your own account username). But where do you go from here? The following sections demonstrate how to accomplish some basic tasks from the Linux command line environment.

### Listing files and directories

The first thing you probably want to do is see what's in the current directory. To do this, type the following command and then press Enter:

```bash theme={null}
ls
```

The **ls** command provides a listing of a directory's contents. Its function is similar to the **dir** command in DOS or Windows. To view more detailed information about a directory's contents, type the following command:

```bash theme={null}
ls -l
```

The **-l** option generates a listing that shows permissions, owner and group membership, size, modification date, and the name for everything in the directory.

### Navigating the directory tree

To determine which directory you are currently working in, type the following command:

```bash theme={null}
pwd
```

The **pwd** command shows the current directory (**pwd** stands for "print working directory"). When you first log in to your account, the working directory is **/home/username** (where *username* represents your own account username). This directory is your home directory, and is also represented by the tilde symbol **\~**.

To change to another directory, use the **cd** command (**cd** stands for "change directory"). For example, to change to the **public\_html** directory, type the following command:

```bash theme={null}
cd public_html
```

To change back to your home directory, type the following command:

```bash theme={null}
cd ~
```

<Note>
  Just as in DOS or Windows, the parent directory is represented by two periods (**..**). So to change to the parent directory (in other words, to go back up one level in the directory tree), type the following command:

  ```bash theme={null}
  cd ..
  ```

  Also as in DOS or Windows, the current directory is represented by one period (**.**).
</Note>

### Finding files

Now that you know how to move through directories and list their contents, you may be wondering how to find specific files. To do this, use the **find** command. The **find** command looks for a file or set of files in a directory and all subdirectories beneath it. For example, to list all files that end with a *.html* extension in the current directory and its subdirectories, type the following command:

```bash theme={null}
find . -name '*.html'
```

In this command, we use one period (**.**) to specify the current directory as the search location. The **-name** option specifies that we are searching for files by their filename (instead of their type or size, for example). The **'\*.html'** option uses a wildcard to indicate that we are interested in files that end with a *.html* extension.

<Tip>
  The **find** command has a large number of options available. You can view information about how to use the **find** command (or any of the other commands described in this article) by using the **man** command. The **man** command shows manual pages for a particular command. For example, to view the manual page for the **find** command, type the following command:

  ```bash theme={null}
  man find
  ```

  You can use the Page Up and Page Down keys to scroll through the manual page. To exit, type `q`.
</Tip>

### Finding the path to a program

You can use the **whereis** command to find the path to a particular program. For example, to find the path to the **grep** program, type the following command:

```bash theme={null}
whereis -b grep
```

This command shows paths to the executable (binary) programs. To view the paths to an executable program and its related help page files, leave out the **-b** option. For example, type the following command:

```bash theme={null}
whereis grep
```

### Creating and removing directories

To create a directory, use the **mkdir** command. For example, to create a directory named **backup**, type the following command:

```bash theme={null}
mkdir backup
```

To remove a directory, use the **rmdir** command. For example, to remove a directory named **backup**, type the following command:

```bash theme={null}
rmdir backup
```

<Note>
  The **rmdir** command only works for directories that are empty. If you try to remove a directory that contains files, you receive an error message. For the **rmdir** command to succeed, you must first delete any files in the directory.
</Note>

### Copying, moving, and deleting files

Working with files is straightforward, and if you have done similar tasks at the command line in DOS or Windows, you should have little difficulty learning how to do so in Linux:

* To copy a file, use the **cp** command. When you copy a file, you specify the source and destination locations. For example, to copy the **index.html** file in the current directory into a directory named **backup**, type the following command:

  ```bash theme={null}
  cp index.html backup
  ```

  > 📘 Note
  >
  > If a directory named **backup** does not exist, then the **cp** command copies the **index.html** file to a file named **backup** in the current directory.

* To move a file, use the **mv** command. As with the **cp** command, you specify the source and destination locations. For example, to move the **index.html** file in the current directory into a directory named **backup**, type the following command:

  ```bash theme={null}
  mv index.html backup
  ```

  > 📘 Note
  >
  > If a directory named **backup** does not exist, then the **mv** command moves the **index.html** file to a file named **backup** in the current directory. This is equivalent to renaming the file.

* To delete a file, use the **rm** command. For example, to delete a file named **old.html**, type the following command:

  ```bash theme={null}
  rm old.html
  ```

### Determining disk usage and free space

To determine how much space a directory occupies, use the **du** command (**du** stands for "disk usage"). By default, the **du** command runs through the current directory and all subdirectories beneath it, adding up the amount of space that files occupy, and providing a total at the end of the listing. The **du** command outputs disk usage in bytes, but to make the output totals easier to read, type the following command:

```bash theme={null}
du -h
```

For example, if you run this command from your home directory, you can quickly see how much total disk space your account occupies, as well as which directories take up the most space.

To determine how much free space remains on a disk, use the **df** command (**df** stands for "disk free"). To make the output totals easier to read, type the following command:

```bash theme={null}
df -h
```

<Note>
  The **df** command is more suitable for a VPS or dedicated server because you control the entire disk. It is less useful on a shared hosting account, where you share the disk with other accounts.
</Note>

## More information

This article is only an introduction to basic Linux commands and its command line environment. There are many more Linux commands and features, and numerous tutorials available on the web. For example, the [linuxcommand.org](http://linuxcommand.org/) website provides an in-depth tutorial about how to use the command line, as well as a downloadable book.

## Related articles

* [Using SSH (Secure Shell)](/docs/using-ssh-secure-shell)
* [Editing text files from the command line](/docs/editing-text-files)
