Deleting files and folders via SSH

Sometimes you would need to remove a file or a folder from the system. To do so using SSH, you would need to execute the appropriate command – rm.

The command in its simpliest form looks like:

rm myFile.txt myFile1.txt myFile2.txt …etc…

You would notice however that listing all files/folders that need to be deleted can be quite time consuming. Fortunately, rmaccepts several arguments which can ease us. In the above example, we could type:

rm myFile*.txt

This will match all files starting with ‘myFile’ and ending in ‘.txt’

To delete a whole folder and its content recursively, you can use:

rm -rf foldername/

To delete all files/folders in the current directory, without deleting the directory itself, you would need to use:

rm -rf *

Please be very careful when using rm command, as it might have devastating effects on your website/server, should you delete a system file or a folder.


  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

List files and directories using SSH

In order to list all files and directories using an SSH client, you would need to execute the...

Create/Edit files and folders using SSH cmd line

There are various ways you can create a new file using the SSH command line.The easiest and most...

Move and copy files using SSH

Often you will need to move one or more files/folders or copy them to a different location. You...

Extracting and creating archive files via SSH

Sometimes you would need to extract or create an archive file (i.e to install a script, you would...

Searching for files/text using SSH

In some cases you would need to find the location of a given file or to search for a certain text...