2

I'm trying to move several .avi files that have spaces in from a CD to my home folder. I've already know how to get rid of the spaces:

find /media/mathscd/ | grep -L -r "*.avi" | for file in *; do mv "$file" echo $file | tr ' ' '_' ; done

But I'm struggling to get move to find the edited files and move them en masse into the folder. I keep getting the error mv: cannot stat '(standard input)': No such file or directory. This is the code I'm trying to use:

find /media/mathscd/ | grep -L -r  "*.avi" | xargs -I{} mv {} /home/09murphyt/Downloads/

Can someone please tell me what I'm doing wrong?

2
  • What are you trying to do exactly? What kind of files is your grep trying to match? Commented Oct 17, 2013 at 10:44
  • What happens if you enclose {} in quotes, i.e. mv "{}". Commented Oct 17, 2013 at 10:56

2 Answers 2

3

Your problem is the -L switch to grep. From the man page:

L, --files-without-match
Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match.

So instead of listing the file names that do not match avi it only lists the place where grep didn't find avi. Since grep usually looks in a file, such a switch would list file names not containing the pattern avi within them. In your case, however, since you're piping to grep from find, the file that grep is reading is (standard input). To see what I mean, try:

find /media/mathscd | grep -L "*.avi"

result:

(standard input)

In other words, grep found lines not matching "*.avi" on standard input, which is exactly what happened.

Since find lists file names directly, you only need to invert the sense of the match:

find /media/mathscd | grep -v ".*\.avi"

(note that grep patterns are different from shell wildcards; you also don't need the -r switch)

Also, using find alone:

find /media/mathscd ! -name "*.avi"
2

Try one of these:

find /media/mathscd/ -name *.avi -exec mv -t ~/Downloads/ {} +
find /media/mathscd/ -name *.avi -print0 | xargs -0 mv -t ~/Downloads/

Make sure to test it by replacing xargs mv* with xargs ls first.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.