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):
$ getconf PATH_MAX /
4096
$ getconf NAME_MAX /
255
PATH_MAX
is the maximum total length, NAME_MAX
if for the filename. The kernel limits are in include/linux/limits.h
in the kernel source:
#define NAME_MAX 255 /* # chars in a file name */
#define PATH_MAX 4096 /* # chars in a path name including nul */
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 within PATH_MAX
buffers, and checking for ENAMETOOLONG
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:
#! /usr/bin/perl
my $kd = "a" x 255;
for my $i (1..64) {
mkdir($kd); chdir($kd);
}
If you want a deep hierarchy, try with:
#! /usr/bin/perl
my $kd = "a";
for my $i (1..8192) {
mkdir($kd); chdir($kd);
}
And you can get:
$ pwd | wc -c
16394
But ksh
gets a bit confused:
$ cd ..
ksh: cd: ..: [File name too long]
bash
does do the cd ..
, but the prompt is messed up, the directory name is not resolved - so pwd | wc -c
is actually 16397 after that.
With GNU find
you can use the -printf
option:
find . -maxdepth 1 -type d -printf '%f\n'
As noted by Paweł in the comments, if you don't want the current directory to be listed add -mindepth 1
, e.g.:
find . -mindepth 1 -maxdepth 1 -type d -printf '%f\n'
Best Answer
Just add a
-prune
so that the found directories are not descended into: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 toawk -F / '{print $NF}'
orsed 's|.*/||'
(also assuming the file paths contain only valid characters).With
zsh
:**/
is any level of subdirectories (feature originating inzsh
in the early nighties, and now found in most other shells likeksh93
,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).