LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-05-2021, 08:44 AM   #1
hnasr2001
Member
 
Registered: Nov 2012
Posts: 98

Rep: Reputation: Disabled
"-" before passing an argument


HI;

When do we need to use - followed by an argument in Linux command? Some of the Linux commands works with or without "-"

Example "tar -cf" or "tar cf".
 
Old 02-05-2021, 09:25 AM   #2
lvm_
Member
 
Registered: Jul 2020
Posts: 923

Rep: Reputation: 336Reputation: 336Reputation: 336Reputation: 336
There are three common command styles: traditional (no dash: c), unix (single dash: -c) and GNU (double dash and long name: --create) and tar supports all three, it is well documented on its man page, and that's where you should look to know which commands support which styles.
 
1 members found this post helpful.
Old 02-05-2021, 09:29 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Honestly I don't know, I think it has to do with how much the tool has been developed and improved. If you call that improvement.

Maybe also the option parsing tools changed and the tools which use them, or started to now use them, get this change as part of that library. I was never a very big user of the getopt stuff, but I know it's there and probably would use it if I was writing something more complex than I normally do.

I've always typed "tar -xvf" and I had a colleague who shouted that you don't need it if they saw someone doing it. He's correct, but my fingers are "trained" over like 30 years' time.

Maybe experiment? Or view the man pages? That is if you care too. Personally it doesn't fuss me that I use the dash. I suppose if it mandated that I not use the dash, then it would irk me a bit. I'd adapt.
 
1 members found this post helpful.
Old 02-05-2021, 11:27 AM   #4
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Quote:
Originally Posted by rtmistler View Post
I've always typed "tar -xvf" and I had a colleague who shouted that you don't need it if they saw someone doing it. He's correct, but my fingers are "trained" over like 30 years' time.

Maybe experiment? Or view the man pages? That is if you care too. Personally it doesn't fuss me that I use the dash. I suppose if it mandated that I not use the dash, then it would irk me a bit. I'd adapt.
That was an intolerant or uninformed colleague. Point him to the man pages as well, and let him know your way works too.

As has already been stated, use the man pages. Some (most) commands require the - but some don't and others use it differently. Once you get familiar with each command the usage becomes second nature.

I had a friend that I assisted in switching from windows to linux and he taught me the difference between "ps -aux" and "ps aux" since he read the man page and I, as a creature of habit, had been using it the same as I started many years before. Since then I more often refer to the man pages for usage info.
 
Old 02-06-2021, 01:08 AM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,789

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
The - was introduced to distinguish between an option and a filename. No filename starts with a - character. (Well, it could start with a - character, but don't do it!)

The tar program cannot be started without an option, so the developer let it simply pick all the letters from the first argument; a - is not required.
The leading - was added later, to make it compatible with the other programs.
So you can say
tar cf file.tar .
or
tar -cf file.tar .
or
tar -c -f file.tar .

The ps program does not take a filename, so on BSD-Unix the developer let it simply pick the letters from the first argument; a - is not required.
The leading - was added later for compatibility on BSD-Unix.
However, the SysV-Unix had different implementation of the ps program, with the - options.
There are conflicting option letters, for example the e option or the u option.
The GNU/Linux ps wants to be compatible with both BSD and SysV; the solution:
options without a leading - are interpreted the BSD way,
options with a leading - are interpreted the SysV way.
ps e
ps -e
ps u
ps -u user

So in Linux you must do
ps aux
ps -ef
otherwise it might interpret it the wrong way and even issue a warning.
 
1 members found this post helpful.
Old 02-10-2021, 07:13 AM   #6
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018
OpenGroup Base Spec. Utility Syntax Guidelines


Unfortunately, there's some inconsistency owing to historical baggage (mostly due to BSD vs SYSV differences dating back to the early days), and then there's additional conventions like: -word (X11 long-options) and --word (GNU long-options).

Some developers are a law unto themselves and may ignore all or part of these well established conventions, so you can never assume the correct way to specify options. I'm afraid it's all a bit of a mess at this point.

Last edited by GazL; 02-10-2021 at 07:15 AM.
 
  


Reply



Posting 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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] iptables bad argument Bad argument `5060' treschen Linux - Newbie 3 11-10-2012 09:29 AM
[SOLVED] shell scripting: value of argument dissapears depending on argument order akelder Programming 5 03-21-2011 11:27 PM
Help With Java Problem Please"""""""""""" suemcholan Linux - Newbie 1 04-02-2008 06:02 PM
message sending failed : Error[22 ] invalid argument .....but each and every argument rakeshranjanjha Linux - Software 2 01-07-2008 11:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration