LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-07-2008, 04:40 AM   #1
lupomanaro
LQ Newbie
 
Registered: May 2008
Posts: 1

Rep: Reputation: 0
Question bash: delete files older than 7 days in a folder and subfoldes


I'am asking help to solve problem on deleting files having symbol ' or " or ( in his name.
Actually I'am using this script:


#!/bin/bash
DIR=$2
GG=$1
##### Ripulitura cestino di rete
rm -f /tmp/lista 2> /dev/null > /dev/null
find $DIR/* -ctime +$GG -depth \
-exec echo "echo \"Rimuovo il file: {}\";
rm -f '{}';
rmdir '{}';
" >> /tmp/lista \;
chmod 755 /tmp/lista
/tmp/lista



It works fine until it find files like this, for example:

file'.txt
test"one".exe
.....
....
and so on


Have you any idea ?
Thanks
Nicola
 
Old 05-07-2008, 10:22 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,118
Blog Entries: 54

Rep: Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787
Quote:
Originally Posted by lupomanaro View Post
Have you any idea ?
In a shell some chars have different meaning. In the case of single and double quotes they need to be escaped, or you need to work the IFS so the shell doesn't interpret them. This should work: 'find . -type f -print0 | xargs -0 -iX /bin/rm -f 'X''.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Bash script to remove files older than 3 days rust8y Linux - General 26 10-04-2012 08:26 AM
Delete files older then 30 days stefaandk *BSD 1 01-07-2008 08:31 PM
script to auto delete files older than X days nocnoc Programming 17 12-06-2006 08:30 AM
delete files older than 30 days using cronjob latheesan Linux - Newbie 5 06-14-2005 02:40 PM
delete files in server that is older than 30 days using cronjob latheesan *BSD 2 06-14-2005 12:37 PM


All times are GMT -5. The time now is 07:00 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration