LinuxQuestions.org
Help answer threads with 0 replies.
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 06-23-2006, 12:47 AM   #1
adamrosspayne
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;

*.mp3
[.]mp3
*.avi
[.]avi
*.mp4
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 Song.zip

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?

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

Rep: Reputation: 151Reputation: 151
You should be able to wrap the argument to rm in quotes so that it doesn't complain about the spaces. For example:
Code:
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
adamrosspayne
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: Tupelo, MS
Distribution: Gentoo
Posts: 6,926

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


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
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


All times are GMT -5. The time now is 08:07 AM.

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