Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Recursive Find file & Delete

  1. #1

    Default Recursive Find file & Delete

    I have my multimedia master files on separate drive mounted at /data with link to my home directory ~/multimedia.
    The multimedia is in the usual Music, Photos & Videos directories and below that many subdirectories.
    As part of rebuilding my system it was necessary to rebuild my master files by copying all my multimedia back from a Qnap NAS box. I had forgotten this puts a hidden file in each subdirectory named .@__thumb. In consequence these files have appeared in my master files and I must delete them.

    I intend to use a command along the lines of:-

    Code:
    find . -maxdepth 1 -type f -name '.@__thumb' -delete
    I have tried using this from my home multimedia directory but it does not work. Is this because the directory is linked? Also I have no idea how many levels to use. If I do not use maxdepth, how do I go into subdirectories recursively please?

    I am searching man pages and google but am scared of trashing the whole lot. Grateful for some help please if anybody has a moment.

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,241

    Default Re: Recursive Find file & Delete

    It may not be very important here, but you should always tell which version of openSUSE you use.

    The first arghument is the starting point, You use . , which means the current working directory. As you do not show what your working directory is, we can not comment on the correctness of this.

    You say "but it does not work". This is a useless remark. find does what you ask it to do, thus it works. It may not be what you expect it to do. While in this case we might have an idea about what you thought that would happen and you apperently mean that something else happened, that is not enough to tell exactly what happens and/or what not.

    In any case, when you want to check (without destryoing anything) what files are found by find, just let find print that list before you add any -delete (or other destructive actions).
    Code:
    find . -maxdepth 1 -type f -name '.@__thumb'
    will show you if, and when yes, how many, of files are to be going deleted.
    Henk van Velden

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,241

    Default Re: Recursive Find file & Delete

    My guess is that you should at least increase maxdepth to 2. Works OK in a small test here.
    Henk van Velden

  4. #4

    Default Re: Recursive Find file & Delete

    Quote Originally Posted by hcvv View Post
    It may not be very important here, but you should always tell which version of openSUSE you use.

    The first arghument is the starting point, You use . , which means the current working directory. As you do not show what your working directory is, we can not comment on the correctness of this.

    You say "but it does not work". This is a useless remark. find does what you ask it to do, thus it works. It may not be what you expect it to do. While in this case we might have an idea about what you thought that would happen and you apperently mean that something else happened, that is not enough to tell exactly what happens and/or what not.

    In any case, when you want to check (without destryoing anything) what files are found by find, just let find print that list before you add any -delete (or other destructive actions).
    Code:
    find . -maxdepth 1 -type f -name '.@__thumb'
    will show you if, and when yes, how many, of files are to be going deleted.
    Hi Henk, sorry I was not clear. OK I am using openSUSE 13.2 x86-64 with KDE 4.14.4 desktop.
    The new drive is mounted at /data and formatted with ext4.
    I have created a soft link to my home directory tree by running:-
    Code:
    ln -s /data/multimedia multimedia
    so now multimedia directory is seen in my home tree.

    From a cli (bash - Konsole) I have been running my find scripts and yes of course it works, I just have not given the right instructions, including putting -type in the right place!!! Unfortunately I stll have not got the result I want with even your line of code giving no output. I believe it is because I am working in a directory that is created by a soft link but cannot find way around this.
    I have moved to the actual directory at /data/multimedia and run the script again but alas, no output.
    Many thanks once more for your reply. If you can help further it would be much appreciated.
    Budgie2

  5. #5
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,241

    Default Re: Recursive Find file & Delete

    As I have said so often in so many threads (and you must have seen at least a few of them) we want computer facts, not stories.

    Thus please, between code tags, what you do and see. You should not say (only) you are "moving to a directory", you most probably mean that you used a cd command (and not that you shifted your chair to the other side of the room). Show it! And the following find. And maybe an ls of some directory in there that proves that there is such a file as you are searching for. Show, show, show. Make it possible for us to have as near the same experience as you have when you are sitting before your keyboard/screen and copy/paste what you see, There is no better way for others to assess your actions.
    Henk van Velden

  6. #6
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    27,076
    Blog Entries
    15

    Default Re: Recursive Find file & Delete

    Hi
    It should be fine with a softlink with the -L option? Anyway, add the print option.
    Code:
    cd /data/multimedia
    find . -name '.@_thumb' -type f -delete -print
    
    /data/multimedia> find . -name '.@_thumb' -type f -print
    ./Pictures/Wallpapers/.@_thumb
    ./Pictures/.@_thumb
    ./Videos/.@_thumb
    malcolml@grover:/data/multimedia> find . -name '.@_thumb' -type f -delete -print
    ./Pictures/Wallpapers/.@_thumb
    ./Pictures/.@_thumb
    ./Videos/.@_thumb
    /data/multimedia> find . -name '.@_thumb' -type f -delete -print
    /data/multimedia>
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    SUSE SLE, openSUSE Leap/Tumbleweed (x86_64) | GNOME DE
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!

  7. #7

    Default Re: Recursive Find file & Delete

    Hi Henk and Malcolm,
    I owe you both further apologies. .@__thumb is a directory not a file so what I need to do is find and delete these directories. Will post again with details if I cannot solve it. Meanwhile I shall try harder.
    Budgie2

  8. #8
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    27,076
    Blog Entries
    15

    Default Re: Recursive Find file & Delete

    Quote Originally Posted by Budgie2 View Post
    Hi Henk and Malcolm,
    I owe you both further apologies. .@__thumb is a directory not a file so what I need to do is find and delete these directories. Will post again with details if I cannot solve it. Meanwhile I shall try harder.
    Budgie2
    Hi
    Change the type to -d then
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    SUSE SLE, openSUSE Leap/Tumbleweed (x86_64) | GNOME DE
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!

  9. #9

    Default Re: Recursive Find file & Delete [SOLVED]

    Quote Originally Posted by malcolmlewis View Post
    Hi
    Change the type to -d then
    Hi Malcolm,

    I think I have it now but only with more help!!!

    Code:
    find . -maxdepth 5 -type d -name '.@__thumb' -exec rm -rf {} \;
    This finds the directories and deletes the files which is what I found I needed. The maxdepth 5 is driven by the way my music is stored and I felt my way by increasing having confirmed script achieves objective.

    Thanks again to you and Henk. I have tried to mark thread as solved for the benefit of others.
    Budgie2

  10. #10
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,241

    Default Re: Recursive Find file & Delete [SOLVED]

    Quote Originally Posted by Budgie2 View Post
    Hi Malcolm,

    I think I have it now but only with more help!!!

    Code:
    find . -maxdepth 5 -type d -name '.@__thumb' -exec rm -rf {} \;
    This finds the directories and deletes the files which is what I found I needed. The maxdepth 5 is driven by the way my music is stored and I felt my way by increasing having confirmed script achieves objective.

    Thanks again to you and Henk. I have tried to mark thread as solved for the benefit of others.
    Budgie2
    That is of course one of the many ways to solve this.
    I hope you read enough of the docs (man pages) to fully understand why all rhis is as it is. Especilay the \; at the end.
    Henk van Velden

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •