One of the benefits of using a Linux distribution like Ubuntu for your operating system is having access to the terminal, the Linux command line interface. In this article, we'll be going over some of the most commonly used terminal commands, their uses, as well some examples for each one. First, we'll start by opening up a terminal, which should start us in our home directory:
cd, or "Change directory" as it is aptly named, changes your directory from the one you are currently in, to the one that you specify. The basic template for the command is:
cd *insert directory path here*
You can cd into a directory using either an absolute path (the true path of the file) or a relative path.
The following is an example of using cd to change directories using both an absolute directory path and a relative path:
The ls command is used to view the contents of some directory. By default, inputting this command outputs the contents of your current working directory. You can, however, input a directory path as an argument to the command and it will show you that directory's contents instead.
One of the options of ls, -a, allows you to view hidden files within your directory. Hidden files are often prefixed with "." such as .ssh
The mkdir command allows you to create a directory in the current working directory. The template for the command is:
You also have the option of making multiple, separate directories like so (make sure not to include spaces after the commas):
Lastly, you also have the option of making nested directories with the -p option:
mkdir -p directoryA/directoryB/directoryC
The rm command removes/deletes files from the current working directory. The syntax is:
It may be useful to include the -v flag when using this command as it outputs the files that were removed to the terminal. You can also remove multiple files at once by specifying file names separated by spaces.
Additionally, you can remove whole directories with the -r option:
The mv command allows you to move a file from the current working directory to another directory. This command also allows you to rename the file, move a file, or move AND rename the file at the same time. The syntax is as follows:
mv fileA.txt directory1
which will move fileA.txt into directory1 (assuming directory1 is indeed a preexisting directory).
To rename a file, replace the second argument with the new name of the file
mv fileA.txt fileB.txt
which will rename fileA.txt to fileB.txt. IMPORTANT! If there is already an existing fileB.txt, you will overwrite that fileB.txt by performing the above operation. You can be prompted when overwriting files with the -i option.