LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-16-2005, 02:51 AM   #1
tsaravan
Member
 
Registered: Jun 2005
Location: India
Posts: 101

Rep: Reputation: 15
rmdir command does not remove directory with space


Hi,

Following is shell script to delete files and directory automatically every friday.

find /scratch -type f -ctime +2 -exec rm -f -R {} \;
find /scratch/* -depth -type d -print | xargs rmdir 2>/dev/null

the script does not delete empty directory which has directory name with space eg., 'my document'

please let me know if have a solution for the above.

thanx.

T. Saravana
 
Old 08-16-2005, 05:02 AM   #2
andy753421
Member
 
Registered: Apr 2004
Distribution: Gentoo
Posts: 65

Rep: Reputation: 15
here's what I would do, but there's probably a better way. that should take care of spaces, and quote marks. if you have any other wierd things in you're file names youll have to take care of that as well.

#!/bin/bash
find scratch -type f -ctime +2 -exec rm -f -R {} \;
find scratch/* -depth -type d -print | sed -e "
s/ /\\\ /g;
s/'/\\\'/g;
s/\"/\\\\\"/g;
s/^/rmdir /;
" | sh
 
Old 08-16-2005, 05:25 AM   #3
tsaravan
Member
 
Registered: Jun 2005
Location: India
Posts: 101

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by andy753421
here's what I would do, but there's probably a better way. that should take care of spaces, and quote marks. if you have any other wierd things in you're file names youll have to take care of that as well.

#!/bin/bash
find scratch -type f -ctime +2 -exec rm -f -R {} \;
find scratch/* -depth -type d -print | sed -e "
s/ /\\\ /g;
s/'/\\\'/g;
s/\"/\\\\\"/g;
s/^/rmdir /;
" | sh
Thank you for the reply. I am getting error message while executing the same.

1) s/^/rmdir: No such file or directory.
2) unexpected EOF while looking for matching `"'
3) syntax error: unexpected end of file

thanks.

T. Saravana
 
Old 08-16-2005, 09:45 AM   #4
andy753421
Member
 
Registered: Apr 2004
Distribution: Gentoo
Posts: 65

Rep: Reputation: 15
did you copy and paste everything? I dont know what would be going wrong. try changing the end 'sh' to a 'bash' and see if that helps, if not please post you're bash and sed versions.
 
  


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
Why a directory can not be able rmdir? backpacker Linux - Software 3 11-21-2005 07:07 AM
remove directory with shell command? khucinx Programming 2 05-19-2004 01:59 PM
Command to remove a directory... xconspirisist Linux - Software 2 11-28-2003 02:06 PM
RMDIR - how to remove a non-empty directory?? jacksmash Linux - Newbie 15 11-23-2003 01:51 PM
what is the command to remove the directory Harish_f Linux - General 6 06-19-2002 04:32 AM


All times are GMT -5. The time now is 11:09 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration