-1

I have the results of a find command going through xargs to an ls -d. When no files match, I get:

.

as my sole output, because by default ls -d displays:

.

..., when no (filename) arguments are specified. Is there any way for ls -d to omit ., when passed no arguments and just display no output?

Update: You just cannot convince ls -d not to display .:

.

ls -d -A\                # Skip implied
   --hide=.\             # No, really, skip implied
   --ignore=.            # I mean it, damn it!

.

:)

2

Using xargs together with find is sooo 1980s...

Call e.g.:

find . -type d -exec ls -d {} + 

and the ls command will never be called without arguments.

The execplus feature has been added to find in 1989 by David Korn for SVr4.

  • That's me, so 1980s! :) Have an up-vote... – Michael Goldshteyn Jun 1 '18 at 16:08
  • Still, it would be nice to know how to get ls -d to not display anything (i.e., to skip the current working directory and or whatever directory is specified) – Michael Goldshteyn Jun 1 '18 at 16:18
  • 1
    You may use e.g. * as the path argument to find. In this case the output would be empty in case that the working directory is empty. Does this help? – schily Jun 1 '18 at 16:21
0

You tagged , so you probably run GNU xargs, which has this option:

-r, --no-run-if-empty
    If the standard input does not contain any nonblanks, do not run the command. 

With find ... | xargs -r ls -d, ls won't be started at all if find doesn't match anything.

find might still match . explicitly. To avoid that, add ! -name . to the find expression. Or use -mindepth 1 (in GNU find) to prevent find from matching any of the paths given on the command line.

(As for how to have ls itself ignore ., I have no idea.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.