An SSH Terminal is the Command Line Interface (CLI) and the core handler of a server. If you have access to it, there is nothing you can’t do with SSH commands. Several WordPress hosting providers, especially Cloud service providers do not provide an online file manager directly owing to security flaws and bad performance. To upload, download, delete, edit or even rename a file, users have to log in to their server by using an FTP client.
In this guide, I will introduce a list of frequently used Linux SSH commands.
The Power of SSH Commands:
Let’s look at an example. If you have a text box accompanied by a button to save the text from the textbox, you are limited to saving the text alone. But if you want to delete the text, you won’t be able to do so because there is no button to delete the text.
When it comes to differentiating UI based programs and command line interfaces, CLI always wins in the terms of power. Yes, we know it’s hard to handle things in CLI.
To overcome this hurdle. You just have to have basic knowledge of command line interface. It’s the same as in our desktop PCs as shown the image below.
What Can We Do Using SSH Commands?
One can say that the SSH terminal is the control room for your cloud server. While you can execute a countless number of SSH commands from the terminal, today we’ll only cover folder and file management related tasks mentioned below.
Linux SSH Commands for Files and Directories
- Where Am I?
- List all files and folders
- Change Directory
- Create a Folder
- Create a File
- Rename File
- Rename Folder
- Copy File
- Remove File
- Move File
- Move Multiple Files at Once
- Edit a File
- Run a File
- Remove Folder
- File Permissions
- Folder Permissions
Here, you are going to learn a few basic SSH commands to perform on your files and folders by using the SSH Terminal so that you can control your files & folders without connecting to an FTP client again and again.
Let’s dive in without any further ado…
Login to Your Hosting
We’ll be using Cloudways – A Managed Cloud Hosting Platform(paas cloud services) for our tutorial.
Login to your Cloudways account and go to the Servers tab.
Launching SSH Terminal
Once you get into the particular server, you’ll see the server credentials there. Click on “Launch SSH Terminal”.
Once you click on the Launch SSH Terminal button, you may see a warning from Chrome.
Basically, it appears when an SSL certificate is not validated across the domain name. As you can see in the address bar, this is not a regular domain, it’s the IP address of our server and it is private. An SSL certificate can not be issued to it.
Ignore this warning after clicking on the advanced tab and “Proceed to xxxxx”.
Accessing the SSH Terminal
Go back to the server details, copy “Username” and paste on the terminal after clicking right button, then select “Paste from browser”.
Go back to the server details, copy “Password” and paste it on the terminal with the same procedure defined above. You will NOT see the password written in plain text, this is the default behaviour of the terminal. Do not worry, just press the Enter button after pasting the password.
After successfully logging in, you’ll see a screen like in the image below.
We are finally logged in to our server via SSH Terminal and we now have a simple PHP “Application”.
Getting Inside an Application
We know we’re in the root directory. But just for your information, you should know the directory you’re currently in.
Where Am I?
SSH Command: pwd
pwd: This will display the folder you’re currently in.
This is the root directory of the Cloudways platform.
List all Files and Folders
SSH Command: ls
Ls – Used to list all files and folders
You can see all the files and folders that are present in the root directory.
SSH Command: cd applications
cd – Used to change the current directory
We’re in the applications folder now.
Below are the steps to get into an application.
cd applications – Get into Applications folder
ls – List all files in the applications folder
cd efaryzckmf – Get into efaryzckmf (our application) folder
ls – List all files in efaryzckmf folder
cd public_html – Get into the public_html folder
ls – List all files and folders in public_html folder
Create a Folder
Now we’re going to create a folder so that we can play around with it.
SSH Command: mkdir NewFolder-1
mkdir – Creates a new folder within public_html folder.
You can see that the NewFolder-1 has been created successfully!
Create a File
SSH Command: touch newfile.php
touch – Used to create a new file
newfile.php is now successfully created in the public_html folder.
SSH Command: mv newfile.php renamedfile.php
mv – Used to rename a file. It will rename newfile.php to renamedfile.php
newfile.php has now successfully been renamed to renamedfile.php. Its syntax is mv OLDNAME NEWNAME.
SSH Command: mv BatchFolder Bat
mv – Used to rename a folder too. It will rename BatchFolder to Bat.
BatchFolder has now successfully been renamed to Bat.
SSH Command: cp renamedfile.php NewFolder-1
cp – Used to copy files.
ls – List all files and folders in public_html
cd NewFolder-1 – Get into NewFolder-1
ls – List all files and folders in NewFolder-1
You can see, the file is copied successfully. Its syntax is cp SOURCE DESTINATION.
SSH Command: rm renamedfile.php
rm – Used to remove a file.
The file is now removed successfully.
SSH Command: mv renamedfile.php NewFolder-1
mv – Used to move files.
You can see that the file has moved successfully. Its syntax is mv SOURCE DESTINATION
cd .. – Used to go one step back
ls – List all files and folders in the public_html. Currently, you can see the file renamedfile.php there.
mv renamedfile.php NewFolder-1 – Moving file renamedfile.php to NewFolder-1
ls – List of all files and folders in the public_html. You can see, file is not there anymore, as it is moved.
cd NewFolder-1 – Get into NewFolder-1
ls – List all files in NewFolder-1. You can see the new file is there.
Move Multiple Files at Once
SSH Command: mv ht.html renamedfile.php ./BatchFolder
You can see, we’ve successfully moved two files from public_html to BatchFolder.
Edit a File
SSH Command: vi renamedfile.php
It will open up the file to write some text.
On your keyboard, press the “INSERT” key and start writing.
Once you’re done, press “ESC” and you will exit from the editor. Then press “ SHIFT + : ” and it will direct you to type a command line at the bottom left.
Type anyone of the following.
q! – Exit without saving
x! – Save changes and Exit
Run a File
SSH Command: php renamedfile.php
php – It is used to run a PHP script.
The file is running successfully.
SSH Command: rm -r NewFolder-1
rm – It is used to remove files and folders. To remove a folder and its sub folders/files the -r is used. It represents the removal of all files and subfolders within a folder.
SSH Command: CHMOD 755 renamedfile.php
CHMOD – Used to control file permissions
P.S: If you are on Cloudways server, you might need to reset permissions so that the server admin can change the file permissions. To reset, navigate to your application, from the left pane, go to Application Settings and click on Reset Permission. Before making any changes, read the File Permissions guideline first.
Navigate to the directory, you want to set permissions.
SSH Command: chmod -R [PERMISSIONS]
For more details about File Manager related commands. You can refer to “Linux Commands” page.
Stop Wasting Time on Servers
Cloudways handle server management for you so you can focus on creating great apps and keeping your clients happy.
We’ve already mentioned that most cloud providers do not integrate online file manager with their servers due to security, privacy, and performance related issues. This is why we listed the most frequently used Linux SSH commands, keeping in mind your needs and convenience. You can now manage your servers and applications even if you do not have an online file editor.
You have probably observed the power of SSH terminal commands from the article above. However, it’s not possible to cover every feature in a short article, hence we kept it limited. If you have any query though, feel free to ask by using the comments section below. You can also mention other features related to the file manager.
Passionate about technology, entrepreneurship, and marketing, Mansoor Ahmed Khan is in computing since he knows how to type on a keyboard. His daily life is rocked by his family, projects, and his screen. Probably in this order, he likes to be convinced at least. You can reach out to him at [email protected].