Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have an OSX Mountain Lion Laptop connected to and ubuntu 11.10 system and tried to copy one .csv file from the OSX machine to the ubuntu machine. I stopped the file transfer as I realised it created several empty files in the target folder.

I now have a few hundred files sitting there which I cant delete using:

    sudo find . -name "*.csv" | xargs /bin/rm

It is saying file does not exist....

Any ideas on that?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Don't use xargs without -0.

(Yes, there are other safe ways of using xargs, but if you care about them, read them up elsewhere. If you don't care to memorize a lot of options and scenarios, just don't use xargs, there's usually a better way anyway.)

The problem with xargs is that its input must be quoted in a peculiar way that no other tool produces. In particular, it can't cope with spaces in file names. You don't say what the error are (for future reference, copy-paste error messages), but chances are that one of the matching file names contains a space, and xargs choked on it.

xargs -0 copes with any strange character you may have in a file name. Pass -print0 to find to make it print the names in the right format:

find . -name "*.csv" -print 0 | xargs -0 rm

Note that sudo find … only runs the find command as root, not the rm command. If you want to run rm as root, use

find . -name "*.csv" -print0 | sudo xargs -0 rm

Under Ubuntu (and also under OSX), you can use find's built-in -delete option to delete matching files.

find . -name "*.csv" -delete

If you know that the files you want to delete are empty, better make the find command only look for empty files, so that you don't accidentally delete other files.

find . -name "*.csv" -type f -empty -delete
share|improve this answer
    
Unfortunately nothing but deleting the whole Desktop folder recursively did the job - thank you very much for your input though. –  Harry Haller Sep 5 '12 at 11:07
add comment

Your Answer

 
discard

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.