What is the purpose of "-" before giving any switch

Taking care of your Linux box.
Post Reply
mashkoor.qadir
Lance Naik
Posts: 32
Joined: Mon Dec 20, 2010 10:27 pm
Location: Karachi
Contact:

What is the purpose of "-" before giving any switch

Post by mashkoor.qadir »

What is the purpose of putting "-" after any command? and before any switch and with some command it doesn't used. Example:

ls -al
ps aux
ps -ef
Kind Regards,
Mashkoor Qadir,
mashkoor.qadir@yahoo.com
http://www.redmath.com
khawar2
Cadet
Posts: 3
Joined: Wed Nov 11, 2009 9:43 am

Re: What is the purpose of "-" before giving any switch

Post by khawar2 »

It was developed in unix to define an option versus a parameter.

For example ls data
means list the contents of the directory data

In the 1970s the parameter were to be given separately

Example ls -l data

means -l is not a directory name but an option for the command ls

It means long listing for directory data

To give two options you needed to say ls -l -a data

This was shortened to ls -la data to avoid having to write more. I think the Linux people did it or the Unix people.

The linux people got confused because they had a lot of options for their "enhanced" unix commands.

So they wanted to use words.

So ls -long meant ls -l -o -n -g

So they created double dash in linux.

ls --long means ls -l

Now for commands like ps -a -x

They can be written as
ps ax

Now how are we going to know is ax is an option or a parameter because it does not have the dash

Well this is done only for commands which take options but no parameters.

So commands like ps only have options (switches) and no parameters after them.

This is not done for commands like ls -la

ls la shall mean ls of the directory la and never -l -a

I hope this helps.

Regards,

Khawar Nehal
khawar@atrc.net.pk
mashkoor.qadir
Lance Naik
Posts: 32
Joined: Mon Dec 20, 2010 10:27 pm
Location: Karachi
Contact:

Re: What is the purpose of "-" before giving any switch

Post by mashkoor.qadir »

Thanks Khawar,

It's very informative for me.
Kind Regards,
Mashkoor Qadir,
mashkoor.qadir@yahoo.com
http://www.redmath.com
Post Reply