LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-09-2003, 10:19 AM   #1
lhorstman
LQ Newbie
 
Registered: Jan 2003
Location: Alexandria, VA
Distribution: Slackware
Posts: 5

Rep: Reputation: 0
Question 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.
 
Old 01-09-2003, 12:40 PM   #2
d3funct
Member
 
Registered: Jun 2001
Location: Centralia, WA
Posts: 274

Rep: Reputation: 31
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. :-)
 
Old 01-10-2003, 03:01 PM   #3
lhorstman
LQ Newbie
 
Registered: Jan 2003
Location: Alexandria, VA
Distribution: Slackware
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks! Thats exactly what I needed.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
copy 3 files to a directory and all subdirectories? snip128 Linux - Newbie 9 08-12-2005 09:18 PM
Copying all files from subdirectories into one directory Hegemon Linux - General 3 01-17-2005 11:25 AM
Unzipping all .gz files in all subdirectories darin3200 Linux - General 10 04-24-2004 09:58 PM
move files to a series of subdirectories acid2000 Linux - General 1 09-01-2003 05:44 PM
How can i delete Directories and Subdirectories? OrganicX Linux - Newbie 15 03-05-2003 08:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration