Solved

Command Line Shortcuts

Posted on 2006-11-18
9
355 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now