Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-23-2006, 12:47 AM   #1
LQ Newbie
Registered: Jun 2006
Posts: 19

Rep: Reputation: 0
how to remove long-windows-filename files based on exlusion list

hi guys,

I want search recursively through a directory/subdirectories that contain files of a type i dont want. The unwanted files are listed in my exclusion file /home/knoppix/ex which looks like;

and so on...

If i enter ls -r | grep /home/knoppix/ex

it spits out matching file/s name in the form; Cool Band - Some Cool

the rm command doesnt like this naming convention. I think it needs the full path.

How can i scipt an automatic removal files based on those in my exclusion file?

Old 06-23-2006, 01:33 AM   #2
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 165Reputation: 165
You should be able to wrap the argument to rm in quotes so that it doesn't complain about the spaces. For example:
export MYFILE="some file.mp3"
rm $MYFILE   # Will fail because of the space.
rm "$MYFILE" # Will work (does on my version of bash anyway)
How is your script written? Can you use that syntax?
Old 06-23-2006, 02:19 AM   #3
LQ Newbie
Registered: Jun 2006
Posts: 19

Original Poster
Rep: Reputation: 0
thanks for the help. i ended up using rsync;

rsync -arz source destination --exclude-from=exclusionfile --delete-excluded

I will learn your method too, thanks for the tip :-)
Old 06-23-2006, 02:25 AM   #4
Bruce Hill
HCL Maintainer
Registered: Jun 2003
Location: McCalla, AL, USA
Distribution: Fedora, Gentoo, Ubuntu (all servers at work are openSUSE)
Posts: 6,931

Rep: Reputation: 128Reputation: 128
If you're interested in removing those spaces from Windoze filenames:
To remove the spaces in files in a directory ->
for i in *; do mv "$i" `echo $i | tr ' ' '_'`; done
or a bash script:
###To remove spaces from files
j=`find $1 -printf "%d\n" | sort -u | tail -n 1`
echo "Max dir depth:" $j
for (( i=0; i<=j ; i++ ))
  for name in `find -mindepth $i -maxdepth $i -iname "* *" -printf "%p\n"`
    newname=`echo "$name" | tr " " "_"`
    echo "$name" "$newname"
    mv "$name" "$newname"
Useful for cleaning up Windoze entropy.


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
shell script to remove old files based on date WindozBytes Linux - General 12 06-04-2012 01:21 AM
Remove files based on content stefaandk Linux - General 2 08-13-2005 08:03 AM
cp lots of files argument list too long dtra Linux - Software 4 07-07-2005 09:14 AM
How to sell Linux solutions to a long-time Windows-based customer. vous Linux - Software 13 05-22-2003 06:35 AM
Amazing thing !I could not remove files even i am root and rm -fr filename. whepin Linux - General 6 01-04-2002 06:30 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:35 AM.

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