change default command options
Solution 1:
One way would be by creating alias in your ~/.bashrc
file:
alias l1='ls -1'
then by typing l1
, ls -1
will be executed
Solution 2:
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.
Solution 3:
Just to clarify something to @RobDavenport answer. You can't use a function to override a command that has the same name.
e.g. to add a default param to the ls
command you can do :
alias ls='ls -1 $@'
This will add a new alias called ls
so it will be called instead of the original command. It will add the -1
option and forward every parameter $@
to the original ls
command.
You could also do
function ls_column () {
ls -1 $@
}
It would have the same effect but you must use a different name for your function. Otherwise it will call itself again and again.
Solution 4:
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.