LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to remove long-windows-filename files based on exlusion list (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-remove-long-windows-filename-files-based-on-exlusion-list-457460/)

adamrosspayne 06-23-2006 12:47 AM

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

gilead 06-23-2006 01:33 AM

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?

adamrosspayne 06-23-2006 02:19 AM

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

Bruce Hill 06-23-2006 02:25 AM

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.


All times are GMT -5. The time now is 02:42 AM.