1

I have found this command online, finding and displaying hardlinks to a file e.g. text.txt.

My question: What is the exclamation mark (!) doing in this command?

find $PWD ! -type d -links +1 -ls | sort -n|cut -d" " -f29 | grep --color=auto "$2"
Zumo de Vidrio
  • 2,021
  • 2
  • 15
  • 33
Andersen SOOS
  • 37
  • 1
  • 2
  • It is also know as a *"Bang"* – Mr. Polywhirl Jan 26 '17 at 00:23
  • 1
    Try using `man find` for documentation on the syntax of that command. – larsks Jan 26 '17 at 00:25
  • Have a look at, for example, http://stackoverflow.com/questions/1341467/unix-find-for-finding-file-names-not-ending-in-specific-extensions (and the man page of `find`). – Benjamin W. Jan 26 '17 at 01:45
  • Please read http://stackoverflow.com/help/how-to-ask , http://stackoverflow.com/help/dont-ask , http://stackoverflow.com/help/mcve and take the [tour](http://stackoverflow.com/tour) before posting more Qs here. Good luck. – shellter Jan 26 '17 at 04:22

1 Answers1

5

This negates the next condition. So ! -type d means "not a directory".

There is one problem, though: ! is also a special character which is used to make bash do history expansion. That's why you often have to escape (... \! ...) or quote it (... "!" ...).

See also: The manual for find (try man find or info find).

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • 1
    I was just reading [BashPitfalls](http://mywiki.wooledge.org/BashPitfalls#echo_.22Hello_World.21.22) and it seems like single quotes are actually needed... (esp before Bash 4.3) (\! might work...) – Gert van den Berg Jan 26 '17 at 14:50