How to delete files and folders via SSH
There may be times when you need to delete a file or folder from the system, and since I can never remember, here's a handy reminder.
To carry out these deletions using SSH, you need to run the appropriate -rm command.
In its simplest form, the command looks like this:
rm myFile.txt myFile1.txt myFile2.txt
However, listing all the files/folders that need to be deleted can be very time-consuming. Fortunately, rm accepts several arguments that can make the task easier. In the example above, you could type
rm myFile*.txt
This will match all files starting with "myFile" and ending with ".txt" and delete them.
To recursively delete an entire folder and its contents, you can use:
rm -rf foldername/
To delete all the files/folders in the current directory, without deleting the directory itself, you need to use:
rm -rf *
Comments