Linux / UNIX: How To Empty Directory

Linux / UNIX: How To Empty Directory

To empty a directory in Linux or Unix, you can use the rm command with the -r and * options.

For example, to delete all files and subdirectories in the current directory, you can use the following command:

rm -r *
Sourc‮ww:e‬w.lautturi.com

This will delete all files and directories in the current directory.

Be careful when using this command, as it will delete all files and directories in the specified directory, including any hidden files. If you want to delete only certain types of files, you can use patterns or file name suffixes to specify which files to delete.

For example, to delete all .txt files in the current directory, you can use the following command:

rm *.txt

Or, to delete all directories in the current directory, you can use the following command:

rm -r */

Keep in mind that the rm command does not have a way to recover deleted files, so use it with caution. If you want to be able to recover deleted files, you can use the trash-put command from the trash-cli package instead. This will move the files to the trash directory, from which they can be recovered if needed.

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