I've read in some bash FAQ a while ago (that I don't remember), that which
should be avoided and command -v
preferred.
Why is that so? What are the advantages, disadvantages of either one?
Copy a File ( cp ) You can also copy a specific file to a new directory using the command cp followed by the name of the file you want to copy and the name of the directory to where you want to copy the file (e.g. cp filename directory-name ).
and >&2 means send the output to STDERR, So it will print the message as an error on the console. You can understand more about shell redirecting from those references: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Redirections.
First Command: ls The ls command lists the files in your current directory (ls is short for "list").
The uniq command can count and print the number of repeated lines. Just like duplicate lines, we can filter unique lines (non-duplicate lines) as well and can also ignore case sensitivity. We can skip fields and characters before comparing duplicate lines and also consider characters for filtering lines.
Well...
command
is likely built in to your shell, and with the -v
option will tell you how your shell will invoke the command specified as its option.
which
is an external binary, located at /usr/bin/which
which steps through the $PATH
environment variable and checks for the existence of a file.
A reason to select the former over the latter is that it avoids a dependency on something that is outside your shell.
The two commands do different things, and you should select the one that more closely matches your needs. For example, if command
is built in to your shell, command -v command
will indicate this with its output (through the non-existence of path), but which command
will try to point to a file on your path, regardless of how command
would be interpreted by your shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With