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 a folder without around 500 subdirectories. There is a lot of trash to be found in it and I want to clean it up.

I have already deleted certain filetypes that I don't want, like images, with this command:

find . -mindepth 1 -iname "*.jpg" -type f -delete

However, I now want to delete all extension-less files. Files like "Shopping list" intead of "Shopping list.txt"

I have tried the following command but it did not work:

find . -mindepth 1 ! -iname "*.*" -type f -delete
share|improve this question

2 Answers 2

up vote 4 down vote accepted

Try this:

find . -type f  ! -name "*.*"  -delete

However, note that the above will not delete files whose name ends in a ., for example foo.. To delete those as well, use this instead:

find . -type f  ! -name "*.?*" -delete
share|improve this answer
    
The second command was my next question. Thanks so much! I could also type find . -type f ! -name "*?.*" -delete to remove files like ".trash" or whatever it was that I didn't need. Don't worry - it wasn't my Home directory, so I didn't lose any config files. –  etsnyman May 15 at 8:43
2  
@etsnyman Better to test first the command without the -delete option! –  Radu Rădeanu May 15 at 8:44
    
@etsnyman not quite, to remove files that start with a dot, use find . -type f -name ".*" -delete the one in your last comment will also delete files with no extensions. And what Radu said! Test first! –  terdon May 15 at 8:47
    
@RaduRădeanu I actually tested it first on a dummy directory with empty files... –  etsnyman May 15 at 8:47
    
@terdon Thanks! –  etsnyman May 15 at 8:48

You could use:

find . -type f ! -name "*.*" -delete
share|improve this answer
    
It worked! Thanks! –  etsnyman May 15 at 8:42

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.