LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-18-2015, 05:55 AM   #1
preetham.66666
Member
 
Registered: Jan 2015
Posts: 33

Rep: Reputation: Disabled
Delete all files in particular directory


I want to find a files compile.logs that older than 90 days in /compile directory this can be achieved by using below command

find /compile -mite +90 -name "compile.logs"

and i get out like this

/compile/home/bob/work/para/build.ntb/compile.logs
/compile/home/meta/work/mac/eth/build.ntb/compile.logs
/compile/home/meta/work/core/qlo/hba/ds-x/port1/build.ntb/compile.logs


Now please advice how to delete all the files after build.ntb directory
 
Old 02-18-2015, 06:07 AM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,597

Rep: Reputation: 2690Reputation: 2690Reputation: 2690Reputation: 2690Reputation: 2690Reputation: 2690Reputation: 2690Reputation: 2690Reputation: 2690Reputation: 2690Reputation: 2690
RTFM

Man page for find mentions -delete option.
Use with care.
 
Old 02-18-2015, 06:12 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,120

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Might depend on how you define "all" in the following - "how to delete all the files after build.ntb directory".
And, of course, which "build.ntb directory".
 
Old 02-19-2015, 02:02 AM   #4
pantdk
Member
 
Registered: Oct 2011
Location: New Delhi
Posts: 248
Blog Entries: 3

Rep: Reputation: 17
check it shown the exact dated files then move for deleted before delete check whether you are able to see the older logs

find /compile -type f -mtime +90 -name "file.log" -exec ls -lrt {} \;
 
Old 02-22-2015, 09:44 PM   #5
preetham.66666
Member
 
Registered: Jan 2015
Posts: 33

Original Poster
Rep: Reputation: Disabled
Hi

I wrote script to find the files which older than 80 days and file name contains compile_dut.log

output should be like below
/compile/home/bob/work/para/build.ntb/compile_dut.log
/compile/home/meta/work/mac/eth/build.ntb/compile_dut.log
/compile/home/meta/work/core/qlo/hba/ds-x/port1/build.ntb/compile_dut.log

and i want to delete all the files under (that is what are the files along with compile_dut.log)
/compile/home/bob/work/para/build.ntb/
/compile/home/meta/work/mac/eth/build.ntb/
/compile/home/meta/work/core/qlo/hba/ds-x/port1/build.ntb/

Please verify my script and let me know any changes required here

#!/bin/sh
#find the files which older than 80 days and file name contains compile_dut.log
find /dv4 -mtime +80 -name 'compile_dut.log' > /dv4/80days.txt
#Remove 15 chars in path
while read line
do
echo -e "$line" | sed 's/.\{15\}$//' >> /dv4/delete-dv4.txt
done < /dv4/80days.txt
#Go to specified directory and delete all the files
while read line
do
cd $line
rm -rf *
done < /dv4/delete-dv4.txt
rm -f /dv4/80days.txt
rm -f /dv4/delete-dv4.txt
 
Old 02-27-2015, 10:52 AM   #6
Slax-Dude
Member
 
Registered: Mar 2006
Location: Valadares, V.N.Gaia, Portugal
Distribution: Slackware
Posts: 528

Rep: Reputation: 272Reputation: 272Reputation: 272
Try this:
Code:
#!/bin/bash
list_of_directories=$(find /dv4 -mtime +80 -name 'compile_dut.log' | rev | cut -d '/' -f 2- | rev)
for each_directory in $list_of_directories; do
  echo "$each_directory/"
# rm -rf $each_directory/*.*
done
...if you are happy with the output, uncomment the rm line
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Cannot delete a recently created directory in Lubuntu, or files in that directory l33y Linux - Newbie 26 06-07-2014 05:49 AM
How to extract all files on a directory and delete all files? moisespedro Slackware 9 01-21-2014 11:55 AM
Can't delete directory and files Anup D. Linux - Enterprise 3 01-26-2013 09:19 AM
How can I delete a directory and its files? OrganicX Linux - General 6 09-01-2002 04:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration