How to delete all the files which are more than 3 weeks old in a particular directory.Thnx in advanc


 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support How to delete all the files which are more than 3 weeks old in a particular directory.Thnx in advanc
# 8  
Old 11-17-2009
It should be ".... | xargs rm"

You had "| rm xargs " and I have no idea what that will do.
# 9  
Old 11-17-2009
Hammer & Screwdriver Thats i typogrphical error....

I am sorry.for typographical error....Its just the way, u wrote it
"xargs rm"
# 10  
Old 11-17-2009
below also will give the same result...why to pipe?

Code:
find  /inbound/etl/dev/CMD/  -type f -mtime +21 -exec rm {} \;

SmilieSmilieSmilie
# 11  
Old 11-17-2009
Why to pipe instead of an extra fork/exec all for each file to be removed? <sarcasm>Hrmmmmm.</sarcasm>

Additionally, the -exec syntax is more treacherous for beginners, especially when doing something like "rm". Finally, there is an advantage (espcecially to noobs) to not need to change the find command in order to do the final step.

Finally, xargs is a really awesome tool and it should be in every noob's toolset.
# 12  
Old 11-17-2009
Quote:
Originally Posted by otheus
Finally, xargs is a really awesome tool and it should be in every noob's toolset.
This is my first time to use xargs ..really man WOOOOOOW such a wonderful tool ...I have read the man page and some exapmle about it what a great tool

really thanks otheus SmilieSmilieSmilieSmilieSmilie
# 13  
Old 12-22-2009
What xargs does is convert the output as arguments for the next command.
redirection > makes the stdout of a command to be saved in a file.
piping | makes the stdout of a command to be the stdin of the next command
xargs -0 is an useful option often used with find. This will eliminate most of the problems with space between filenames.
xargs -I alias is another useful option which helps to command more conveniently and also i've seen somethings dont work without this option. dunno why..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

2. Shell Programming and Scripting

List 2 weeks older file on specific directory

Ive been a vocal of FIND command even before. Command below doesnt really give me the file that is older than two weeks.. Is there a script that will list me the log files that i want like for this date December 10, 2014, it shud list me the date between November 26, 2014 and below. When i run... (6 Replies)
Discussion started by: kenshinhimura
6 Replies

3. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurrence of a specific word

he following are the files available in my directory RSK_123_20141113_031500.txt RSK_123_20141113_081500.txt RSK_126_20141113_041500.txt RSK_126_20141113_081800.txt RSK_128_20141113_091600.txt Here, "RSK" is file prefix and 123 is a code name and rest is just timestamp of the file when its... (7 Replies)
Discussion started by: kridhick
7 Replies

4. Shell Programming and Scripting

Move log files with date and delete older than 3 weeks

I have written a script which generate one logfile on every sunday and thursday I want to move the older log files into /tmp directory befor generating new one so i used mv command like mv usr/sbin/appl/logfile.txt usr/sbin/appl/tmp 2) But when i move this file to /tmp it will... (1 Reply)
Discussion started by: Nakul_sh
1 Replies

5. Shell Programming and Scripting

Delete multiple folders in a directory which are two weeks old

I need help. I have to delete multiple directories inside a directory that are two weeks old. Example: Today is July 09, 2012 Folder1 > folder1 (created June 4, 2012) -- should be deleted > folder2 (created June 2, 2012) -- should be deleted > folder3 (created... (4 Replies)
Discussion started by: jasperux
4 Replies

6. UNIX for Dummies Questions & Answers

Cannot delete files and directory

hello i am trying to delete some files and also some directories. However, despite having the required permissions (i m the owner), Permission is being denied. I also tried to delete using find and inode number, but again Permission was denied. :wall: I am new to unix so please dumb down... (8 Replies)
Discussion started by: curiosity
8 Replies

7. Shell Programming and Scripting

Delete all files if another files in the same directory has a matching occurence of a specific word

Hello, I have several files in a specific directory. A specific string in one file can occur in another files. If this string is in other files. Then all the files in which this string occured should be deleted and only 1 file should remain with the string. Example. file1 ShortName "Blue... (2 Replies)
Discussion started by: premier_de
2 Replies

8. Shell Programming and Scripting

Delete the files older than 3 weeks in a particular directory.

Hi, Friends, I am writing a script to delete all the files which are there for more than 3 weeks. I have tried this : find /home/appl/backup -type f -mtime +21 -exec rm -f {} \; But i am not sure if it deletes only the files in specified directory or all the directorinies in the provieded... (3 Replies)
Discussion started by: rajsharma
3 Replies

9. Shell Programming and Scripting

delete all but one files in a directory

what`s the script to do that? assuming my text file is "test.txt" (10 Replies)
Discussion started by: finalight
10 Replies

10. Shell Programming and Scripting

Delete Some Old files from Particular Directory

Hi Team, I am new to scripting. I want to create a script, which needs to keep only 5 days directories and want to remove the old directory from a particular directory. Can Somebody help me with starting this script. All my directories will be created in the name <YYYYMMDD>. Thanks... (2 Replies)
Discussion started by: siva80_cit
2 Replies
Login or Register to Ask a Question