Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

When I enter command

ls

I see a list of files and directories in current directory, the list displayed is quite annoying.

Rather, I like to execute ls command with -1 option like

ls -1

My question is how to change default behavior of ls command such that it will always execute with -1 option. i.e how to display files and directories in one column with ls command.

Thanks.

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

One way would be by creating alias in your ~/.bashrc file:

alias l1='ls -1'

then by typing l1, ls -1 will be executed

share|improve this answer
add comment

zetah's answer is the best. To elaborate:

Aliases are best used for short, simple, often used modifications of command default parameters. They are stored in memory (after being read from their source file), for better performance or repetitive use.

Functions are appropriate for more complex activity that are often used, and are also stored in memory.

Scripts are appropriate for the most complex and least often used commands.

See this question and answers on unix stackexchange - explains the difference in best use between aliases, functions, and scripts.

share|improve this answer
add comment

In your Home directory, open .bashrc file in editor and add alias ls='ls -1'.

First open the terminal ( Press ControlAltT), enter gedit ./.bashrc to open your .bashrc file in the editor.

Find the section that has some aliases for ls. In mine (stock 11.10) it looks like:

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

Add the following line after the ls aliases:

alias ls='ls -1'

Save the file, exit gedit and the terminal and reboot. Now the ls command should execute ls -1 by default.

share|improve this answer
    
This redefines "ls" to now operate as "ls -1" by default for this user. If you'd rather use a new command, then @zetah answer covers that. –  James Feb 13 '12 at 4:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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