How to delete files from a specific date?


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers How to delete files from a specific date?
# 8  
Old 07-07-2012
i seriously do not recommend using "find" for this problem, as (as you know) it searches recursively...
i prefer the straightforward approach:

Code:
ls -l | grep "May 15" | awk '{print $9;}' | tee /tmp/log

once i'm happy with that output:
Code:
/bin/rm `cat /tmp/log`

This is using some of the ideas also offered above. Primarily, the idea that you are able to check your work (multiple times) before running the final 'rm' command.

oh... and you can add "| grep -v ^d" in that pipeline to avoid grabbing directories.
# 9  
Old 07-07-2012
Quote:
Originally Posted by quirkasaurus
i seriously do not recommend using "find" for this problem, as (as you know) it searches recursively...
i prefer the straightforward approach:
I seriously recommend against recommending to not use find for this task Smilie.

find does not have to recurse into subdirectories if that is not desired. On GNU/Linux and *BSD systems, all finds support -maxdepth n. On systems that do not support that primary, the following gets the job done:
Code:
find "$path" ! -name "$path" -prune ...

Your "straightforward approach" is actually more complicated, brittle, and error prone. In addition to all the reasons mentioned by agama in post #6, filenames with whitespace will not make it through intact.

grep/awk are misc text processing tools. find's primaries know what they're looking at. In my opinion, find is the right tool for the job.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Delete log files content older than 30 days and append the lastest date log file date

To delete log files content older than 30 days and append the lastest date log file date in the respective logs I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs This is my script cd... (2 Replies)
Discussion started by: sreekumarhari
2 Replies

3. Shell Programming and Scripting

Delete file with specific date

let say i have list of file PermissionsDirectoriesGroupSizeDateDirectory or file drwx------2users4096Nov 2 19:51mailv drwxr-s---35www 32768Jan 20 22:39public_htmlt drwx------ 2 users 4096 Nov 2 19:51 mail drwxr-s--- 35 www 32768 Jan 20 22:39 public_html drwxr-s--- 35 www 32768 Jan... (3 Replies)
Discussion started by: Jewel
3 Replies

4. 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

5. Shell Programming and Scripting

How to delete files in specific dir

I've got a problem how to delete files from specific directory. I don't want do it recursively but only in specific directory. So, command like find /home/dirname/ -mtime +8 -type f -exec rm {} \; is not for me because this command will remove ifs files in /home/dirname and all... (2 Replies)
Discussion started by: zukes
2 Replies

6. Shell Programming and Scripting

Delete files created before specific date.

There is a system logging a huge amount of data and we need to delete some of the older logs .I mean the files that are created before one week from today. Here is a listing of files that are sitting there: /usr/WebSphere/AppServer/logs # ls -l -rw-r--r-- 1 root system 3740694 May... (5 Replies)
Discussion started by: moustafashawky
5 Replies

7. Shell Programming and Scripting

Delete lines prior to a specific date in a log file.

Hi all. I have a database log file in which log data get appended to it daily. I want to do a automatic maintainence of this log by going through the log and deleting lines belonging to a certain date. How should i do it? Please help. Thanks. Example. To delete all lines prior to Jun... (4 Replies)
Discussion started by: ahSher
4 Replies

8. Shell Programming and Scripting

How do I delete all files that contain specific text?

Hi all, I want to remove the files from a folder whcih contain a specific text in it. eg: If i have the files like xxxx.NAME.adadd.ajfaj.kjfha agsg.NAME.dfshd.djsh.sdjhf asgd.NAME2.sdhj.djhf.sjdhf shdd.NAME2.dhse.tywe.eyio How to remove the files which contain the pattern "NAME"... (3 Replies)
Discussion started by: sparks
3 Replies

9. UNIX for Dummies Questions & Answers

How to delete specific files only

Hello, I have these files in my directory. ABC123 ABC12.sls.20080809111121 ABC233 ABC12.sls.20080403123212 ABC543 ABC12.sls.20080804231212 ABC323 ABC12.sls.20080809111232 ABC765 ABC12.sls.20080809112343 ABC654 ABC12.sls.20080809113133 I want to delete only files in first... (2 Replies)
Discussion started by: i.scientist
2 Replies

10. Shell Programming and Scripting

delete files in specific directory

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... (2 Replies)
Discussion started by: legato
2 Replies
Login or Register to Ask a Question