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 first.
The command line environment
When you log in to your account using SSH, the first thing you see is the Linux command line prompt: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:Navigating the directory tree
To determine which directory you are currently working in, type the following command: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:Also as in DOS or Windows, the current directory is represented by one period (.).
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: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:Creating and removing directories
To create a directory, use the mkdir command. For example, to create a directory named backup, type the following command: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.
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:
📘 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:
📘 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:
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: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.