Dynamically change find -maxdepth value given specific subdirectoy name - find

tl:dr I am trying to get find to completely ignore a specific subdirectory regardless of depth.
I am asking this question in reference to a line of code from maldets open source. It is the find command that generates the filelist that the scanner is to examine.
I know find will start at whatever dir specified, at a given maxdepth value.
Is it possible to change the maxdepth level at say dir/subdir/Thisleveldir so that when using the flag -D search nothing below Thisleveldir/ is listed?
For instance I want to search the /home directory to a max depth of 15
find /home -maxdepth 15 -type f -size +100M
until the pwd is /home/user/ReallyHugeDirThatDoesntNeedToBeSearched/ at which point -maxdepth gets set to 1
then once the pwd again is not that specific subdirectory -maxdepth reverts to its previous value of 15.
Is this possible?

Related

Zsh completion caching policy explained

I'm writting some zsh functions using the powerful completion feature. The computation of my completions take some times and I want to make use of the completion caching policy. From the zsh manual (https://zsh.sourceforge.io/Doc/Release/Completion-System.html) I found this code snippet
example_caching_policy () {
# rebuild if cache is more than a week old
local -a oldp
oldp=( "$1"(Nm+7) )
(( $#oldp ))
}
I couldn't find any explanation on the (Nm+7) syntax, what does Nm means ? With try and error I could find out that for example Nms+1 would change the cache policy to 1 second, while Nmh+1 to 1 hour. But where can I find the general (NmX+N) construct explanation ?
Same what does exactly means the line (( $#oldp )) ?
I can explain the (Nm+7)
man zshexpn, search for Glob Qualifiers
a[Mwhms][-|+]n
files accessed exactly n days ago. Files accessed within the last n days are selected using a negative
value for n (-n). Files accessed more than n days ago are selected by a positive n value (+n). Op‐
tional unit specifiers `M', `w', `h', `m' or `s' (e.g. `ah5') cause the check to be performed with
months (of 30 days), weeks, hours, minutes or seconds instead of days, respectively. An explicit `d'
for days is also allowed.
Any fractional part of the difference between the access time and the current part in the appropriate
units is ignored in the comparison. For instance, `echo *(ah-5)' would echo files accessed within the
last five hours, while `echo *(ah+5)' would echo files accessed at least six hours ago, as times
strictly between five and six hours are treated as five hours.
m[Mwhms][-|+]n
like the file access qualifier, except that it uses the file modification time.
N stands for NULL_GLOB, if zsh matches nothing, it will remove the pattern.
Without this N option, if it matches nothing it will print an error.
Example with 4 files
$ touch lal # = updates file modification date to now
$ ls
lal lil lol tut
$ ls l*(m+7)
lil lol
# files older than 7 days starting with l
$ ls l*(m-7)
lal
# files younger than 7 days starting with l
$ ls l*(m+200)
zsh: no match
# no files older than 200 days
$ ls l*(Nm+200)
lal lil lol tut
# N = NULL_GLOB made disappear the non-matching pattern so it's just ls

I don't see data older than 72h

i have problem with my graphite (I think so)
when i set eg. CPU-system diagram to 72h is all ok, i see data etc.
when i set more than 72 - eg. 73 or 73-89h from this moment i see empty graph
I can't even see the latest data 72h
I try change storage-schemas.conf eg.
[default_1min_for_2weeks]
pattern = .*
retentions = 10s:100h,5m:168d,10m:1y
I try change by this option
find /var/lib/carbon/whisper-ng/* -type f -name '*.wsp' -exec whisper-resize --nobackup {} 10s:100h 5m:160d 10m:1y \; -exec chown carbon:carbon \;
but sometimes it help, but not for long after couple days problem is back
Interestingly, it works normally on some charts (all data from collectd)
Graphite-web 1.2.0DEV
go-carbon 0.13.0

How can I stop find from searching a dir tree once it finds a match?

This is a variant of "How can I stop find from searching after first result found?" which I posted earlier today but is different enough to warrant a new question (IMO). It involves the find command ant potentially a perl soln if find can't do what I need.
Using find, I want to search a dir tree for all instances of dirs with name "out". Once an instance of "out" is found, I want it to stop searching under that dir but keep searching other paths for "out".
Consider this example...
mkdir -p top/a/b/out/c/d/out/e/leaf
mkdir -p top/a/bb/cc/out/dd/ee/out/ff/gg/out/hh/leaf
I want to find...
top/a/b/out
top/a/bb/cc/out
... but no other instances of "out".
Also, I want it to stop searching (wasting time) once it hits an instance of "out" in a path.
I am going to run this in perl, so I suppose I could get creative and write some recursive func to do this. And so I will also tag this with question with "perl" should that be the eventual solution.
Use the -prune action:
find top -name out -print -prune
This action prevents find from recursing into a directory.

Can't make a directory using a variables value - Command Prompt

I'm trying to set up a simple backup process for a folder on my C drive that will back that folder up to another location on the network. I know how to create a scheduled task but I'm struggling to understand why my command prompt code won't work - I'm a novice when it comes to the Command Prompt though!
So my question is two fold:
Why does echo %variableName% not return the variable value - it only returns %variableName%.
This is what I type in:
#echo off
set varA = 5
echo %varA%
%varA% <- This is what its popping out
Do I need different preceeding and succeeding characters for this?
I want to create a folder with the date for the name (I do realize that are quite a few questions out there on this but they didn't work), how do I do it?
Here is what I tried:
set folder_name = %DATE:/=_%
set folder_name <- Display value for folder_name
folder_name = Wed 11_06_2013 <- Actual value
When I try to do this:
mkdir %folder_name%
dir
Creates a folder with this %_date% as the name.
Where am I going wrong?
Thanks
Space is significant in SET statements.
SET varspace=spacevalue
will set a variable named "varspace" to "spacevalue"
Remove the spaces and it should be plain sailing...
Oh - except that if the variable contains a space, then commands such as MD or mkdir (which are synonyms) require "rabbits ears" around the value, thus:
mkdir "%folder_name%"

ClearCase: How to find elements that do NOT have a particular label

I'm looking for a ClearCase command that will list all the elements that are visible in my current view, but do NOT have a particular label applied to them.
Say for example, most of the elements that are visible in my view have LABEL_X applied to them. I want a list of those elements that do not have LABEL_X.
I obviously need to use cleartool find, but the usage and ClearCase man page baffle me in terms of how to construct a query like this.
This should work:
ct find -all -ele '! lbtype_sub(LABEL_X)' -print
ct find -ele '! lbtype_sub(LABEL_X)' -print
Notes:
ct stands for cleartool
Unix syntax here (for windows, replace simple quotes with double quotes)
beware of the space between ! and lbtype_sub (in winodws you do not need the space)
-ele very IMPORTANT to get only one occurrence of a given file (and not all the different versions of a file matching a criteria)
-ele limits the search to elements, not versions (that would trigger a lot more results with versions involved...)
-all list all elements included "deleted" (that is "unreferenced") ones.
The second line lists only visible elements (in the current view)
You should execute those second command lines on the sub-directory of your choice within a given ClearCase (snapshot or dynamic view): all files within that sub-directory (and sub-sub directories...) matching the cirteria will be listed.
Warnings:
files and directories are listed. If you want only files, add -type f to the query:
ct find -type f -ele '!lbtype_sub(LABEL_X)' -print
what is displayed is the extended path for elements, that is the name of the file followed with ##.
To list only the name without ##, use '-nxn' (no extendedpathname option)
ct find -nxn -ele '!lbtype_sub(LABEL_X)' -print
Another more complex but also more complete way to list only the name without ##, is to use descr -fmt. For instance:
ct find . -ele "!lbtype_sub(LABEL_X)" -exec "cleartool descr -fmt \"%En %d\n\" \"%CLEARCASE_PN%\""
ct find . -ele '! lbtype_sub(LABEL_X)' -exec 'cleartool descr -fmt "%En %d\n" "$CLEARCASE_PN"'
would give you (in windows or unix syntax) the date and name of the files and directories not labeled LABEL_X.
With that 'descr -fmt' display, you can combine any kind of information and presentation you want for the result.
Above works, but remember to specifiy -cview to get JUST the current view, otherwise you'll get files from all the other views as well.
I needed to use the following on my Linux clearcase install:
cleartool find -cview -all -version '\!lbtype(LABEL_X)' -print
The syntax from VonC's post did not work properly with the "!" not being escaped.