Solved

Command Line Shortcuts

Posted on 2006-11-18
9
358 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
  • 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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 …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

830 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