Remove only files in directory on linux NOT directories [closed]

find PATH -maxdepth 1 -type f -delete

BUT this won't prompt you for confirmation or output what it just deleted. Therefore best to run it without the -delete action first and check that they're the correct files.


You can use find with -type f for files only and -maxdepth 1 so find won't search for files in sub-directories of /path/to/directory. rm -i will prompt you on each delete so you can confirm or deny the delete. If you dont care about being asked for confirmation of each delete, change it to rm -fv (-f for force the delete). The -v flag makes it so that with each delete, a message is printed saying what file was just deleted.

find /path/to/directory -maxdepth 1 -type f -exec rm -iv {} \;

This should meet the criteria:

NOT directories
NOT subdirectories
NOT files in these subdirectories.