![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Deleting / finding files older than X days missess a day | guruparan18 | Shell Programming and Scripting | 4 | 05-08-2008 03:09 AM |
| df -k and deleting files | ajayr111 | UNIX for Dummies Questions & Answers | 4 | 03-14-2007 04:03 PM |
| Help with finding certain files, and then deleting | Puck | UNIX for Dummies Questions & Answers | 2 | 03-13-2007 08:18 AM |
| finding duplicate files by size and finding pattern matching and its count | jerome Sukumar | Shell Programming and Scripting | 2 | 12-01-2006 12:20 AM |
| Deleting old files | shiroh_1982 | Shell Programming and Scripting | 2 | 06-21-2006 01:42 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Is there an efficient way in finding and deleting files?
Hi
I have a script to find and delete the files which are say, noDaysOld, I am interested to find the number of such files I am fniding for deleting and then deleting it. So, the script I wrote, first finds the number of such files and then deletes, clearly this is two different steps. Step 1: Code:
noOfFiles=$(find $dirPath -type f -ctime $noDaysOld | wc -l) Step 2: Code:
find $dirPath -type f -ctime $noDaysOld -exec rm -f {} \;
Another point is, how can we write the command in step 2 with "xargs"? Will the command performs better with xargs? |
| Forum Sponsor | ||
|
|
|
|||
|
One way is Instead of having two find commands, U can store the output of first find in a file.
Then u can do wc -l and rm. like.. Code:
find $dirPath -type f -ctime $noDaysOld >> output 2>/dev/null noOfFiles=`wc -l output` cat output | xargs rm xargs is a command that accepts list of words and provides those as input to the given command. Iam think that calling a shell script in the -exec is a better approach.. Thanks Penchal Last edited by Yogesh Sawant; 05-21-2008 at 12:38 AM. Reason: added code tags |
|
|||
|
Is it possible to use teecommand here?
I tried and I didn't get any error (any results either), the command was, Code:
find . -type f \( -ctime $noDaysOld -o -ctime +$noDaysOld \) |tee wc -l > noOfFiles | rm -f {} \;
So, is there any way in making this work? Again, if I use xargs here, will this work? |
|||
| Google The UNIX and Linux Forums |