How to Delete Files in Directory in Linux

If you want to delete files within a directory in Linux, you can use this simple command

rm -f /your/directory/*

If you want to delete files and directories recursively within a directory in Linux, you can use this command instead 🙂

rm -rf /your/directory/*


If there are too many files under that directory, you may get an error

-bash: /bin/rm: Argument list too long

To delete many files, change active directory to that directory, and run a command :

cd /your/directory/
ls | xargs rm -f

Make sure you do not type wrong directory before executing the command 🙂

Leave a comment

Your email address will not be published. Required fields are marked *