Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
What are you trying to do exactly? What kind of files is your grep trying to match? – Joseph R. Oct 17 '13 at 10:44
What happens if you enclose {} in quotes, i.e. mv "{}". – ladaghini Oct 17 '13 at 10:56
up vote 3 down vote accepted

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"


(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"
share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.