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.

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.

  • 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'
  • That would be Ubuntu's (without the code formatting). – Peter Mortensen Dec 24 '16 at 15:17
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=....

  • 1
    Or just alias l la – Kevin Dec 22 '16 at 16:11
4

They do not produce the same output in all directories.

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.