Hot answers tagged

46

TL;DR This forces the destination to be a directory that already exists or the command to fail without effect and is used as a fail-safe. The meaning of . Every directory in typical Unix/Unix-like filesystems include two special directories: one referencing the directory where it is: . and one referencing the parent directory of where it is: .. (allowing to ...


16

What exactly am I missing here? The script.sh command is hashed. If you run hash -r, then command -p script.sh will fail as expected. But if you run it directly, it will be hashed again. This really looks like a bug in bash -- it does not happen in other shells.


6

$ awk '(FNR-1)%4 == 0 { getline add <"add.txt"; print add }; 1' data.txt 2001-01-01 00:00:00 42 1 -500 11.822788 -400 12.006394 -350 12.287062 -300 12.793395 2001-01-02 00:00:00 42 1 -500 11.823597 -400 12.008012 -350 12.287062 -300 12.794204 2001-01-03 00:00:00 42 1 -500 11.826023 ...


5

Anything that can reasonably called Unix or Unix-like has POSIX utilities. You can generally assume that the utilities are present, that they support the listed options, and that they behave as indicated. There are a few limitations: Features that are marked as optional may not be present everywhere. Recently added features may not be present everywhere yet....


2

Debian doesn’t aim for strict POSIX conformance in general. Some of the tools mandated by POSIX are, in practice, not that commonly used, and therefore they aren’t included in the “standard” Debian installation. For most of these tools this situation has evolved over time, so one can find traces of their demotion; see this bug requesting ed’s for example. ...


2

If GNU sed is an option, especially for those on MacOS, we can run the following sed code. The R command and the ~ command, which are gnu additions are the key here. The ~ will make sed look at every fourth line specially, for others it will pass through to stdout. The R shall take one line from add.txt and mix it with the data.txt line. $ sed ' 1~4!b ...


2

In bash, to prevent a command from being added to history, put a space before the command. This is assumes that you have, as is common, the ignorespace option set in HISTCONTROL. If you don't, run the following command (or add it to ~/.bashrc to make it permanent): export HISTCONTROL=ignorespace Many people also want to ignore duplicate commands, in which ...


1

Use grep, e.g. grep "cpu MHz" /proc/cpuinfo to select the line. Use sed to extract some text from the line, e.g. remove everything up to the colon. Combine them with a pipe (|) to do both. grep "cpu MHz" /proc/cpuinfo | sed -e "s/^.*: //"


1

IMHO the simplest approach is just to read add.txt into an array and then print a line from the array every 4 lines of data.txt: $ awk 'NR==FNR{a[NR]=$0; next} FNR%4==1{print a[++c]} 1' add.txt data.txt 2001-01-01 00:00:00 42 1 -500 11.822788 -400 12.006394 -350 12.287062 -300 12.793395 2001-01-02 00:00:00 42 1 -500 11....


1

lsblk will give you MAJ:MIN numbers To calculate the equivalent for ras-mc-ctl, do: d = (MAJ * 256) + MIN To go from ras-mc-ctl to lsblk, do: MAJ=int(d/256) MIN=d % 256 For your case: MAJ=(2064/256)=8 MIN=(2064%256)=16


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