Linux Delete All Files In Directory Using Command Line

ht‮spt‬://www.lautturi.com
Linux Delete All Files In Directory Using Command Line

To delete all files in a directory using the command line in Linux, you can use the rm command with the -f option to force the deletion of the files and the -r option to delete the files recursively:

$ rm -rf /path/to/directory/*

This will delete all files in the /path/to/directory directory, including any subdirectories and their contents.

Note that this command will delete all files in the directory, including hidden files and files that are protected by special permissions. Be careful when using this command, as it cannot be undone and there is no way to recover the deleted files.

You can also use the find command with the -delete option to delete all files in a directory:

$ find /path/to/directory -type f -delete

This will find all files in the /path/to/directory directory and delete them.

Alternatively, you can use the rm command with the -i option to interactively delete the files, which will prompt you to confirm each file before it is deleted:

$ rm -i /path/to/directory/*

This can be useful if you want to delete some, but not all, of the files in the directory.

These are just a few examples of how to delete all files in a directory using the command line in Linux. The specific steps may vary depending on the distribution and version of Linux that you are using. You can refer to the documentation for the rm and find commands for more information on how to use them.

Created Time:2017-10-29 22:08:53  Author:lautturi