Categories: Snippets

Remove all files from a directory?

  • To remove the folder with all its contents(including all interior folders):
    rm -rf /path/to/directory
    
  • To remove all the contents of the folder(including all interior folders) but not the folder itself:
    rm -rf /path/to/directory/*
    
  • To remove all the “files” from inside a folder(not removing interior folders):
    rm -f /path/to/directory/*
    

Where:

  • rm – stands for “remove
  • -f – stands for “force” which is helpful when you don’t want to be asked/prompted if you want to remove an archive, for example.
  • -r – stands for “recursive” which means that you want to go recursively down every folder and remove everything.

Recent Posts

How To Troubleshoot Socket Errors in MySQL – Ubuntu

MySQL manages connections to the database server through the use of a socket file, a special…

5 years ago

How to remove .html, .php, etc (extension) from URL?

To remove the .html extension from your urls, you can use the following code in…

5 years ago

Ubuntu with Apache2: Installing and Configuring Your SSL Certificate

Use free/paid SSL certificates https://www.sslforfree.com Enable SSL Module Replace 'default-ssl' with the real site name…

5 years ago

Create zip archive excluding specific Files & Directories

Create archive of all files under public_html directory ignoring all files and folders including text…

6 years ago

how to use sudo command to install .tar.gz?

To install some file *.tar.gz, you basically would do: Open a console, and go to…

6 years ago

Change ownership of the directory in ubuntu

The chown command has the following syntax: [crayon-662f223c3e5d6769557014/] So in your example command it is your primary…

6 years ago