How to Delete Files and Folders via SSH (2024)

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 simplest form looks like:

rm myFile.txt myFile1.txt myFile2.txt

However, listing all files/folders that need to be deleted can be quite time-consuming. Fortunately, rm accepts several arguments which can ease your task. In the above example, you could type:

rm myFile*.txt

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

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 *
How to Delete Files and Folders via SSH (2024)
Top Articles
Latest Posts
Article information

Author: Rev. Leonie Wyman

Last Updated:

Views: 6143

Rating: 4.9 / 5 (79 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Rev. Leonie Wyman

Birthday: 1993-07-01

Address: Suite 763 6272 Lang Bypass, New Xochitlport, VT 72704-3308

Phone: +22014484519944

Job: Banking Officer

Hobby: Sailing, Gaming, Basketball, Calligraphy, Mycology, Astronomy, Juggling

Introduction: My name is Rev. Leonie Wyman, I am a colorful, tasty, splendid, fair, witty, gorgeous, splendid person who loves writing and wants to share my knowledge and understanding with you.