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:-

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.

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).

find . -maxdepth 1 -type f -name '.@__thumb'

will show you if, and when yes, how many, of files are to be going deleted.

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

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:-

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

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.

Hi
It should be fine with a softlink with the -L option? Anyway, add the print option.


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> 

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 :wink:

Hi Malcolm,

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

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. :wink:
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.

Hi Henk,
As you have guessed I did not find this in a man page. In fact I am hopeless with regular expressions so if you have time to suggest where I should do more study please do.

Meanwhile I am now trying to master rsync. Will post on this later.
Thanks again,
Budgie2

Hi,

Since you’re using -exec then is suggest you use + instead of ; since openSUSE’S find supports it. -exec forks a child process and with ; it forks per file/directory. while using + find tries to take/process files/directory as much as possible without hitting ARG_MAX. the value of

getconf ARG_MAX

FYI there is also a -delete option in GNU find.

Hm, there are no real regular expressions in that whole command line. Thus, I assume, you are realy lost here.

Did y ou try to find in

man find

about that -exec (it is under the Actions section there)?

You see there that the general form is

-exec command ;

So why do you have ; in your command line? (And I can assure you that you need it!)

My advice is that you realy should read some documentation about bash. That is the program running when you type this command line. That is the program that first interpretes that line. And according to

man bash

(That is a huge document and has a steep learning curve, better try to find some book about shell usage).

Important are in this case of course the section DEFINITIONS (where you will find that ; is a control operator: Red Alert, two usages of the same character in our case).

Also applicble is the section about QUOTING.

================

In general I would say that even trying to use rather simple command lines in bash, a basic knowledge of what happens to your command line as explained in the section EXPANSION is a must.

I was just browsing the forum looking for a possible answer to my thread and found this thread here. I really wonder why you prefer to reply to someone’s question is this critical manner instead of just explaining?
In my opinion, with such replies you would rather not encourage people to learn something about bash or linux but encourage them to just to stay away from its seemingly complexity. If you have a knowledge on something why just not share it?

To the actual find command (This part is for Budgie2](https://forums.opensuse.org/member.php/15973-Budgie2)):
As far as I know every -exec command should be terminated with " ;" in find, where “The semicolon (backslashed to avoid the shell interpreting it as a command separator) indicates the end of the command.” as it is written in Wikipedia on find. Any other syntax such as

 find in_your_directory -name your_name -type d -exec rm {} ;

would just exit with an error.
There is no regex used in this commands, regex means REGular EXpressions and is used in many programming languages for searching for certain patterns somewhere. A typical linux module which uses regex is, for instance, sed.

With this post I do not mean to attack you, Henk, I was just wondering why do you do this …

Konstl

Hi Henk and konstl,
Many thanks to both of you. I am trying to learn but am mainly trying to get things done in between several other unrelated tasks. All help is gratefully received and gentle pushes in the right direction for further reading have been requested and are appreciated.
Will see if there is an O’Reilly book on shells and/or bash but the explanation of the : now understood.
Budgie2