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

learn more… | top users | synonyms

4
votes
1answer
159 views

If I'm logged in as root, how do I restart mysql or apache with options?

I know the commands to restart/stop/start, but when I try to pass options it doesn't seem to work! CENTOS 6, MySQL 5.14 service mysql restart service httpd restart Then I tried this: ...
0
votes
1answer
45 views

What are the -i and -o options of wlconf for?

Version = 1.2 # defaults binary_name="/lib/firmware/ti-connectivity/wl18xx-conf.bin" wlconf_path="/usr/sbin/wlconf/" ini_path="/usr/sbin/wlconf/official_inis" {body of code} basically, the user ...
1
vote
4answers
63 views

Why is it find dir -name file and not find -n dir file?

I've searched around for this but I couldn't find anything on it. I've always wanted to know, why is it that most other built in bash commands have the format of command -flag arg1 arg2, i.e. cp -r ...
-3
votes
2answers
28 views

What does the -p option do in the read command?

What does the -p option do in the read command? An example: read -p "Please enter your first name: " firstName An explanation of the -p option on read's manual page (I don't understand this): ...
0
votes
1answer
34 views

Why do i need -d option on this cut command?

I have one txt file called sales.txt Fred apples 20 April 4 Susy oranges 5 April 7 Mark watermelons 12 April 10 Terry peaches 7 April 15 And when i use this command: [root@ip-10-0-7-125 ...
30
votes
6answers
9k views

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 ...
3
votes
2answers
8k views

List of available command options?

I'm currently setting up my first web server without a control panel and so far things are going pretty good! I was just wondering if anyone could direct me to somewhere that explains all of the ...
2
votes
1answer
47 views

Why is the xargs -i option deprecated?

I was reading the Linux man page for xargs recently, and it appears that the -i option is deprecated. To quote from the documentation: -i[replace-str], --replace[=replace-str] This ...
0
votes
2answers
42 views

Explanation of options(flags) for bash [closed]

I often see scripts with usage of options as in if [ -f some_file ] checks whether some_file is a file. I have a very vague understandings of flags, but can someone give me a good explanation? Others ...
1
vote
2answers
71 views

How to order several options of a command (ls)?

Why doesn't ls behave the same after exchanging the order of options -l and -f? $ ls -l -f 0821131236.jpg 0823130821.jpg $ ls -f -l total 33176 -rw-rw-r-- 1 t t 364186 Jan 6 16:06 ...
1
vote
2answers
27 views

Should the operands to a utility always appear after all the options to the utility?

POSIX says utility_name[-a][-b][-c option_argument] [-d|-e][-f[option_argument]][operand...] ... The arguments following the last options and option-arguments are named "operands". ...
0
votes
1answer
38 views

NFS server mount options vs. client mount options

On an NFS server, the shares are typically set up in /etc/export, where mount options like rw, root_squash, sync etc. can be set. When mounting the NFS share on the client side, again mount options ...
6
votes
2answers
9k views

syntax of ls --hide= and ls --ignore=

ls --hide and ls --ignore provides the possibility leave out files defined through regular expressions set after the --ignore= part. The latter makes sure that this option isn't turned off via -a, -A. ...
3
votes
2answers
123 views

The discrimination between short and long option is only `-`?

On Unix system, options begin with - is short option, while options begin with -- is long option. Is my understanding right?
3
votes
2answers
236 views

How does the -d option to bash read work?

I have a bash script where I'm trying to assign a heredoc string to a variable using read, and it only works if I use read with the -d '' option, i.e. read -d '' <variable> script block ...
-2
votes
1answer
64 views

What does the -p option do exactly with the cp command?

So I am trying to understand what is the significance of the -p option for the cp command. I opened the manual of the cp command and it says -p same as --preserve=mode,ownership,time stamps. But ...
3
votes
2answers
64 views

Set awk array on command line?

I know the -v switch can be used to awk on the command line to set the value for a variable. Is there any way to set values for awk associative array elements on the command line? Something like: ...
2
votes
3answers
87 views

What does the option -9 mean for killall?

I saw the command killall -9 but there is not such a option in the man page. So now I'm a bit confused: what does -9 option mean?
1
vote
1answer
65 views

Can a bash array be used in place of eval set — “$params”?

I'm taking a look at the optparse library for bash option parsing, specifically this bit in the generated code: params="" while [ $# -ne 0 ]; do param="$1" shift case "$param" in ...
1
vote
2answers
34 views

Listing negative numbers in zenity --list

$ zenity --list --column 'Numbers' '-3' This option is not available. Please see --help for all possible usages. $ zenity --list --column 'Numbers' -- '-3' So obviously zenity is interpreting the ...
38
votes
7answers
7k views

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, ...
5
votes
1answer
6k views

Provide two arguments to one option using getopts

In below code when I give option r then getopts requires one arguments: while getopts ":hr::l:" opt; do case $opt in r ) echo "Run Numbers - argument = $OPTARG " ;; l ) echo ...
5
votes
1answer
92 views

Why do some utilities parse operands before options?

According to several sources, the UNIX utility guidelines specify that operands should always be processed after options: utility_name[OPTIONS][operands...] Some older UNIX utilities are known to ...
0
votes
3answers
58 views

Understanding options to sort

part 1 ps -e | sort -k 1 -nr What is the interpretation of the above command? I want to understand the role of -nr. It is not clearly given the man pages of sort. part 2 When you open the man ...
3
votes
1answer
71 views

Is there a way for “less” to truncate lines and still exit after < 1 screen?

Like many (most), I use git, which by default sends its output (for diffs, logs, etc.) to less, with the options -FRSX. The options are overrideable in .gitconfig by setting the pager to be called ...
0
votes
1answer
56 views

Is a “--silent” flag supposed to suppress warnings and errors, or just warnings?

I'm designing a terminal-based application, and I want to implement a --silent flag to suppress noise if they don't want it. In this application, errors are most commonly logged when the application ...
19
votes
3answers
22k views

tar cvf or tar -cvf ?

I have learned to use tar without '-' for options, like tar cvfz dir.tar.gz Directory/ but I recently came accross the slightly different tar -czvf syntax (I think the 'f' must be the last option in ...
0
votes
2answers
378 views

Linux command to display the contents of a given file byte by byte with the character and its numerical representation displayed for each byte [closed]

I am looking for the Linux command and option combination to display the contents of a given file byte by byte with the character and its numerical representation. I was under the impression that in ...
42
votes
7answers
3k views

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 - ...
3
votes
2answers
41 views

Function with many arguments but only one switch

I am effectively making a recycling bin via some scripts I made. The first script is pretty much an alternative to the rm command (instead of actually deleting a file, it moves it to a deleted ...
6
votes
1answer
152 views

How can I delete a file named “--append”? [duplicate]

By mistake I have created a file named : --append. How do I delete it? Simply entering the usual command, rm -f --append, doesn't work.
17
votes
2answers
895 views

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 ...
21
votes
3answers
662 views

The precedence of command options?

I know that rm -f file1 will forcefully remove file1 without prompting me. I also know that rm -i file1 will first prompt me before removing file1 Now if you execute rm -if file1, this will also ...
1
vote
0answers
37 views

Using rsync with the verbose option and filtering the information displayed

I am using rsync with the -a -r and -v options to copy files and directories from one server to another. This all works fine. But when I make a change, for example, to a single file on the source ...
3
votes
2answers
386 views

diff --git unknown option

when I try to run diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c I get unknown option (I have installed git via apt-get install git)
2
votes
3answers
115 views

How to read this tcpdump man page?

I am trying to use the tcpdump command in a project and I have some difficulties understanding the help page. SYNOPSIS tcpdump [ -AbdDefhgHIJKlLnNoOpPqRStuUvxX ] [ -B buffer_size ] [ -c count ] ...
5
votes
2answers
4k views

Negative arguments to head / tail

Variants of this question have certainly been asked several times in different places, but I am trying to remove the last M lines from a file without luck. The second most voted answer in this ...
1
vote
1answer
102 views

Using apropos command with -a to search multiple keywords on CentOS 7

I'm running CentOS 7.0 build 1503. I'm trying to search for commands I don't know the name of by searching the man descriptions for multiple keywords using AND (e.g. search for a command containing ...
124
votes
8answers
44k views

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 ...
38
votes
2answers
69k views

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 ...
0
votes
1answer
99 views

What's the -alhF flag in ls?

What is the -alhF flag in ls? I can't find it in the man page.
6
votes
2answers
21k views

How can I detect that no options were passed with getopts?

I have this code - #getoptDemo.sh usage() { echo "usage: <command> options:<w|l|h>" } while getopts wlh: option do case $option in (w) name='1';; ...
7
votes
1answer
740 views

Why does `du -sh *` complain about invalid options?

I've searched my best through Google, but for the life of me I can't figure out what to use instead of * (asterisk) after a recent update (even Wikipedia seems to think du -sh * and du -sh * should ...
1
vote
2answers
590 views

How to extract unknown arguments within a shell script?

I have a shell script that accepts a variety of options, some with arguments, some without, some short, some long. It should handle some of these options itself and pass on the rest it does not know ...
16
votes
3answers
17k views

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 ...
2
votes
1answer
159 views

Order between options and operands?

When using a utility program, we may specify options (and their option arguments) and/or operands. In most cases (in the sense of conforming to some standard (POSIX?)) does the order between ...
1
vote
0answers
109 views

Why is rm -r the same as rm -R?

If you look in the rm man page you see that rm -r, rm -R, and rm --recursive are all the same. -r, -R, --recursive remove directories and their contents recursively When using options, I'm ...
1
vote
2answers
135 views

how to delete file that start with “-” [duplicate]

I try to delete this file on my solaris machine rm "-Insi" rm: illegal option -- I rm: illegal option -- n rm: illegal option -- s I also try this rm "\-Insi" -Insi: No such file or directory ...
4
votes
1answer
2k views

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. ...
18
votes
2answers
5k views

What is the difference between “du -sh *” and “du -sh ./*”?

The title says it all. What's the difference between those 2 commands? NOTE: I'm more interested in the * and ./* part.