why is the ls command an alias for itself with colors?

Discuss the security implications of the various flavors of linux and unix

why is the ls command an alias for itself with colors?

Post by ghostheadx2 on Thu Feb 18, 2016 1:38 am
([msg=91643]see why is the ls command an alias for itself with colors?[/msg])

I test which type is the ls command and it says

Code: Select all
ls is aliased to 'ls --color=auto'


This conveys why they are color coded as results when I list the contents of a directory why the results would be color coded. But why is it an alias for itself in color code. Like, why did the people who wrote the program want it to be color coded? What is the point? Is it just for organization, aesthetic, etc. reasons? Is it to help point out to the user that a content as certain important properties that need to be highlighted? Please elaborate.
ghostheadx2
Contributor
Contributor
 
Posts: 728
Joined: Wed Nov 19, 2014 1:19 am
Blog: View Blog (0)


Re: why is the ls command an alias for itself with colors?

Post by boriz666 on Thu Feb 18, 2016 3:35 am
([msg=91644]see Re: why is the ls command an alias for itself with colors?[/msg])

Greetings,
the "alias" command in linux/unix etc. is used like a kind of macro creator,
say you are tired of writing

ls -l --color=auto

For getting a detailed file listing with colors for the different file types.

Then you can alias it, so forexample you only have to write ls, like this:

alias ls='ls -l --color=auto'

Once the above command is issued, in your shell, whenever you write ls
it will translate to ls -l --color=auto.

For the alias to have effect, you normally write your aliases in the .bashrc
(if you use bash) in your home directory, so each time you start a new shell
the aliases are there for you. (and other things you might wan't).

The options in the ls command are many and the --color is one of them and
it is used to make it easy for the eyes to spot executable files, directories,
links and other distinct file types.

You also ask why its an alias for itslef, thats just cause the distro you use have
set up the alias: alias ls='ls --color=auto' in the standard configuration.
An alias is as i said a kind of macro and you can have an alias that has the same
name as most commands, but for security reasons you cant alias the alias command.

If you wanted to run the command on its own you'd have to write
/bin/ls

Then you are running the ls command directly.

You can see all the active alias'es on your current shell by issuing the command
alias
on its own.

For a list of which command line options the ls command takes you can issue the
command: man ls

Here you can see the wealth of options you have in displaying your files, thats one
of the things i love about linux, the versatility that is in most commands / programs.
boriz666
Experienced User
Experienced User
 
Posts: 99
Joined: Tue Mar 24, 2015 11:53 am
Blog: View Blog (0)



Return to *nix

Who is online

Users browsing this forum: No registered users and 0 guests