How can i delete files in folder by date?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How can i delete files in folder by date?
# 1  
Old 08-07-2006
How can i delete files in folder by date?

Hi,
I have some files on a folder and i want to delete all the files that were created on July.
Thanks,
Kobi.
# 2  
Old 08-07-2006
Computer

Hi,

Copy and paste this when you have used 'cd' to change into the directory you want to work on:

ls -l | grep "[0-9][0-9] Jul" | awk ' {print $9}' | xargs rm -i

Note: this will go ahead and delete all those it found without confirmation to proceed, assuming the files you are wanting to delete have not been modified since they were created

Last edited by miwinter; 08-07-2006 at 10:53 AM..
# 3  
Old 08-07-2006
Hi,
I tried it but it asks me for confirm the delete, and moves on to the next file...
I need it to delete everything on the folder that was created on july automaticaly without confirm.
# 4  
Old 08-07-2006
kobibn,
miwinter suggested the 'rm -i' just so that you could choose to not delete files that you wanted to keep, but were selected by the grep command. If you are sure that all the files are to be deleted, skip the '-i' from the rm command.
# 5  
Old 08-07-2006
Sorry, yes, I meant to add that, but after editing it to ensure you wouldn't delete files with Jul in the name of the file as well, I totally forgot to document that bit! Cheers BT
# 6  
Old 08-08-2006
Quote:
Originally Posted by miwinter
Sorry, yes, I meant to add that, but after editing it to ensure you wouldn't delete files with Jul in the name of the file as well, I totally forgot to document that bit! Cheers BT
Thanks!!! Now i can really use it
# 7  
Old 08-08-2006
My pleasure Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to replace old date with current date dynamically in multiple files present in a folder

I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server $ cat temp.txt RTG*888*TD8*20180201~... (1 Reply)
Discussion started by: Shankar455
1 Replies

2. Shell Programming and Scripting

Grep date pattern folder and zip -->delete

Hi All, OS: Redhat Linux 7.5 Shell: Bash I have some folder like this 2018-09-16 2018-09-17 2018-09-18 2018-09-19 and so on... Everyday one script create a folder with pattern YYYY-MM-DD (it will have so many sub directories files in it) Now what I would like to achieve is a... (1 Reply)
Discussion started by: onenessboy
1 Replies

3. Shell Programming and Scripting

Delete oldest folder based on folder named as date

Hi, I have a script doing backup to synology server, the script create new folder each day with the date as being folder name i.e. 2018-07-30. Just before creating the new folder I want the script to find the oldest folder from the list and delete it including its content. for example... (3 Replies)
Discussion started by: humble_learner
3 Replies

4. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

5. Shell Programming and Scripting

Script to delete files in a folder older than 2 days

hi i need a script to delete the files older than 2 days... if my input is say in a folder versions A_14122012.txt A_15122012.txt A_16122012.txt A_17122012.txt i want my output to be A_16122012.txt A_17122012.txt thanks in advance hemanth saikumar. (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

6. UNIX for Dummies Questions & Answers

Script to delete files in different folder

Hi Experts, i need a little help. i have different folder that contain files that need to be deleted. but those folder contains huge amoung of same with 3 different extention. what i used to do is to delete them using the rm commande rm *.ext *.ext1 *.ext3 what i want to do is to have... (1 Reply)
Discussion started by: yprudent
1 Replies

7. Shell Programming and Scripting

need to navigate into specified folder and delete the files

Hi all, I need to write a script to naviagate into the list of specified folder and delete the files in it. I have mentioned the list of folders in a external file so it can be reusable. The issue is am facing now is that, i am not understating on how to navigate into the folder locations... (6 Replies)
Discussion started by: Nithz
6 Replies

8. Shell Programming and Scripting

Delete files in a folder with a specific ending

Hi I have files that end with .txt.txt that i want to delete. But I also have files that end with .txt that I want to leave intact. How do I specifically delete files that end with .txt.txt in a folder. thanks (5 Replies)
Discussion started by: kylle345
5 Replies

9. Shell Programming and Scripting

delete all the files in folder a which exist in folder b

Hi , I need a script which basically deltes all files in folder a which are alreasy present in folder b say folder a has files abc.txt pqr .txt and b has abc.txt pqr.txt rmr.txt then file abc.txt and pqr.txt from a should be deleted (6 Replies)
Discussion started by: viv1
6 Replies

10. Shell Programming and Scripting

delete all folders/files and keep only the last 10 in a folder

Hi, I want to write a script that deletes all folders and keep the last 10 recent folders. I know the following: ls -ltr will sort the folders from old to recent. ls -ltr | awk '{print $9}' will list the folder names (with a blank line at the beginning) I want to get the 10th folder from... (3 Replies)
Discussion started by: melanie_pfefer
3 Replies
Login or Register to Ask a Question