New answers tagged

0

man bash first has: Redirecting Standard Output and Standard Error &>word >&word Of the two forms, the first is preferred. This is semantically equivalent to >word 2>&1 Now what can 2>&1 mean when you have e.g. cmd >out 2>&1? This is further down: Duplicating File Descriptors The ...


0

While I agree with the other answers that & is just a part of >&. And think that there way of looking at it may be better than mine. I have another way to look at it. example for > When we have >word. If the word does not start with a & then it is a file name. If it does then it is a number of an existing file-handle, or a -.


0

As mosvy commented The ampersand in >& does not have a functional role. Its role is more like the role of the letter c in cat. The notations >&, <& etc have the roles explained in the man page for bash. You could regard the & as indicating that the redirection involves merging two IO streams. But it is more of part of a mnemonic ...


0

This should work in any standard shell, not just bash: { cmd 2>&1 >&3 | sed 's/^/err: /' >&2; } 3>&1 | sed 's/^/out: /' This could be made into a function, for convenience: # usage louterr cmd [args ...] louterr(){ { "$@" 2>&1 >&3 | sed 's/^/err: /' >&2; } 3>&1 | sed 's/^/out: /'; } cmd(){ echo ERR &...


1

Follow up question answers itself when executed: The err function prints to stdout as well. Obviously the first form has the original stdout, while the second already uses the "redirected to out() function" one.


2

Use Process Substitution not pipes: { echo "foo" ; echo "bar" >&2; } 2> >(sed "s/^/err: /") > >(sed "s/^/out: /") err: bar out: foo If you're doing this in a script, use the exec command to set up the redirection for the whole duration of the script: bash -c ' exec 2> >(sed "s/^/err: /") > >(sed "s/^/out: /") echo ...


1

Adding Jim comment as an answer here for more visibility. use nohup program > program.out & to write the output to program.out instead of nohup.out


-1

A zip archive is not sequential (since it can have the table of contents at the end of the file) so it is difficult to stream-unzip it. Try to see if you can get another file format, like .tar.gz. If you're downloading a .zip file from GitHub, there is almost always a .tar.gz version available. For example, https://github.com/madler/zlib/archive/v1.2.11....


7

echo 123456789 > out.txt writes the string 123456789 in out.txt file. The exec 3<>out.txt construct opens the file out.txt for reading < and writing > and attaches it to file descriptor #3. read -n 4 <&3 reads 4 characters. echo -n 5 >&3 writes 5 (replacing 5 by 5). exec 3>&- closes file descriptor #3. Resulting in ...


0

The definite answer is line buffering. You can demonstrate this with ping -c 3 instead of just ping, where all output is produced only at the completion of the first command. As a workaround with GNU grep you can reduce your two filters to one ping 192.168.0.1 | grep -oP '[[:digit:].]+(?= ms)' Or if you really want to use two filters, either grep --line-...


0

I think your problem is caused by the line buffering of your shell. If you let your command run long enough, you should see some output. Or just limit the amount of pings like this: $ ping -c4 192.168.0.1 | grep -o '[^ =]* ms' | grep -o '^[^ ]*' There is some more information and workarounds (solutions?) if you follow this link


4

To clarify, OP commented that the account USER has no password set. From man pam_unix (pam_unix is the module referenced below): nullok The default action of this module is to not permit the user access to a service if their official password is blank. The nullok argument overrides this default and allows any user with a blank password to ...


0

First off be sure that there isn't an easier way to get the information you want there are a lot of other tools out there that may work better, and htop doesn't go to files well. See: https://stackoverflow.com/questions/17534591/htop-output-to-human-readable-file although there is a kludge here: https://askubuntu.com/questions/726333/how-to-save-htop-output-...


5

The error is output at the time bash is processing the > /dev/tcp/localhost/22 redirection, and at that point stderr hasn't been redirected yet. Just change the order of those two redirections: if 2> /dev/null > /dev/tcp/127.0.0.1/22; then echo open else echo closed fi Note that those /dev/tcp/host/port are not real files. bash (or ksh where ...


2

I have script that writes to FDs 1, 2 and 3. I want to output script::1 and script::2 to stderr and script::3 to stdout. Just change the order: ./script.sh 3>&1 1>&2 [ you can omit the 2>&2, you only have to that in ksh for fds greater than 2 ;-) ] Most confusion with fd redirecting operators comes from the fact that people seem to ...


1

I got the answer sed -i -e '/hello/{ w file2.txt' -e 'd;}' file1.txt (moves the matching lines into file2.txt) Or grep "hello" file1.txt > file2.txt (copies the matching lines into file2.txt)


1

This is a textbook use of grep, so much so that it's called "grepping" as a verb much more often than it's called redirecting. fgrep hello file.txt > file2.txt fgrep is a variant of grep that only looks for fixed strings (as opposed to matching regular expressions, the re in grep). The standard equivalent is grep -F, though you'll find ancient grep ...


2

You will need the command grep. (man grep). And file redirection >. (man bash) From grep manual . . . SYNOPSIS grep [OPTION...] PATTERNS [FILE...] . . . -F, --fixed-strings Interpret PATTERNS as fixed strings, not regular expressions. . . . I recommend reading this manual, more fully.


1

Was having this issue after trying the exact same thing. As novice mentions in the comments, there is an -o flag which should output to file, however I found this didn't work under linux despite being in the man page. Ultimately what I needed was for iperf to continue running after ssh session interruption. In the end I used the following command. nohup ...


Top 50 recent answers are included