Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I use surveillance software witch collects clips from IP cameras. This software creates directory's on HDD named as date of creation video clip it contains.
Additionally each such directory contains "special" subdir, named
Code:
.@__thumb
containing thumbs of all video clips this directory contains.
The content of this "special subdir" is refreshed each day automatically by surveillance software.
So, time of creation of video clip is equal to modification time. But time of modification of "special subdir" is always set to today. So time of modification of all directory with all clips is set to today too.
Linux does not keep informations about creation time. Only access and modification time is available.
I want to remove all files and directory's older then 30 days. It is easy with video clips in the way like this
How can I modify the code line above, to delete all directory's containing only one hidden subdir?
then, as per pan64, try Perl, as you'll need to count how many hidden subdirs there are to get just the upper dir that contains only one hidden subdir (iiuc)
Try starting here https://docstore.mik.ua/orelly/perl4/cook/ch09_06.htm.
Quote:
what are dot files again?
Well, '.' is curr dir (aka pwd) and '..' is parent dir.
.xxx can be a dir or file and just contains stuff eg .mozilla in $HOME contains firefox cfgs etc.
dot files are often ignored by 'normal' cmds (wildcards) and need more special coding to catch them.
It looks like right way. But how can I "find" directory containing only one subdir named ".@__thumb" and no other files?
again, find is unable to do that, this is not the right way.
You need to implement a script which can check if a directory contains only one subdir (named ".@__thumb") and nothing else.
i'm a little confused about the examples in post #1, and how you used placeholders like "dir" and "subdir".
would it be possible to show us the exact names and what you want to delete? maybe coupled with the output of 'tree'?
furthermore, i am thinking that the thumbnail's name should reflect on the movie clip's name.
I think you must postprocess the find output, e.g. with awk
Code:
find /record -type d -name ".?*" -prune -print -o -print |
awk -F/ '{ x=$0; sub("/[^/]*$","",x); c[x]++ } ($NF==".@__thumb") { d[x] } END { for (i in d) if (c[i]==1) print "rm -rf", i }'
Add a pipe to sh to run the rm commands.
Explanation: in order to run faster, find prunes all .xxx directories.
In the embedded awk code, x is the dirname of each pathname, c[] counts the directory entries, d[] stores the directories that have .@__thumb. At the END i loops through the d[] keys, and prints if the corresponding c[] is 1.
Last edited by MadeInGermany; 05-12-2017 at 02:33 PM.
Here seems to be one way of finding them. The following recursively finds all directories that do contain a subdirectory named 'foo' but at the same time don't contain any regular files:
Code:
for f in $(find /some/directory -type d -exec test -d {}/foo \; -print); do
find $f -mindepth 1 -maxdepth 1 -type f -print | grep -m 1 -q . || echo $f;
done
Note: it will choke on names with spaces.
Last edited by Turbocapitalist; 05-13-2017 at 12:25 AM.
Reason: -m 1
I'm really sorry, I have to say probably that works, but you made four loops which is very-very inefficient (a for loop, 2 find loops and a grep). And hard to understand.
That's why I suggested to use for example python, the os.walk module will deliver all the information you need to be able to decide.
You can also try to process the output of ls -lR too (which eventually runs faster than find) with awk.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.