Use find
for this job
find / -mindepth 7 -maxdepth 7 -iname '*.txt' -exec echo cp {} /destination \;
Modify *.txt
pattern to your needs, and remove echo
if you like what you see on the screen.
Just add a -prune
so that the found directories are not descended into:
find . -type d -path '*/wp-content/plugins/*' -prune -print
You need to quote that *wp-content/plugins/*
as it's also a shell glob.
If you want only the directory names as opposed to their full path, with GNU find
, you can replace the -print
with -printf '%f\n'
or assuming the file paths don't contain newline characters, pipe the output of the above command to awk -F / '{print $NF}'
or sed 's|.*/||'
(also assuming the file paths contain only valid characters).
With zsh
:
printf '%s\n' **/wp-content/plugins/*(D/:t)
**/
is any level of subdirectories (feature originating in zsh
in the early nighties, and now found in most other shells like ksh93
, tcsh
, fish
, bash
, yash
though generally under some option), (/)
to select only files of type directory, D
to include hidden (dot) ones, :t
to get the tail (file name).
Best Answer
The actual limits can depend both on the filesystem you're using, and the kernel.
To find out the limits for a particular mount point, you can use
getconf
(ex. for/
on my machine):PATH_MAX
is the maximum total length,NAME_MAX
if for the filename. The kernel limits are ininclude/linux/limits.h
in the kernel source:For a list of filesystem limits, see Comparison of file systems.
The filesystem limits dictate the maximum nesting level (if any) for directories and then length of file and directory names for that filesystem. The kernel limits dictate how long strings that refer to paths can be.
You can actually have a nesting structure that exceeds the
PATH_MAX
limit. But you won't be able to refer to it with a fully-qualified path from root. You should also expect strange software bugs if you use such deep structures, since a lot of code expects paths to fit withinPATH_MAX
buffers, and checking forENAMETOOLONG
errors (and correctly recovering from them) is probably not one of the best-tested code paths out there.As for organization, just use whatever feels more natural. Keep hierarchies reasonable, avoid strange characters (and whitespace) if you want to be script-safe/friendly. Those limits are quite generous. If you ever get near
PATH_MAX
, it's probably time to reorganize things.If you do want to test out how things behave in very lengthy paths, here's a fast way to generate huge paths:
If you want a deep hierarchy, try with:
And you can get:
But
ksh
gets a bit confused:bash
does do thecd ..
, but the prompt is messed up, the directory name is not resolved - sopwd | wc -c
is actually 16397 after that.