Help with finding certain files, and then deleting


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with finding certain files, and then deleting
# 1  
Old 03-13-2007
Help with finding certain files, and then deleting

I must really be bad at life today, because I couldn't even find a search option on the forums before asking for help, so I apologize if this is already listed somewhere.

I'm pretty new to UNIX, and basically only know enough to be dangerous. I have been appointed a task to basically go to a directory, find all files that begin with a certain phrase (smith, jones, etc.) and then delete all files that are older than 90 days. Any files within the last 90 days need to be compressed into a TAR file and then archived and moved to another folder.

The problem i'm having is twofold. One, I can't figure out how to get a good listing of all files older than 90 days using the search criteria of the filename (all files starting with jones over the last 90 days). I don't even know if I need this, but I thought it was a good start. I need to delete all these files > 90 days with the certain filename delimiters regardless. I've tried find, but can't figure out the switches, and I can find all the files with the name i'm looking for using ls -lrt | grep jones but that isn't doing me much good. I've searched Google for examples but haven't had any luck yet and am trying hard not to get fired, so I figured posting might be a faster solution.

Once I get those deleted, I need to then archive the files within the last 90 days into a tar and then move that file (or files?) into another directory.

If anyone can help, i'd appreciate it. Much thanks.
# 2  
Old 03-13-2007
Wow, I now see search functions for the forum. I guess they weren't showing up when I was registered but not activated. I suck at the internets today, I swear.
# 3  
Old 03-13-2007
you really need to look at find man page

you should be able to find file with

Code:
find /path -name "smith*"

you are able to execute any command with -exec flag to find :

Code:
find /path -name "smith*" -exec rm -r {} \;

To find files older than 90 days you can have a look at -mtime, -ctime and -atime

Code:
find /path -name "smith*" -mtime +90 -exec rm -r {} \;

Sorry, I don't have more time for this right now .... if you need precision after looking at find man page, post back here.

You should also read about regexp (man regexp) so you can find the right expression to put in -name "expression"
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

2. Shell Programming and Scripting

Finding a match and deleting the line above to it..

Hi All, I have a file with the data: Sun is Hot Moon is cool ; -- Mon Sep 10 08:54:10 CDT 2012 -- Mon Sep 11 08:54:10 CDT 2012 -- Mon Sep 12 08:54:10 CDT 2012 revoke connect from SREE; delete from = 'SREE'; grant connect to SREE with 'fastcar8'; I want to remove the line above... (8 Replies)
Discussion started by: raosr020
8 Replies

3. Shell Programming and Scripting

AIX system.... deleting files in remote directory after retrieving files

Hi Friends, I am new to this , I am working on AIX system and my scenario is to retrive the files from remote system and remove the files from the remote system after retreving files. I can able to retrieve the files but Can't remove files in remote system. Please check my code and help me out... (3 Replies)
Discussion started by: vinayparakala
3 Replies

4. Shell Programming and Scripting

Need help comparing two files and deleting some things in those files!

So I have two files: File1 pictures.txt 1.1 1.3 dance.txt 1.2 1.4 treehouse.txt 1.3 1.5 File2 pictures.txt 1.5 ref2313 1.4 ref2345 1.3 ref5432 1.2 ref4244 dance.txt 1.6 ref2342 1.5 ref2352 1.4 ref0695 1.3 ref5738 1.2 ref4948 1.1 treehouse.txt 1.6 ref8573 1.5 ref3284 1.4 ref5838... (24 Replies)
Discussion started by: linuxkid
24 Replies

5. Shell Programming and Scripting

help with finding text and deleting line

HI All, I need to search for a particular pattern input by the user in order to delete the line. My username.txt has username@email.com:John:149.0.3.4:1 username1@email.com:Harry:149.0.3.4:1 username1@email.net:Alex:149.0.3.4:1 username1@email.edu:Nemo:149.0.3.4:1 The program i written ... (3 Replies)
Discussion started by: ichar
3 Replies

6. Shell Programming and Scripting

Finding a flatfile & deleting first line

I have a small script where I want to see if a file exists & then delete the first line from it. I have code to help me find if the file exists, but I am unsure as to how to then take in the answer and remove the first line from the flatfile: This is what I have so far just to output if the... (3 Replies)
Discussion started by: fatalxkiss
3 Replies

7. Shell Programming and Scripting

Finding duplicate lines and deleting folders based on them

Hi, I have research data, which is organized to 100 folders numbered 00-99. I have many sets of 100 folders, for different values of initial parameters. For some reason, the computer that ran the program to gather the data, didn't always create a unique seed for each folder. I anticipated that... (1 Reply)
Discussion started by: Jopi
1 Replies

8. Shell Programming and Scripting

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. ... (3 Replies)
Discussion started by: guruparan18
3 Replies

9. Shell Programming and Scripting

Deleting / finding files older than X days missess a day

Hi When trying to find and delete files which are, say, 1 day, the find command misses a day. Please refer the following example. xxxd$ find . -type f -ctime +1 -exec ls -ltr {} \; total 64 -rw-rw-r-- 1 oracle xxxd 81 Apr 30 11:25 ./ful_cfg_tmp_20080429_7.dat -rw-rw-r-- 1... (4 Replies)
Discussion started by: guruparan18
4 Replies

10. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies
Login or Register to Ask a Question