1

I have a list of files which I got using find / -type f -size +10M -exec ls -l {} \; I got this command from here

How can I remove all these files ?

I tried

sudo rm `find / -type f -size +10M -exec ls -l {} \;`

but it doesn't work.

Also, what does {} \ do ? And what's the use of -exec in this command, will the pipe operator not work ?

4
  • 1
    I recommend you read the find manual page. Commented Sep 27, 2017 at 7:18
  • 3
    As for your problem, why don't you have find execute rm for you instead of ls? Commented Sep 27, 2017 at 7:19
  • @Someprogrammerdude will that work ? Commented Sep 27, 2017 at 7:23
  • '{}' is the placeholder for the exec command (it works a bit like xargs). It is replaced by the file name found for every new file meeting requirements is found. \; is used with -exec option which denotes the termination of exec. Commented Sep 27, 2017 at 7:28

2 Answers 2

1

I think it should be possible to have find run rm on each file found, but I couldn't get it to work.

So here is my solution using a for loop:

for $f in `find / -type f -size +10M`;do rm $f;done
Sign up to request clarification or add additional context in comments.

2 Comments

Outch! find / -type f -size +10M -exec sudo rm '{}' +
@ceving the + did the trick for me. When I tried ending the command with \; it just kept saying "missing argument to `-exec'
0

Thanks guys, I finally got it to work with @some-programmer-dude suggestion:

find / -type f -size +10M -exec rm {} \;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.