11

I often find myself using ll which is an alias.

$ type ll
ll is an alias for ls -lh

I always wondered where this was defined as it works both on bash, zsh but not on sh:

# THIS IS SH
$ ll
sh: 1: ll: not found
Eliah Kagan
  • 119,640

3 Answers3

12

In Ubuntu, this alias is defined by default in the ~/.bashrc file, in mine like this:

$ grep "alias ll" ~/.bashrc
alias ll='ls -alF'

Another file read by default is the ~/.bash_aliases. It may not exist until you create it, but it's the recommended way of storing aliases as keeping them in a separate file provides clarity. Your ~/.bashrc contains the following section, the if expression in which loads this aliases file if it exists:

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

As for zsh I suppose the alias is defined in the same manner in your ~/.zshrc file or any file sourced by it. If you use oh-my-zsh it may be contained in lib/directories.zsh or plugins/common-aliases/common-aliases.plugin.zsh.

sh (= dash in Ubuntu) reads only ~/.profile, which normally doesn't contain any aliases as they are defined shell-specific. In the case of an alias as simple as alias ll='ls -lh' however you could go for a definition in ~/.profile. Further reading: Is there a “.bashrc” equivalent file read by all shells?

dessert
  • 40,956
3

For zsh, aliases can be added in .zshrc. ll must have been defined in that file.

You can add an alias in .zshrc by editing it with any file editor such as nano. For example:

alias ll="ls -lh"
Kulfy
  • 18,154
n4t5ru
  • 41
  • 1
0

I ran into the same question on Manjaro Linux, which uses Zsh by default, but I couldn't find any alias defined in the usual spots (e.g. /etc/profile, /etc/zsh/zprofile, grep -rin alias /etc/*, ~/.zshrc, etc.... )

It turns out that Manjaro had installed oh-my-zsh under a system-level location: /usr/share/oh-my-zsh/

Thanks to this answer, I was able to track it down:

zsh -ixc : 2>&1 | grep 'll='

First line shown in the trace output found it:

+/usr/share/oh-my-zsh//lib/directories.zsh:37> alias 'll=ls -lh'
TrinitronX
  • 3,394