LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   delete files / keep subdirectories? (https://www.linuxquestions.org/questions/linux-newbie-8/delete-files-keep-subdirectories-40850/)

lhorstman 01-09-2003 10:19 AM

delete files / keep subdirectories?
 
Is there an easy way to delete all the files in a large directory tree while keeping that directory structure? I'd like to delete all the files in 16 subdirectories named 00 - 0F which each have 256 subdirectories below them named 00 - FF where I'd also like to delete all files. I would like to keep all 4112 empty directories. All the files are named 00000000 - FFFFFFFF (not that many files, normally about 00000000 - 00000000FF). Could someone give me an easy command to accomplish this or direct me to an appropriate scripting How-To? Thanks.

d3funct 01-09-2003 12:40 PM

Look at the manpage for find and then try this:

Assume the parent directory of the 00 - 0F subdirectories is called /large_directory

find /large_directory -type f -exec ls {} \;

Try this to make sure that the 'find' command is retrieving all the files you want, and NOT listing the subdirectory names.

Then try the same command with a small change, do :

find /large_directory -type f | xargs rm

This will delete all the files listed in the first find command.

You can verify that all the files were deleted by re-running the first find command.

You can verify that the directories under /large_directory still exist by typing this:

find /large_directory -type d -exec ls {} \;

This should return by showing all of your subdirectories.

Hope it helps. :-)

lhorstman 01-10-2003 03:01 PM

Thanks! Thats exactly what I needed.


All times are GMT -5. The time now is 11:09 PM.