Solved

Command Line Shortcuts

Posted on 2006-11-18
9
360 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
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.:
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.

734 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