Tag Info

Hot answers tagged

59

The a* and *a* syntax is implemented by the shell, not by the ls command. When you type ls a* at your shell prompt, the shell expands a* to a list of all files in the current directory whose names start with a. For example, it might expand a* to the sequence a1 a2 a3, and pass those as arguments to ls. The ls command itself never sees the * character; it ...


22

In The Art of Unix Programming Eric Steven Raymond describes how this practice evolved: In the original Unix tradition, command-line options are single letters preceded by a single hyphen... The original Unix style evolved on slow ASR-33 teletypes that made terseness a virtue; thus the single-letter options. Holding down the shift key required actual ...


20

In general, most utilities have options that begin with -. Most of those utilities have a feature that allows you to specify an argument that is not an option by supplying the special option --. For those utilities, -- means that no further arguments are options. So in your case, you can use touch -- -stuff. For more information about general conventions ...


20

See Keith Thompson’s answer; but to explain why ls --directory a* shows files and directories: The --directory option does not suppress non-directory files. Instead, it lists the directories as such, while it would otherwise list their content. Example: $ mkdir foo $ touch foo/bar $ ls foo bar $ ls --directory foo foo


19

There's no rc file for grep, but you can set the environment variable GREP_OPTIONS to a whitespace-separated list of options that will apply to all grep commands. This requires GNU grep (the implementation on non-embedded Linux, Cygwin and some other systems) 2.4; the --exclude option is new to GNU grep 2.5. Put something like this in your ~/.profile: ...


17

tar is one of those ancient commands from the days when option syntax hadn't been standardized. Because all useful invocations of tar require specifying an operation before providing any file name, most tar implementations interpret their first argument as an option even if it doesn't begin with a -. Most current implementations accept a -; the only ...


15

Also touch ./-stuff What happens here: for "usual" filenames the current directory (./) is implied and thus unnecessary. However, we can explicitly specify it with ./ (it's just redundant in normal cases); this way, the argument won't start with - and won't be parsed as an option, but as a filename.


14

I assume you're using bash or similar. An example: all=false long=false while getopts ":hal" option; do case $option in h) echo "usage: $0 [-h] [-a] [-l] file ..."; exit ;; a) all=true ;; l) long=true ;; ?) echo "error: option -$OPTARG is not implemented"; exit ;; esac done # remove the options from the positional parameters shift $(( ...


13

The -- is working for tools which use getopt(3) to process command line arguments and many API that parse POSIX style options. From the manual page of getopt(3): The interpretation of options in the argument list may be cancelled by the option `--' (double dash) which causes getopt() to signal the end of argument processing and return -1. I would ...


10

I may be a dinosaur, but I think that habitually using "cvf" instead of "-cvf" is probably more portable. I imagine most Linux distros use GNU tar, and I would guess that the *BSDs do also, but you'll find proprietary Unixes that still use the old SysV tar, which used to require you to not use a '-' in the options. I do not use "-cvf" (or "-xf" or ...


10

The answers of Vegar Nilsen and edfuh are very good and the proper solutions to a problem like this. I do want to add a general response to this question that allows you to delete any file with a difficult file name. First its inode number is obtained using ls -i or some form of stat and then the file is removed by searching for files in the current ...


10

There is a technique called residual information retrieval that can read data that was deleted based on the idea that when the drive is magnetized in order to store data other parts that are close to the data is also affected by this and it should be possible to re-read data this way ... this is though a costly technique, but use it if you are paranoid ;) ...


10

This is entirely up to you but most programs do someting like this program --help Usage: program [<options>][<arguments> ...] Options: --help show this message, then exit --something after some spaces for alignment, an explenation follows. You should check out getopt which most programs (this is also available in programming ...


9

-O3 has several disadvantages: First of all it often produces slower code than -O2 or -Os. Sometimes it produces longer code due to loop unrolling which may be in fact slower due to worse cache performance of code. As it was said it sometimes produces wrong code. It may be either due to error in optimalization or error in code (like ignoring strict ...


9

As I can see you don't need to remove your dir , only files inside. So you can recreate it rm -r /path/to/dir && mkdir /path/to/dir or even delete only files inside find /path/to/dir -type f -delete afair first one works faster.


7

You need to pass a top directory name. Some versions of find assume the current directory if you omit it, but not AIX's. Also, -L isn't what you want here: it tells find to follow symbolic links, but that's not what you're asking, you're asking to find symbolic links. find / -type l -print will print out all the symbolic links. See man find


7

This option is largely useless. Overwriting with multiple patterns is a bit of paranoia that isn't justified by real-world tests: on modern hard disks, overwriting once or multiple times, with zeroes or ones or random patterns, doesn't make any difference. The case is less clear for SSD, but these have their own issues; overwriting multiple times wears out ...


6

One reason for continuing to use the single letter options is because they can be strung together: ls -ltr is a lot easier to type than ls --sort=time --reverse --format=long. There are a number of times when both are good to use. As for searching for this topic, try "unix command line options convention".


6

Use getopts. It is fairly portable as it is in the POSIX spec. Unfortunately it doesn't support long options. There is an interesting approach that does some preprocessing on the argument list to translate long options into short ones that getopts recognizes. See also this getopts tutorial courtesy of the bash-hackers wiki and this question from ...


6

Because -a and -b start with - the command thinks they are options. To prevent that stick a -- before the list of filenames like this: convmv -f ENCODING -t utf8 --notest -- * That way everything after -- will be treated as regular arguments without trying to process them as options. This is common in a lot of unix commands.


5

It's included by (obscure) reference. SEE ALSO X(7), echo(1), cat(1) And buried down a ways in X(7): OPTIONS Most X programs attempt to use the same names for command line options and arguments. All applications written with the X Toolkit Intrinsics automatically accept the following options: -display display This option ...


5

It is typical for programs to force the "some_string" part to be the last argument so that .abc.ksh "some_string" -a "sample text" is an error. If you do this, then after parsing the options, $OPTIND holds the index to the last argument (the "some_string" part). If that is not acceptable, then you can check at the beginning (before you enter the while to ...


5

Maybe there is a hack that would allow to change the job's output file descriptor to /dev/null, but I don't know it. In any case, the program would still be writting all those lines, they would just be discarded. This would therefore only help if the terminal display is the bottleneck, not the message generation.


5

This feature makes reading the output of grep easier. If you want to check data that grep cannot read directly then you may end up using a pipe to feed grep instead of creating a temporary file which grep can read. If you don't want a temporary file (e.g. because it would be huge) then without --label you would have the problem that grep cannot print the ...


4

ack can do what you want and more. It will ignore binary files by default and you can tell it to ignore other filetypes as you want --notext, --nohtml, etc. It has the ability to define an rc file too so you can customize it with your own types.


4

Note that large chunks of the toolchain (glibc in particular) flat out don't compile if you change optimization levels. The build system is setup to ignore your -O preferences for these sections on most sane distros. Simply put, certain fundamental library and OS features depend on the code actually doing what it says, not what would be faster in many ...


4

Use find to do it: find -name '--help' -delete And this is a good method because if you have more then a few files like this that you can delete you can get a preview list of the files by simply running find without the -delete option first, and then if the list of files look good just run it again with -delete. In fact, you avoiding rm in favor of find ...


4

This isn't a bash question per se -- everything in that command is a set of arguments to the unix find(1) command, which would behave the same regardless of what shell you invoke it from. Given this, what you really need to do is look at the documentation for find(1) -- and you can do that by running: $ man find or, if your version of find is the Gnu one ...


4

In this context, the -name is telling the find command to filter results to those that end with '.html' and the -exec is telling the find command to run grep with the results. The -l applies to the grep command and indicates that the file name of the first input file to match the pattern (i.e. somethingtobefound) should be printed and scanning halted. As ...


4

To change options permanently and in the sanctioned manner, edit the files in /etc/sysconfig that have the same name as the service. For example, consider httpd. On one system I have, there are several things you can set: # Processing model HTTPD=/usr/sbin/httpd.worker # Additional options OPTIONS= # Set locale HTTPD_LANG=C (The actual file is much ...



Only top voted, non community-wiki answers of a minimum length are eligible