10

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.

1 Answer 1

14
# 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.

2
  • Ah, the edit to the 2nd one makes a lot more sense - I thought I was doing it wrong. What is that parenthesis grouping called so I can find out more about it?
    – Patrick M
    Jan 15, 2014 at 15:42
  • 1
    The paren's are meaningful to the shell, hence, escape them so that the shell doesn't strip them out. man find - the operator with first and highest precedence is the parenthesized expression; search on OPERATORS. The theory behind find is like most C and UNIX evaluation; a Boolean expression, evaluated from left to right, with 'short-circuiting' i.e. once a truth expression is determined (like "if (TRUE or anything else")). Jan 15, 2014 at 15:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .