19

I entered la accidentally instead of ls to view the contents of a directory and it produces exactly the same output as ls...

Why is this? Surely it doesn't make sense to have two commands that do the exact same thing.

TellMeWhy
  • 17,484

6 Answers6

34

la is an alias to ls -A defined in ~/.bashrc file in Ubuntu.

It only shows the same output if you have no hidden files or directories.

ls -A shows hidden files and directories.

Pilot6
  • 90,100
  • 91
  • 213
  • 324
  • 3
    More like "it does not necessarily show the same output", since if you don't have any hidden files (those starting with a dot) besides . and .., the output will be the same. – Muzer Dec 22 '16 at 16:43
  • 1
    That is true. Updated. – Pilot6 Dec 22 '16 at 18:36
  • 2
    Note that ls -A is different to ls -a - the latter will show the . and .. meaning this directory and containing directory respectively. – Tim Dec 22 '16 at 21:01
14

la is defined as an alias in Ubuntus ~/.bashrc file together with a few others. la is simply an ls -A as you can see in the following snippet from the ~/.bashrc

# this alias is defined earlier to grant colored output
alias ls='ls --color=auto'

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias li='ls -lF'
Videonauth
  • 33,355
  • 17
  • 105
  • 120
8

When in doubt, type la.


Bash output:

la is aliased to `ls -la'

Fish output:

la is a function with definition
function la --description 'List contents of directory, including hidden files in directory using long format'
    ls -lah $argv
end
6

ls is a command, l and la are most likely aliases which make use of the command ls. If you run the command alias you can find all the aliases on your system.

$ alias | grep -E ' l=| la='

This will return all the aliases that match the pattern l=... or la=....

4

They do not produce the same output in all directories.

Create a dotfile with touch .whatever, then issue both la and ls.

user4556274
  • 4,877
2

la is an alias for ls -A, as stated by other answers. As such, it can't be used in shell scripts, while ls can.

Your computer has multiple aliased commands. A complete list can be obtained by executing alias. On my machine it prints this:

alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'  
alias egrep='egrep --color=auto'  
alias fgrep='fgrep --color=auto'  
alias grep='grep --color=auto'  
alias l='ls -CF'  
alias la='ls -A'   
alias ll='ls -alF'   
alias ls='ls --color=auto'

--color=auto means colour will be turned off when not printing directly to STDOUT.

wjandrea
  • 14,236
  • 4
  • 48
  • 98