Questions tagged [options]

Passing options like -l or --word to commands, or parsing them in scripts.

Use this tag for questions about options for shell commands: passing them and parsing them.

There are three common variants of option syntax; different commands use different syntax.

  • POSIX: This is the traditional Unix style. Options consists of a - (dash a.k.a. minus) followed by a single letter. If - is followed by multiple letters, each letter is an option (this is called bundling). Example: ls -la is equivalent to ls -l -a.
    An option can take an argument, which is either in the next word or glued to the option. Example: sort -st: is equivalent to sort -s -t :.
  • GNU: in addition to the POSIX syntax, options can start with -- and consist of multiple letters. Arguments are either given after a = or in the next word. Example: sort --stable --field-separator=: is equivalent to sort --stable --field-separator :.
  • Multi-letter: an option consists of a - followed by more characters (usually letters and dashes). If there is an argument, it is in the next word. Example: xterm -name foo -e foo

Further reading

336 questions
483
votes
10 answers

How do I delete a file whose name begins with "-" (hyphen a.k.a. dash or minus)?

How do you remove a file whose filename begins with a dash (hyphen or minus) -? I'm ssh'd into a remote OSX server and I have this file in my directory: tohru:~ $ ls -l total 8 -rw-r--r-- 1 me staff 1352 Aug 18 14:33 --help ... How in the…
Astra
  • 4,933
  • 2
  • 16
  • 6
168
votes
4 answers

How can I execute local script on remote machine and include arguments?

I have written a script that runs fine when executed locally: ./sysMole -time Aug 18 18 The arguments "-time", "Aug", "18", and "18" are successfully passed on to the script. Now, this script is designed to be executed on a remote machine but, from…
AllenD
  • 2,397
  • 4
  • 17
  • 14
69
votes
5 answers

getopt, getopts or manual parsing - what to use when I want to support both short and long options?

Currently I'm writing a Bash script which has the following requirements: it should run on a wide variety of Unix/Linux platforms it should support both short and (GNU) long options I know that getopts would be the preferred way in terms of…
helpermethod
  • 1,952
  • 2
  • 19
  • 25
65
votes
2 answers

cp -L vs. cp -H

Problem When copying files with cp -H or cp -L, I get the same results: $ ls -l fileA fileA -> fileB $ cp fileA somewhere/ -H $ ls -l somewhere/ fileA # fileA is a copy of fileB, only renamed, with same properties! This answer here…
erch
  • 4,890
  • 17
  • 49
  • 81
62
votes
4 answers

Where is the `--` (double dash) argument documented?

There are some utilities that accept a -- (double dash) as the signal for "end of options", required when a file name starts with a dash: $ echo "Hello World!" >-file $ cat -- -file Hello World! $ cat -file # cat - -file fails…
user232326
59
votes
1 answer

What is the actual purpose of GNU grep's -X option and why is it undocumented?

By reading this question, I have discovered that GNU grep has a -X option which expects an argument. Strangely, it is mentioned neither in the man page nor in the info page. Looking at the source code, there is that comment right in the middle of…
xhienne
  • 17,075
  • 2
  • 52
  • 68
54
votes
6 answers

Single dashes `-` for single-character options, but double dashes `--` for words?

Where did the convention of using single dashes for letters and doubles dashes for words come from and why is continued to be used? For example if I type in ls --help, you see: -a, --all do not ignore entries starting with . -A,…
Larry
  • 551
  • 1
  • 4
  • 4
53
votes
4 answers

tree command for multiple includes and excludes

Could you please give me an example of using the tree command to filter out result as follows: to ignore directories (say bin, unitTest) only listing certain files having extensions (say .cpp, .c, .hpp, .h) providing full path-names of only the…
Linda
  • 531
  • 1
  • 4
  • 4
52
votes
7 answers

why does ls -d also list files, and where is it documented?

when specifying ls --directory a* it should list only directories starting with a* BUT it lists files AND directories starting with a Questions: where might I find some documentation on this, other than man and info where I think I thoroughly…
erch
  • 4,890
  • 17
  • 49
  • 81
47
votes
5 answers

Is there a 'rc' configuration file for grep/egrep? (~/.egreprc?)

I usually use grep when developing, and there are some extensions that I always want to exclude (like *.pyc). Is it possible to create a ~/.egreprc or something like that, and add filtering to exclude pyc files from all results? Is this possible, or…
45
votes
7 answers

Is `-` used only with cd?

cd - can switch between current dir and previous dir. It seems that I have seen - used as arguments to other commands before, though I don't remember if - means the same as with cd. I found that - doesn't work with ls. Is - used only with cd?
Tim
  • 98,580
  • 191
  • 570
  • 977
43
votes
2 answers

What's the difference between a flag, an option, and an argument?

ls -a (I consider -a an option) sudo -u username (-u = option, username = arg) chmod 664 my-dir (664 = option, my-dir = arg) I can't think of an example that might say "this is a flag" except perhaps when looking at dir listing: -r--------. 1…
user172130
34
votes
1 answer

Do you need to specify the "defaults" option in fstab?

The Arch Wiki on fstab specifies the options of / to be defaults,noatime, but on my installation the default fstab is created with the options of rw,relatime. The Arch Wiki covers the atime issues. What I am curious about is the defaults option. The…
StrongBad
  • 5,151
  • 9
  • 47
  • 73
32
votes
8 answers

Is there way to see `man` document only for specified option of a command

If I want to know the meaning of wget -b, I see the manual by man wget, then search the -b option. -b --background Go to background immediately after startup. If no output file is specified via the -o, output is redirected to…
ironsand
  • 5,085
  • 12
  • 50
  • 73
32
votes
2 answers

Security implications of running perl -ne '...' *

Apparently, running: perl -n -e 'some perl code' * Or find . ... -exec perl -n -e '...' {} + (same with -p instead of -n) Or perl -e 'some code using <>' * often found in one-liners posted on this site, has security implications. What's the deal?…
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
1
2 3
22 23