Solved

Command Line Shortcuts

Posted on 2006-11-18
9
361 Views
Last Modified: 2011-04-14
Greetings:

How would I create command line shortcuts in Linux.  For example I would be in a shell at the command line and to view my directories and files in /home/user(user being me) I would type in ls -al which would list all files in alphabetical order.  Now what I would like to do is type in l(lower case L) and receive the same output as ls -al.

MikeP
0
Comment
Question by:palazzini
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 15

Expert Comment

by:periwinkle
ID: 17973160
you could do this via an alias, but I would urge you to be careful to not overwrite important commands, or to set things up in a way that you forget the underlying command.  To set this alias, you'd do the following (via a login script or from the command line):

alias l 'ls -al'
0
 
LVL 12

Expert Comment

by:ibu1
ID: 17973738
Do this exactly
vi /usr/bin l
ls -al


save file
chmod 777 l

Now when u type l it will work as ls -al
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17973873
Agree with periwinkle. To make it permanent save the alias command to $HOME/.bashrc file. I assume You are using bash as Your shell... Also remember that aliases are not recursive, so following is wrong
alias ll='ls -la'
alias lf='ll -F' # will not work, ll is unknown here
0
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 
LVL 48

Expert Comment

by:Tintin
ID: 17973894
ibu1

I assume you meant to write

vi /usr/bin/l

That's not a good idea, as you should not pollute /usr/bin with your own scripts.  Also doing a chmod 777 is a bad idea as it means anyone can delete,edit the file.

aliases or functions are the way to go.
0
 
LVL 2

Author Comment

by:palazzini
ID: 17975042
Thanks for the quick response everyone.  I am talking about the bash shell.  I'm using Ubuntu 6.06.  What I'm looking for are step by step instructions to do this request.   For example to create the aliases script or function do this:

Step 1-Start at the command line here.
Step 2-Open text editor(vi, pico) and type the following.  
Step 3-Save to this path.
Step 4-etc, etc, etc,
 
This way I will create the command line short-cut without making any mistakes.  The idea is if I can create this command line short cut there are alot more I would like to do.  I just need to be instructed on how to correctly create the commands.
Once again thanks for being there.  This is my favorite site for getting IT help.

MikeP
0
 
LVL 15

Accepted Solution

by:
periwinkle earned 500 total points
ID: 17975106
open a shell at the console or via ssh.
vi .bashrc
use 'i' to insert and type the following line:
alias l 'ls -al'
press the esc key to get out of insert mode
type the following to write and quit:
wq
exit your command shell, and restart it to see the change when you log in again.
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17975110
Yes, start the command line terminal
 echo "alias l='ls -la'" >> $HOME/.bashrc
every newly opened shell should have the alias set
Alternative: if You can handle editing files, open .bashrc (in Your home directory) and add following line
alias l='ls -la'
0
 
LVL 2

Author Comment

by:palazzini
ID: 17975256
That's what I needed.  Thanks everyone for the input.
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 17976627
glad to have helped - ravenpl's solution to add the line via echo and redirection is simple and elegant, too...
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question