6

found ls binary using whereis but can't find ll why ? How to find where ll binary loacted ?

I found "ls" binary using "whereis" but can't find "ll"

$ whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz

But can't find ll :

$ whereis ll
ll:
Ashish Karpe
  • 2,427

3 Answers3

14

ll is not a binary but an alias of the ls -alF command.

Check the .bashrc file :

$ alias ll
alias ll='ls -alF'
cl-netbox
  • 31,163
  • 7
  • 94
  • 131
hg8
  • 13,462
  • i want to call ll in shell script how to do that gives error : $ /bin/ll > /tmp/file -bash: /bin/ll: No such file or directory – Ashish Karpe Nov 05 '15 at 16:17
  • 7
    And, if I can add something, use type, which is a built-in in most shells, or which (/usr/bin/which) instead of whereis. Differently from whereis, those will detect aliases etc. – kos Nov 05 '15 at 16:40
  • 3
    @kos type, yes, but which will not detect aliases. As you note, it's an executable /usr/bin/which, which does not have access to your shell aliases. – wchargin Nov 06 '15 at 02:59
  • 1
    @WChargin Sorry, I mixed things up / phrased that badly. I use zsh an in zsh which is a built-in (and detects aliases). /usr/bin/which won't detect aliases; which in zsh (and I guess in other shells which have it as a built-in as well) will detect aliases. – kos Nov 06 '15 at 03:57
  • 2
    @kos got it—good to know! – wchargin Nov 06 '15 at 04:04
  • 1
    On some systems, /usr/bin/which can display aliases from bash when invoked as alias | which -i, which is itself often made an alias, as in alias which="alias | which -i". Unfortunately, the version in Ubuntu seems to lack this feature, so while using which can apply generally, it doesn't here :-( – John O'M. Nov 06 '15 at 13:06
7

As noted by kos in the comments, you should use the bash built-in type command which, unlike whereis, is also aware of aliases and shell built-ins:

$ type ll ls cd
ll is aliased to `ls -alF'
ls is hashed (/bin/ls)
cd is a shell builtin

(For the meaning of "hashed", see this question on unix.SE.)

6

Many users like short cuts and this is what an alias is, a shortcut option for users.

Scripts should not use shortcuts, that is not a portable design, as you found out, these alias commands are not consistently defined.

Easiest answer to meet your need, assuming the use of 'll' is repeated:

Within the script, define the alias ll='ls -l', before referencing the command, then the use of 'll' will work throughout this script.

#!/bin/bash
alias  ll='ls -alF'
... (rest of the script)

Better Answer: better to use the full command in the script, provides documentation. Never use an alias in a script that others have to use.

Byte Commander
  • 107,489
  • This interface modified the script line, should begin with a 'hash' character followed by an 'exclamation' then /bin/bash as in '#!/bin/bash' assuming this is a bash script. This is the recommended first line of any bash script. This tells the system which shell to be used to interpret this script. – webmaster LinuxCourses Nov 05 '15 at 16:37
  • 1
    You just need to use code formatting. Select a snippet and hit CTRL+K or click the {} button. Or manually indent each code line with 4 spaces. That's the Markdown syntax used here on StackExchange. See http://askubuntu.com/help/formatting to learn more. – Byte Commander Nov 05 '15 at 17:43
  • Muchos gracias, I was not aware of these formatting options. I see that you have modified my answer, much appreciated. – webmaster LinuxCourses Nov 05 '15 at 20:43