Hot answers tagged

85 votes

Do progress reports/logging information belong on stderr or stdout?

POSIX defines standard error as for writing diagnostic output This doesn't limit its use to error messages only. I would consider progress information as diagnostic output, so it belongs on ...
user avatar
66 votes
Accepted

gpg —list-keys command outputs uid [ unknown ] after importing private key onto a clean install

GNUPG has a trust database stored at ~/.gnupg/trustdb.gpg You can backup this trust database using the --export-ownertrust option: gpg --export-ownertrust > file.txt If you exported your secret ...
user avatar
  • 5,800
47 votes

Why is cp's option not to overwrite files called --no-clobber?

“Clobber” in the context of data manipulation means destroying data by overwriting it. In the context of files in a Unix environment, the word was used at least as far back as the early 1980s, ...
user avatar
43 votes
Accepted

Do progress reports/logging information belong on stderr or stdout?

Posix defines the standard streams thus: At program start-up, three streams shall be predefined and need not be opened explicitly: standard input (for reading conventional input), standard output (...
user avatar
41 votes
Accepted

Check ping statistics without stopping

From the ping manpage (emphasis mine): When the specified number of packets have been sent (and received) or if the program is terminated with a SIGINT, a brief summary is displayed. Shorter ...
user avatar
40 votes
Accepted

When and how was the double-dash (--) introduced as an end of options delimiter in Unix/Linux?

As far as I can tell, the use of -- as end-of-options-marker starts with sh and getopt in System III Unix (1980). According to this history of the Bourne Shell family, the Bourne Shell first appeared ...
user avatar
  • 1,196
40 votes
Accepted

How to run a command 1 out of N times in Bash

In ksh, Bash, Zsh, Yash or BusyBox sh: [ "$RANDOM" -lt 3277 ] && do_stuff The RANDOM special variable of the Korn, Bash, Yash, Z and BusyBox shells produces a pseudo-random decimal integer ...
user avatar
32 votes
Accepted

Since when do the POSIX and GNU rm not delete /?

You can find the HTML version of all the editions of POSIX 2008 online: original: http://pubs.opengroup.org/onlinepubs/9699919799.2008edition/utilities/rm.html TC1 (2013 edition) http://pubs....
user avatar
29 votes
Accepted

Why both `make clean` and `make mrproper` are used?

Cleaning is done on three levels, as described in a comment in the Linux kernel Makefile: ### # Cleaning is done on three levels. # make clean Delete most generated files # Leave ...
user avatar
  • 275k
28 votes
Accepted

What is the relationship between GNU and GNOME?

@rob is right. GNOME is technically an official GNU project. However, there is a lot of interesting history. Let's roll back the clock It's 1996. There are no desktop environments. Users and ...
user avatar
  • 14.1k
28 votes
Accepted

Subtract time using date and bash

That last example should have clarified things for you: timezones. $ TZ=UTC date -d "2019-01-19T05:00:00Z - 2 hours" +%Y-%m-%d_%H:%M:%S 2019-01-19_03:00:00 $ TZ=Asia/Colombo date -d "2019-01-19T05:00:...
user avatar
  • 4,486
28 votes

Why is cp's option not to overwrite files called --no-clobber?

Because this is actually a standard term. As explained in Wikipedia: In software engineering, clobbering a file or computer memory is overwriting its contents. The Jargon File defines clobbering ...
user avatar
  • 219k
26 votes

Drive name? What is the correct term for the "sda" part of "/dev/sda"?

sda is the device name. /dev/sda is the device path. Think of /sbin/fdisk, fdisk is the file name, while /sbin/fdisk is the file path.
user avatar
  • 1,388
25 votes

What are the differences between bsdtar and GNU tar?

BSDTAR vs TAR plus much more Here is one benefit!! I'm going to go into 5 topics here (and go way off topic, but it will cover what you want as well): bsdtar vs tar sparse files vs not thick and ...
user avatar
  • 351
25 votes
Accepted

Why didn't GNU Info succeed man?

To answer your question with at least a hint of factual background I propose to start by looking at the timeline of creation of man, info and other documentation systems. The first man page was ...
user avatar
  • 75.7k
25 votes

How to run a command 1 out of N times in Bash

Non-standard solution: [ $(date +%1N) == 1 ] && do_stuff Check if the last digit of the current time in nanoseconds is 1!
user avatar
23 votes

Check ping statistics without stopping

There is one more easy way to get the ping statistics durning it's execution: Just press Ctrl + | (vertical slash or it's also called pipe line) I do personally use it very often, try it: 64 bytes ...
user avatar
21 votes

Where does the word GNU come from?

GNU is a recursive acronym, GNU's Not UNIX It was chosen because: The name “GNU” was chosen because it met a few requirements; first, it was a recursive acronym for “GNU's Not Unix”, second, ...
user avatar
  • 14.3k
21 votes

How to run a command 1 out of N times in Bash

An alternative to using $RANDOM is the shuf command: [[ $(shuf -i 1-10 -n 1) == 1 ]] && do_stuff will do the job. Also useful for randomly selecting lines from a file, eg. for a music ...
user avatar
  • 1,955
21 votes
Accepted

Why does the `-` (minus) interpretation of GNU date differs from the intuitive one, when a date is specified?

In short: The date you give with --date is taken in local time, unless you specify a time zone, and something like +/- NNN is taken as one. Only anything after that, even if it's just hour is taken as ...
user avatar
  • 119k
20 votes
Accepted

`set -e` and `grep` idiom for preventing premature exit from shell script when pattern not found

You can put the grep in an if condition, or if you don't care about the exit status, add || true. Example: grep kills the shell $ bash $ set -e $ echo $$ 33913 $ grep foo /etc/motd $ echo $$ 9233 ...
user avatar
20 votes

Is it possible to change the kernel in a UNIX/Linux system?

No, each kernel implements its own features in its own way. There's a large amount of POSIX compatibility but once you get out of that the executables need to be compiled with the kernel mechanisms ...
user avatar
  • 16k
19 votes
Accepted

Any way to have a "verbose mode" or "debug mode" with sed?

As fra-san mentioned, GNU sed introduced a --debug option which does pretty much what you’re looking for, in version 4.6; so e.g if you run: printf '%s\n' one two | sed --debug 'H;1h;$x;$s/\n/_/g' ...
user avatar
19 votes
Accepted

Is it possible to save `bc` command line history?

If you aren't happy with the command line editing features that are built into a program, you can run it through rlwrap. This is a wrapper around a command line processor (a REPL) that lets you edit ...
user avatar
19 votes

ls -d command only returns `.` eg, and no child directories

When you provide the -d option, you're telling ls that you don't want it to list the contents of any directories, only the directory name itself. When you don't provide any additional arguments to ls,...
user avatar
  • 63.8k
19 votes
Accepted

Why should I care about POSIX if I'm writing bash scripts?

Perhaps you don't need to care if you know you're only going to use some particular shell that's not limited to just the POSIX features. But, there's still a chance you'll end up having to use ...
user avatar
  • 119k
18 votes
Accepted

Confusion about changing meaning of arguments and options, is there an official standard definition?

Adapted from the POSIX standard's "Utility Argument Syntax" section: utility_name [-a] [-b] [-c option_argument] [-d|-e] [-f[option_argument]] [operand...] The utility in the example is ...
user avatar
  • 275k
17 votes

Print contents of a file only after last occurrence of a token?

Reverse the file, display it until the first occurrence, and reverse the output again: tac logfile.log | sed '/STARTING SESSION/q' | tac tac is efficient when given a regular (seekable) file to ...
user avatar
16 votes
Accepted

Why does `find . -type f` take longer than `find .`?

GNU find has an optimization which can be applied to find . but not to find . -type f: if it knows that none of the remaining entries in a directory are directories, then it doesn't bother to ...
user avatar
16 votes

Is it possible to change the kernel in a UNIX/Linux system?

FreeBSD doesn't use a Linux kernel - as its name suggests, it uses a BSD kernel. It is possible to replace a Linux kernel with a different Linux kernel (either one you built yourself or one you ...
user avatar
  • 7,798

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