Find all files in the current directory only excluding hidden directories and files.
For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided.
The -prune primary in find ignores everything except directories, but the combination ! -name ".*" -prune does not prune directories with names starting with a period. A rough equivalent of -maxdepth 1 for use in versions of find that don't have the -maxdepth primary is \( ! -name . -prune \) .
If there is no -exec primary, no -ok primary, and no -print primary in the expression given to find , the -print primary is supplied by default.
The following is a slightly simpler command than MadeInGermany's suggestion and should produce the same results:
Don, your find does not visit any subdirectories,
while my find visits non-hidden subdirectories.
One precision: -maxdepth 1 can be replaced by \( ! -name <basestartdir> -prune \)
where <basestartdir> is . when the start directory is . .
Therefore, I would append /. to a startdir, and add -type d for clarity:
find /startdir/. \( -type d ! -name . -prune \)
And perhaps add -print or -o -print (there is a difference!) for even more clarity.
The original request (Find all files in the current directory only excluding hidden directories and files.) is ambiguous. With the reference to -maxdepth , I thought the intent was to "find all files in the current directory only (excluding hidden directories and (hidden) files)". But, I guess it could also be read as "find all files in the current directory (only excluding hidden directories) and files (in non-hidden directories)".
Maybe ksailesh1 will give us a better description with a small sample file hierarchy and the desired output.