Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Command Line Shortcuts

Posted on 2006-11-18
9
Medium Priority
?
362 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
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…
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.
Suggested Courses

670 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