The which function returns the full path to some other function, if I'm not mistaken.
$ which ls # => /bin/ls
But if I wanted to the directory the function is in, how would I do that? I'm thinking of doing something like this:
$ cd $(which ls)
Obviously, that won't work because ls
isn't a directory. Perhaps I'm barking up the wrong tree with which
?
all commands
. There are some commands that are part of the shell calledshell builtins
, in case of Bash you can read about them inman bash
or by typinghelp <COMMAD>
, for examplehelp cd
. However, there are many shell and not all of them have the same set of builtin commands. OTOH, there are command line external programs that are not part of an external shell. It depends on your system what these programs are. – Arkadiusz Drabczyk Jul 23 '15 at 09:20dirname
existed, so I didn't know to even look it up. I'm familiar with the concept of builtins and using man, but it's not terribly helpful unless I know what to look for. So the follow up was, other than going on stackexchange to ask questions, where would one find some listing of builtins in a particular shell? From there, I'm happy to use man (or bro) to learn more about them. – Mike Lane Jul 23 '15 at 14:59dirname
is not a builtin, it's a separate program. In bash you can list all builtins usinghelp
. You can useman -k
to look for programs for a specified task locally. Apart from that, reading and writing shell scripts is the only way to learn new commands. – Arkadiusz Drabczyk Jul 23 '15 at 15:04