Login or Register to Ask a Question and Join Our Community

Find and purge a files in a dir

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find and purge a files in a dir
# 1  
Old 10-19-2007
Find and purge a files in a dir

HI All,

I have recuirement to purge the files in a directory . In that directory i an having many sub-directory .

When i use find command like
find ~/work/test/insert -name "*.*" -mtime +12

it is listing the file not accesed before 12 , It also takes the subdirectories inside the directory ~/work/test/insert .

I want to conside only this directory , not the subdirectories in find . PLease let me know how i can be done.

offcourse i searched the form but this is not working for me

find ~/work/test/insert \(! -name ."*.*") -type f -mtime +1 -print

# 2  
Old 10-19-2007
i know this command is wrong

find ~/work/test/insert \(! -name ."*.*") -type f -mtime +1 -print

i have also done as

find ~/work/test/insert \(! -name ."*.*"\) -type f -mtime +1 -print

the same is also not working .... is there is a way to do this to find only in a directory omitting its sub directory???
# 3  
Old 10-19-2007
The solution depends on the version of find you're using:

find .  -name . -prune -type f -mtime +12

find . -maxdepth 1 -type f -mtime +12

# 4  
Old 10-19-2007
find . ! -name . -prune -mtime +1

This commands work for me .. But i need to specify hthe directory .. If i do like this

find /working/can/transfer ! -name . -prune -mtime +1

find /working/can/transfer ! -name . -prune "*.*" -mtime +1

is not working . please let mew know what needs to change ..

# 5  
Old 10-19-2007
find /working/can/transfer/. ! -name . -prune -type f -mtime +1

Don't get confused by the path (/./), it's valid Smilie
# 6  
Old 10-19-2007
That was really great !... Thanks...

Just a question my command is

find /working/can/transfer/ -name "*.*" -mtime +1 -exec rm -f -r

is there is any way to work with this command like include -prune i tried with

find /working/can/transfer/ -name -prune "*.*" -mtime +1 -exec rm -f -r

it is not working can i know why it is ???..

# 7  
Old 10-19-2007
Given the previous posts:

find /working/can/transfer/. ! -name . -prune -type f -mtime +1 -exec rm -rf {} +

With zsh (even on your old Solaris Smilie):
rm -- /working/can/transfer/*(m+1^/)

Last edited by radoulov; 10-19-2007 at 08:02 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

2. Shell Programming and Scripting

Shell script to find files in dir and updation

Hi, I have the shell script requirement mentioned below : List all java and c files or all files in directory and sub directories' in folder structure in current dir. then search for pattren1 in all files globally and replace with other string . And also check the date... (3 Replies)
Discussion started by: ammulu
3 Replies

3. Red Hat

Find and Chown all files in a DIR except for Root

RHEL 6.3 Could someone tell me how to use the find and chown command to replace all files in a directory owned by user1 (for this example) and replace with user1:group1? Most importantly I dont want to change any files owned by root. I recently used the following command but it changed the root... (4 Replies)
Discussion started by: gps1976
4 Replies

4. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

5. Shell Programming and Scripting

Find the number of files older than 1 day from a dir

Hello All, I need to write a script/command which can find out the number of .csv files residing in a directory older than 1 day. The output should come with datewise (means for each date how many files are there). I've this command, but this command gives the total number of files. It's... (10 Replies)
Discussion started by: NARESH1302
10 Replies

6. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

7. Red Hat

find help with directory purge.

Hi, I have a purge directory called /b02/purge which has backed up directories like this drwxrwxr-x 17 root root 4096 Jan 5 15:33 purge1 drwxrwxr-x 17 root root 4096 Jan 5 16:21 purge.new1 drwxrwxr-x 15 root root 4096 Jan 5 16:21 purge.new2 drwxrwxr-x 17 root root 4096 Jan 12... (3 Replies)
Discussion started by: uxadmin007
3 Replies

8. Shell Programming and Scripting

find string from multiple dir and redirect to new files

Hi, I am new to script and I want find one string from multiple files in diff directories and put that out put to new file. Like I have A,B & C directories and each has multiple files but one file is unic in all the directories like COMM.txt Now I want write script to find the string... (8 Replies)
Discussion started by: Mahessh123
8 Replies

9. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

10. Shell Programming and Scripting

How to find sticky bit dir/files

I need to find all sticky bit dir/files on my system and clean them up if necessary. How to I write a script to do this? Thanks. (2 Replies)
Discussion started by: pdtak
2 Replies
Login or Register to Ask a Question

Featured Tech Videos