This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

📣 Try the fastest hosting platform with pay-as-you-go pricing & 24/7 expert support! MIGRATE NOW →

How to Use SSH Commands to Handle Files & Folders on Linux Web Server

Updated on December 13, 2021

7 Min Read
SSH Linux Commands

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.

SSH on Cloud

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

  1. Where Am I?
  2. List all files and folders
  3. Change Directory
  4. Create a Folder
  5. Create a File
  6. Rename File
  7. Rename Folder
  8. Copy File
  9. Remove File
  10. Move File
  11. Move Multiple Files at Once
  12. Edit a File
  13. Run a File
  14. Remove Folder
  15. File Permissions
  16. 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.

Cloud Server - Cloudways

Launching SSH Terminal

Once you get into the particular server, you’ll see the server credentials there. Click on “Launch SSH Terminal”.

P.S: To make the process faster, you can access SSH terminal using Putty and SSH keys too.

Cloud Server Terminal - Cloudways

Once you click on the Launch SSH Terminal button, you may see a warning from Chrome.

SSL Warning 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”.

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.

SSH Terminal

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.

Folder

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

Files and Folders

You can see all the files and folders that are present in the root directory.

Change Directory

SSH Command: cd applications

cd – Used to change the current directory

Directory

We’re in the applications folder now.

Below are the steps to get into an application.

PHP 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.

New 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

Create a new file

newfile.php is now successfully created in the public_html folder.

Rename File

SSH Command: mv newfile.php renamedfile.php

mv – Used to rename a file. It will rename newfile.php to renamedfile.php

Rename File

newfile.php has now successfully been renamed to renamedfile.php. Its syntax is mv OLDNAME NEWNAME.

Rename Folder

SSH Command: mv BatchFolder Bat

mv – Used to rename a folder too. It will rename BatchFolder to Bat.

2

BatchFolder has now successfully been renamed to Bat.

Copy File

SSH Command: cp renamedfile.php NewFolder-1

cp – Used to copy files.

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.

Remove File

SSH Command: rm renamedfile.php

rm – Used to remove a file.

Remove Files

The file is now removed successfully.

Move File

SSH Command: mv renamedfile.php NewFolder-1

mv – Used to move files.

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

1

You can see, we’ve successfully moved two files from public_html to BatchFolder.

Edit a File

SSH Command: vi renamedfile.php

Edit File

It will open up the file to write some text.

On your keyboard, press the “INSERT” key and start writing.

Insert Key

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.

Run a File

The file is running successfully.

Remove Folder

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 on Cloud (10)

File Permissions

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.

File Permission

Numerical Permissions

Folder Permissions

Navigate to the directory, you want to set permissions.

SSH Command: chmod -R [PERMISSIONS]

3

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.

Conclusion

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.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Mansoor Ahmed Khan

Been in content marketing since 2014, and I still get a kick out of creating stories that resonate with the target audience and drive results. At Cloudways by DigitalOcean (a leading cloud hosting company, btw!), I lead a dream team of content creators. Together, we brainstorm, write, and churn out awesome content across all the channels: blogs, social media, emails, you name it! You can reach out to me at [email protected].

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour

CYBER WEEK SAVINGS

  • 0

    Days

  • 0

    Hours

  • 0

    Mints

  • 0

    Sec

GET OFFER

For 4 Months &
40 Free Migrations

For 4 Months &
40 Free Migrations

Upgrade Now