1

I have a directory structure like the following:

UltrastarDaily% tree -L 1 . ├── lost+found ├── purple_rsync_bak.06-02-21_06-38-44am ├── purple_rsync_bak.06-02-21_07-41-32pm ├── purple_rsync_bak.07-02-21_08-02-51am ├── purple_rsync_bak.07-02-21_08-17-26am ├── purple_rsync_bak.08-02-21_02-00-06am ├── red_rsync_bak.01-02-21_06-11-39pm ├── red_rsync_bak.06-02-21_06-16-58am ├── red_rsync_bak.06-02-21_06-23-24am ├── red_rsync_bak.06-02-21_06-26-58am ├── red_rsync_bak.06-02-21_06-27-30am ├── red_rsync_bak.06-02-21_06-31-36am ├── red_rsync_bak.06-02-21_06-33-14am ├── red_rsync_bak.06-02-21_06-34-04am ├── red_rsync_bak.06-02-21_06-34-52am ├── red_rsync_bak.06-02-21_06-35-22am ├── red_rsync_bak.06-02-21_06-41-48am ├── red_rsync_bak.06-02-21_07-39-41pm ├── red_rsync_bak.07-02-21_08-01-14am ├── red_rsync_bak.07-02-21_08-17-41am ├── red_rsync_bak.07-02-21_08-38-52am ├── red_rsync_bak.08-02-21_01-56-43am ├── red_rsync_bak.27-01-21_06-13-39pm ├── red_rsync_bak.28-01-21_02-22-31pm ├── red_rsync_bak.30-01-21_12-48-03am ├── rsync-WDPurple.log ├── rsync-WDRed.log ├── WDPurple └── WDRed 

I want to delete all .mp4 files recursively from ...._rsync_bak.... directories.

Currently I am using the command:

find ./ -regextype posix-egrep -regex ".*_rsync_bak.*.mp4" -delete 

However, it does not make sure I am only searching the root directory. It might also delete mp4s from directories that are named like ...._rsync_bak.... but inside WDPurple or WDRed directory.

1
  • 1
    Just use -maxdepth 2 to delete the files inside the directories you mentioned, but ignoring the subdirectories within them. Also don't forget to add -type f to only select files. linux.die.net/man/1/find Commented Feb 9, 2021 at 11:25

1 Answer 1

6

Include the directories in the search path

find ./*_rsync_bak.* -type f -name '*.mp4' -print # -delete 

Replace -print with -delete, or simply append -delete to the end of the command, once you are sure it's picking up no more than the files you expect

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.