Linux delete script in sub-directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Linux delete script in sub-directory
# 1  
Old 03-18-2010
Linux delete script in sub-directory

Under TEMP folder, it have many sub-folder, example"0015,0016,etc"
I need to discovery those file which are 2 days ago in this sub-folder , and list out to investigate, at the end delete all file in those sub folder, only keep the emptu directory. Thanks
# 2  
Old 03-18-2010
Code:
 find -mtime +2 -exec rm {} \;

# 3  
Old 03-18-2010
Try this ,

Code:
find /tmp/ -mtime  +2 -type f -exec rm {} \;

# 4  
Old 03-18-2010
Do not execute the "find" commands from the previous posts. They will delete a lot more than you want and could crash your system.

This script looks for directories with a four character numeric name, then searches those directories for old files. It then echoes the command which would be executed so you can test the script without deleting anything.

Code:
find /temp_folder_name/ -type d -name '[0-9][0-9][0-9][0-9]' -print | while read DIR
do
       find "${DIR}" -type f -mtime +2 -print | while read FILENAME
       do
               # Remove echo only if you are happy
               echo rm "${FILENAME}"
       done
done

# 5  
Old 03-18-2010
GOOD, THANKS

I WILL TRY IT
Login or Register to Ask a Question

Previous Thread | Next Thread

9 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

Shell script to delete specify directory

I have the following directories under "0.0.0.0" /scratch/builds/snapshotBuilds/0.0.0.0 drwxr-xr-x+ tested-571 drwxr-xr-x+ tested-576 drwxr-xr-x+ tested-597 drwxr-xr-x+ 600 drwxr-xr-x+ 601 drwxr-xr-x+ 602 drwxr-xr-x+ 603 drwxr-xr-x+ tested-604 drwxr-xr-x+ tested-605... (13 Replies)
Discussion started by: ibad_urs
13 Replies

3. Shell Programming and Scripting

Linux shell script delete

Hi Everyone I am beginner and I will really appreciate if I receive any help I want to create linux shell script " delete" that will : 1 create folder "dustbin" if it exists then do nothing 2 move any file that I want to delete from random location into the "dustbin" folder and remember... (4 Replies)
Discussion started by: Oggie25
4 Replies

4. Shell Programming and Scripting

delete only particular file in directory shell script

Hi, what function do we use to delete only particular file that we want in directory shell script for example I want only to delete test.txt in directory how to do it ? in sh Thank (1 Reply)
Discussion started by: guidely
1 Replies

5. Shell Programming and Scripting

script to delete contents in a directory by date

Hi , I am trying to make a cron job to delete the contents of a directory in a linux environment.The contents created before 2 days should get deleted by this job.Here is what i have written : /usr/bin/find / -name *.log -ctime +2 -exec /bin/rm -f {} \; Is it correct....If not so,please... (9 Replies)
Discussion started by: d8011
9 Replies

6. Shell Programming and Scripting

Script to delete all something.txt~ file from a directory

There are some files in a directory like a.tx~ , b.txt~,c.txt~. I want to delete all these files inside that directory and sub directory. How can i do this? #!/bin/bash cd thatdirectory ...... rm -rf *~ ...... (7 Replies)
Discussion started by: cola
7 Replies

7. Shell Programming and Scripting

Sheel script to Delete a set of files from a given directory

I have a file <filestodelete> containing names of files to to be deleted from a directory <filesstore>. I want a script file which accptes the <filestodelete> and also the location of the directory(<filestore>) and deletes all files matching. Thanks in Advance.. (3 Replies)
Discussion started by: VardhiniVenkat
3 Replies

8. Shell Programming and Scripting

shell script which will delete every thing under a directory except a single sub dire

write a shell script which will delete every thing under a directory except a single sub directory (2 Replies)
Discussion started by: alokjyotibal
2 Replies

9. Linux

command in linux to delete a directory

hi all, can anybody tell me command(in linux) to delete a directory which have other directories & files in it. its urgent thanks vikas (2 Replies)
Discussion started by: guptavikas1
2 Replies
Login or Register to Ask a Question