11

I want to use find for getting all simlinks and regular files. I can use the -type for these individually, and I can use -o to string them together, but I apparently can't do -type fl.

Is there a way condense this command? It's pretty burdensome.

find -type l -name node-dev -exec ls -lah {} + -o -type f -name node-dev -exec ls -lah {} +

I would like to be able to run it without the -o, like:

find -type lf -name node-dev -exec ls -lah {} +

The man page seems to indicate this isn't possible (it doesn't say anything about extra -type flag arguments), but I thought I'd ask anyways and try to learn something.

Note the files have no guarantee of any kind of reasonable extension naming structure, so any regex based solutions probably won't work. Also, I could use the '!' operator to exclude directories like this answer suggests, but I'd ideally like to exclude more than just directories from the search.

Patrick M
  • 501

1 Answers1

15
# Apply to only link or file type directory entries: 
$ find . \( -type l -o -type f \) -name node-dev -exec ls -lah {} \;

# Apply to anything but a directory - add more with -o in between "\(" & "\)" meta-characters:
$ find . ! \( -type d \) -name node-dev -exec ls -lah {} \;

Note that on the find command, there is a -ls switch which could replaces the -exec call, keeping in mind that find can be slow to begin with, but having to create a new process for each found file does use system resources better utilized elsewhere.