Computing.Net > Forums > Unix > delete files in specific directory

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

delete files in specific directory

Reply to Message Icon

Name: legato78
Date: March 27, 2006 at 22:13:12 Pacific
OS: unix
CPU/Ram: solaris 8
Product: sun solaris
Comment:

i have a directory "ABC" with lots of old files and sub directories in it.
the issue now is i want to delete away files which are older than 15 days in "ABC" without deleting the files in the sub directories and without deleting the sub directory.
i tried using find command but it will drill down to the sub directory and delete files.
i have zero experience in scripting so lots of help will be appreciated :)



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 28, 2006 at 10:01:28 Pacific
Reply:

Unless you are using the GNU find which supports the maxdepth option, what you are asking for is not easy. Place this command in a script of it's own:


find . \( -type d ! -name . -prune \) -o \( -type f -print \) | nawk ' gsub("^./","") '

Now, if you are in the current directory that you want to search, it will only find the files in that current directory. For more info, check this link:

http://www.unixreview.com/documents/s=8925/ur0310e/


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: delete files in specific directory

Delete files from textfile listing? www.computing.net/answers/unix/delete-files-from-textfile-listing/7218.html

How do i recover a deleted file in unix? www.computing.net/answers/unix/how-do-i-recover-a-deleted-file-in-unix/2325.html

Merging files in a directory www.computing.net/answers/unix/merging-files-in-a-directory/7781.html