Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > chaning ls to ls -l

chaning ls to ls -l
Thread Tools
Forum Regular
Join Date: Jun 2003
Status: Offline
Reply With Quote
Sep 12, 2004, 01:52 AM
 
I want to change the ls command to ls -l. I know i have to use aliases, but I don't know exactly how to them.
     
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status: Offline
Reply With Quote
Sep 12, 2004, 06:54 AM
 
Originally posted by iStudent 2003:
I want to change the ls command to ls -l. I know i have to use aliases, but I don't know exactly how to them.
It is very common to use 'll' as an alias for 'ls -l'... in fact it is the default on many Unix systems.

First find out which shell you are using because the syntax is slightly different for bash than tcsh. tcsh was the default shell for 10.2 and earlier and bash for 10.3 and later. Type:

echo $SHELL

If you are using the bash shell (10.3 and later) just type:

alias ll='ls -l'

From now on, in that particular terminal window, whenever you type ll at the command prompt it will be translated to ls -l. To remove the alias just type:

unalias ll

To make it permanent so it will work in any shell as that user just add the alias line to your ~/.bashrc file. Whenever you log in the .bashrc file is parsed and the alias will be automatically set. You can have as many aliases as you like in .bashrc, one alias per line. If you want to make it global (the same for all users of the system) just add the alias line to /etc/bashrc. At any time you may type the command alias with no arguments to see the current list of aliases that you have set.

If you are using the tcsh shell (10.2 and earlier) just type:

alias ll ls -l

and it will behave just like the one in bash. To remove it type:

unalias ll

as before.

To make it permanent add it to your ~/.cshrc file. To make it global add it to the /etc/csh.cshrc file. It is really pretty simple.

Some other common aliases are (in bash format):

alias cp='cp -i'
alias l.='ls -d .[a-zA-Z]*'
alias mv='mv -i'
alias rm='rm -i'

Usually it is not a good idea to alias a standard command such as ls to something with different behaviour. Such as:

alias ls='ls -l'

This is because it can have unexpected side effects when strung (piped) together with other commands. It is better to give the alias a different name. In the above example, for instance, there is an alias for rm that remaps rm to rm -i. This is not necessarily a bad idea because it puts the rm command into "interactive mode" and the command will prompt you for each file that you want to delete. If you type something like:

rm *

You will be asked for each and every file:

rm: remove `filename'?

to which you can answer y or n. To escape this behaviour one time just type:

\rm *

and the aliased rm will behave as usual. As always, to escape a command altogether just type Ctrl-c.

I have heard it said that if one has to use a complex command more often than once in a row that it should be aliased.

Another VERY useful feature of the bash shell (I don't know if there is an equivalent in tcsh) is recursive command history editing. Type at the prompt:

Ctrl-r

and then start typing the first few characters of some long or complex command that you typed earlier in your session. The prompt will then start to recursively traverse your command history automatically completing the command for you as you type. You can also edit the line.

Have fun!
-DU-...etc...
     
Forum Regular
Join Date: Jun 2003
Status: Offline
Reply With Quote
Sep 13, 2004, 01:47 AM
 
Yep, that worked!!! Thanks!!!
     
Mac Elite
Join Date: Oct 2000
Location: Seattle
Status: Offline
Reply With Quote
Sep 14, 2004, 02:36 AM
 
I set mine up as

alias ll "ls -Flh "

the h gives you the file sizes in human readable form, 4.2MB and 1.2GB instead of just the bytes (which I find pretty useless) . The F puts a / at the end of directories, makes it easier to tell the difference.

Speaking of aliasing complex commands here is a trick I use to make the command line history easily searchable.

alias hist "cat ~/.history | grep"
set histdup='prev'
set savehist = 1000
set savehist = ( 100 merge )


add these lines to your .tcshrc file. The first line sets 'hist' to be a grep search of the history file, the next three tell the history to not add repeats, save the last 1000 commands, and keep the history after you log out.

now if you can't remember the command you used last week for flushing the DNS cache, just type for example:

% hist cache

you'd get something like this:

lookupd -flushcache
sudo lookupd -flushcache
sudo lookupd -flushcache


What the terminal really needs is a bookmarks drawer.
(Last edited by Gavin; Sep 14, 2004 at 02:46 AM. )
     
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status: Offline
Reply With Quote
Sep 14, 2004, 11:22 AM
 
Originally posted by Gavin:

What the terminal really needs is a bookmarks drawer.
Isn't that what aliases are for?
-DU-...etc...
     
Mac Elite
Join Date: Oct 2000
Location: Seattle
Status: Offline
Reply With Quote
Sep 15, 2004, 01:06 AM
 
Aliases are fine for shortening a few things you type all the time. They aren't right for every time saving situation, like they are not very useful for storing multiple variations on the params you send in. And you still have to memorize your aliases which is very geeky.

I need a way to replace my files of notes and snippets which document commands I rarely use. Bookmarks would give me a quick way to find that thing I did a year ago and can't quite remember what is was.

Every time you do something useful you add it to the list with a description. drop it into your hierarchy.

-filesystem stuff
ls -l , list this folder
find ....blah | .. , show all the jpegs in this folder and all it's subfolders
find ....blah | grep..2... , show all the jpegs in this folder but not it's subfolders

-services
apachectl graceful , restart apache
service proftpd stop, kill the ftp server on my linux box

-installation
./configure --some_param bob etc. , the long config command for my software package


Something like that. Just double click it in the list and it drops it into the terminal. You could also take any these and make it into a button in a button bar for things you do all the time. Way faster than typing which is the idea behind aliases anyway.

Besides, aliases are a pain in the butt to set up compared to a web browser's book marks.
(Last edited by Gavin; Sep 15, 2004 at 01:30 AM. )
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:48 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2