I'm wanting to find multiple files as in

 find /etc/ /usr/ -type f,d -size +1k -exec ls -slah {} /; -exec rm -riv {} +

My question to you is how can I delete only the file size 5k and below with the -exec option

  • 1
    Words? Files? Which is it? – muru May 18 '17 at 1:49
  • Also note that manually deleting files from system directories in this way has Bad Idea written all over it – steeldriver May 18 '17 at 2:44
  • Why, please elaborate ! – user610658 May 19 '17 at 2:49

If I understand your question correctly, you want to:

  1. Look for files under /etc and /usr
  2. Select only those files which are under 5k in size
  3. Delete them

In that case, what you want is this:

find /etc /usr -type f -size -5k -delete

Notice that there is no need for -exec, since you can simply use the -delete option.

In your question you wrote -size +1k. Did you mean to ask about finding files which are between 1k and 5k in size? If that was the case, then you can simply specify the -size option twice:

find /etc /usr -type f -size +1k -size -5k -delete
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy