Finding and removing unwanted files using Linux command line

find -depth -type f -iname ‘*PREMIS*’ > ~/premis

find -depth -type f -iname ‘*PREMIS*’ -exec rm -rf {} \;

Advertisements

2 thoughts on “Finding and removing unwanted files using Linux command line

  1. > find -depth -type f -iname ‘*PREMIS*’ -exec rm -rf {} \;
    Why use -exec when you can use built-in -delete?
    After http://unixhelp.ed.ac.uk/CGI/man-cgi?find :
    > ACTIONS
    > -delete
    > Delete files; true if removal succeeded. If the removal failed,
    > an error message is issued. Use of this action automatically
    > turns on the ‘-depth’ option.

  2. Thank You
    I have recently needed this command again
    I am trying to get rid of empty files in a tree of directories.
    I took your advice and used the delete command (I understand that using this also triggers the -depth automatically)
    This is the command that I ended up using.
    Command:
    find test/ -type f -empty -delete
    Description:
    Find any file (recursively) in the test directory (and remove it only if it is empty).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s