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

Taking care of your Linux box.

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

Postby mashkoor.qadir » Tue May 27, 2014 10:59 am

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
mashkoor.qadir
Lance Naik
 
Posts: 32
Joined: Mon Dec 20, 2010 10:27 pm
Yahoo Messenger: mashkoor.qadir@yahoo.com
Location: Karachi

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

Postby khawar2 » Thu Apr 16, 2015 2:19 pm

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
khawar2
Cadet
 
Posts: 1
Joined: Wed Nov 11, 2009 9:43 am

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

Postby mashkoor.qadir » Wed Oct 14, 2015 3:25 pm

Thanks Khawar,

It's very informative for me.
mashkoor.qadir
Lance Naik
 
Posts: 32
Joined: Mon Dec 20, 2010 10:27 pm
Yahoo Messenger: mashkoor.qadir@yahoo.com
Location: Karachi


Return to “%s” Administration

Who is online

Users browsing this forum: No registered users and 2 guests

cron