In this guide, you are going to learn about the Linux commands required to navigate through the account and perform basic tasks. Such include changing folders, renaming files, or creating directories. Mastering this process is going to allow you to perform certain operations at a much quicker rate and is going to allow you to install scripts manually. To start your journey through the command-line interface, please login using the SSH protocol. You are going to know you have logged in when you see the following output:
[user@hostname ~]#
The above prompt indicates that you have logged in with your user at the designated hostname and you are currently within the tilde "~" directory, which symbolizes the home dir of your account or /home/user/.
The list command
To execute the "list" command, please type:
ls
This command is going to show you all of the files and folders within the current directory. To have all this output neatly arranged within a proper list and provide more information, such as permissions and size, please add the -l option:
ls -l
The change directory command
To execute the "change directory" command, please type:
cd
Now that you know how to generate a list of all the files and folders contained in the current directory, let's see how to change it to another one. You can locate the root directory of the primary domain name on a typical cPanel server within the home dir of the user. It's called "public_html" and to access it, please type:
cd public_html
The print current working directory command
To execute the "print current working directory" command, please type:
pwd
It is going to show you a single line containing the absolute path to the directory you are currently within. If you type "pwd" within the "public_html" folder, you will be presented with the following output:
/home/user/public_html
The move command
To execute the "move" command, please type:
mv <file/folder> <destination/new name>
This command is going to allow you you to move a file/folder from one place to another. if you have an index.html file inside the "public_html" folder and you want to move it to your home dir, please type in the following:
mv index.html /home/user
As the home dir is a parent directory of the "public_html" you can type:
mv index.html ..
The two dots mean "1 directory behind the current one". Another use of the move command is to rename files/folders. You might be wondering why can this command be used for moving and renaming files? Well, it's quite simple. When you move the file in the same directory, the file is placed within the respective folder again, however this time under a different name. Let's use the index.html file as an example. Say you want to rename it to index.html-backup, as you intend on deploying a new index page for your site. To do so, please type:
mv index.html index.html-backup
The copy command
To execute the "copy" command, please type:
cp <file/directory> <destination>
This command lets you copy a file/directory from one location to another. Say you are in the "public_html," and you have another website with its root directory located inside the home dir called "my-second-site." To copy the index.html file to the "my-second-site", please type:
cp index.html /home/user/my-second-site/
To copy a folder, the command needs an additional option - "-r," which stands for "recursively." Linux is going to assume that you have other files/folders within this directory which you want to copy as well. We are going to give an example where we copy the "public_html" folder within the "my-second-site" directory:
cp -r /home/user/public_html/ /home/user/my-second-site/
The touch command
This command is going to enable you to create а single file on your account through the command-line interface. To execute it, please type:
touch filename
Let us say we are currently in the "public_html" folder again. To create the file named "test.html," please type:
touch test.html
The "create directory" command
This command is going to let you to create directories on your account. To create a directory, please navigate to the desired destination using the "cd" command explained in the previous paragraphs. Afterward, please type:
mkdir directory-name
To create the "my-test-site" directory within the "public_html" folder, please first access the "public_html" folder and type the following command:
mkdir my-test-site
The "remove directory" command
This command can remove existing directories on the server ONLY if they are empty. Otherwise, you are going to receive an error. To remove the "my-test-site" directory we created earlier; please navigate to the "public_html" using the "cd" command and type:
rmdir my-test-site
The remove command
Please be very cautious when using this command, as you can delete important files/folders that you can not recover unless you have a backup:
rm <filename/directoryname>
Let's assume you have an "index.html2" file located in your "public_html" folder, which served as your old index page. To delete it, please navigate to the "public_html" folder using the "cd" command and type:
rm index.html2
To delete a folder, you need to add one option to the command - the "-r," flag which stands for "recursively." Adding this option is going to delete the folder, along with all of its content. Let's suppose you have the folder "old-website" inside your "public_html" folder, which stores an old version of your site, and you no longer need it. To delete it, please type:
rm -r old-website
Executing the above command is going to prompt a question asking you if you are sure you want to delete this folder. Type in the letter "y" to confirm. To avoid this prompt, you can add the "-f" option, which stands for "force." Here is what the command is going to look like:
rm -rf old-website