io redirection is the process of changing where the output and input of a program originate

learn more… | top users | synonyms (1)

1
vote
4answers
685 views

Inserting the command line text before output in stdout (for pipe / redirection)

Consider the following bash constructs: ls /usr/include/asm > list-redir.txt ls /usr/include/asm | tee list-tee.txt In this case, list-redir.txt and list-tee.txt will be identical, and will ...
17
votes
2answers
395 views

What does 'exec {fd}</dev/watchdog' do in Bash

That is literal, {fd} isnt a placeholder. I have a script that does this, and does not source in anything, nor does it reference {fd} anywhere else. Is this valid bash? exec {fd}</dev/watchdog
0
votes
1answer
22 views

Having extra parameters in piping or redirection

I have two programs and I want to pipe them into each other but they take extra parameters: prog1 <inputfile> <outputfile> min max prog2 <inputfile> <outputfile> min max ...
25
votes
5answers
2k views

Why pipe to cat only to redirect? [duplicate]

I occasionally see things like: cat file | wc | cat > file2 Why do this? When will the results (or performance) differ (favourably) from simply: cat file | wc > file2
12
votes
4answers
375 views

Why does cat x >> x loop?

The following bash commands go into an infinte loop: $ echo hi > x $ cat x >> x I can guess that cat continues to read from x after it has started writing to stdout. What is confusing, ...
3
votes
1answer
23 views

Executing awk on each file found with find, then redirecting the result to a new filename

I am trying to take the results from find and then execute awk to print the first two columns. Then I want to redirect those results to a new file name for each file, using the existing file name with ...
1
vote
3answers
69 views

pipe in shell with redirection

My understanding is that a pipe in shell like a | b redirects b's stdin to a's stdout. However, I tried ls | less < somefile, the behavior is very strange. less shows the output of ls concatenated ...
4
votes
3answers
593 views

Output exceeding terminal window height

I had run a program that resulted in many more lines of output than my current terminal window width. As a result, I could only see partial results...is there any way to get the full output? I am ...
4
votes
1answer
86 views

Capture output without redirection and leave it on terminal too

I need to capture output of a daemon that also includes a on-demand mode and behaves differently depending on if output goes to tty or not. Just redirecting stdout anywhere makes it go into logging ...
0
votes
1answer
34 views

Sort file “foo” and use redirection “>” to save output into the same “foo” file [duplicate]

i have a text file ~/foo: a b c a b c i use sort foo -u, and that works correctly. I can use redirection operator ">" to save output into other file (f.e.: sort foo -u > bar), but when i want to ...
5
votes
2answers
43 views

posix placement of stdin redirection (<in cmd vs cmd <in)

I always write stdin redirection after the command, because for me it's more natural to have first the command and then the redirections (if any): some-command < input-file > output-file For ...
4
votes
2answers
47 views

Capturing output/redirection of commands chained by &&

I have a series of commands a,b,c which I am chaining together with &&: a && b && c. I want to catch the output of all the commands to both stdout and stderr. a && b ...
1
vote
2answers
42 views

run command with sudo su in script and redirect stdin and stdout

I need to run command as another user and write to its stdin and read from its stdout. I can run command as another user only via opening new shell: sudo su anotheruser but with new opened shell i ...
6
votes
1answer
87 views

Extra output on input redirection

I have a folder with three files: $ ls a b c If I pipe the output of ls to wc, I get the right result: $ ls | wc -l 3 However, when I specify the input to wc as the output of ls, I get extra ...
31
votes
2answers
23k views

View stdout/stderr of systemd service

I have created a simple systemd service file for a custom application. The application works well when I run it manually, but my CPU gets maxed out when I run it with systemd. I'm trying do track ...
4
votes
1answer
129 views

Pass BASH array to diff like file contents

I have two bash arrays, say: arr1=( 1 2 3 ) arr2=( 1 2 A ) and I want to compare them using diff. How could I pass the arrays as if they were the contents of a file? I tried a few variations, but ...
15
votes
4answers
1k views

How can the standard input of one program be passed as an arg to another?

Let's say a program exists, which takes two arguments; input file and output file. What if I don't wish to save this output file to disk, but rather pass it straight to stdin of another program. Is ...
2
votes
1answer
42 views

Do not wait until the return for Shell redirection

I would like to redirect the output of a script (Python or any other kind) to a file. Easy to do with > or >>. But with these two the output seems to be written in the file only once the script ...
4
votes
3answers
550 views

Behaviour of “|” pipe in linux with “>” output redirection

I am executing command ls > a.txt | sort > b.txt This command is doing the below things : executing ls sorting it creating a.txt and storing sorted output to a.txt creating b.txt , but its ...
6
votes
2answers
15k views

nohup: ignoring input and redirecting stderr to stdout

I am starting my application in the background using nohup as mentioned below - root@phx5qa01c:/bezook# nohup java -jar ./exhibitor-1.5.1/lib/exhibitor-1.5.1-jar-with-dependencies.jar -c file ...
2
votes
1answer
35 views

Terminal - redirection of output to file is cutted

I am using command: ./cpp-generator > ~/log.log But when I open the log.log the file is short. It ends in the middle of word. But if I run just: ./cpp-generator in terminal is whole, full ...
9
votes
3answers
3k views

Piping STDERR vs. STDOUT

According to "Linux: The Complete Reference 6th Edition" (pg. 44), you can pipe only STDERR using the |& redirection symbols. I've written a pretty simple script to test this: #!/bin/bash echo ...
-1
votes
2answers
19k views

Redirecting the content of a file to the command “echo”

I have a file named my_file.txt whose content is just the string Hello. How could I redirect its content to the command echo? I know I have the commands less, cat, more... but I need to do it with ...
14
votes
3answers
446 views

How to log whatever I enter in terminal to file

I am a novice just learning Fedora 13. I just wanted to know if its possible to redirect whatever I type in the terminal to a file, so that I would be able to see from the file, that a particular ...
5
votes
2answers
370 views

Why bzip2 --version behaves strange?

So if I enter the command $ gzip --version | head -n1 everything goes as expected. But if I try the same with bzip2: $ bzip2 --version | head -n1 I get a lot of lines and I have to press Ctrl-C ...
1
vote
0answers
50 views

Recording shell output for interactive commands

While looking into a shell redirection problem, I found a couple of answers that pointed me to the script command. As I understand it, script just records in- and output of the terminal, and allows me ...
4
votes
1answer
653 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
1
vote
2answers
102 views

How to while read line with a pipe

I am currently trying read a csv file with BASH. The 10th [$f10] value of the csv file must be greater then 0 for a given machine class and machine ID [m_class] and [m_id] (these are user defined) . ...
2
votes
1answer
91 views

What are the Linux shells that allow network traffic management (sending/receiving data to/from `/dev/tcp/host/port`) via redirectors?

Following this Bash tutorial, I have succeded in obtaining the code of a web page issuing simple commands by using this method: $ exec 3<>/dev/tcp/www.google.com/80 $ echo -e "GET / ...
2
votes
1answer
60 views

Continously writing terminal output to text file

I am running a small cli python app in terminal. It loops infinitely and outputs text to the terminal. I want to output the text to a file, and I can do that with the following command python [my cli ...
4
votes
1answer
2k views

“>/dev/null 2>&1” in `if` statement

I don't understand the below if condition. I know that /dev/null 2 > &1 is sending output to error stream (please correct me if I am wrong). But I don't get it when it is in an if condition ...
2
votes
1answer
108 views

I/O redirection shortcut doesn't work when at the end of a command line

I've been getting myself comfortable with I/O redirection. I've become aware of the &> shortcut for 2>&1. I believe it also works as >&. There may be a nuance to that of which I'm ...
0
votes
4answers
54 views

Excluding specifics lines from being redirected [closed]

Let's say I am executing a script like this : /a/b/c/script.sh >> abc.log This will mean that all the contents/execution of script will be re-directed to abc.log. If I want a particular line ...
0
votes
1answer
33 views

Redirect stdin for multiple shell functions [closed]

I'm surprised nobody has asked this before - maybe I'm just that dumb? How to I force this script to do what I intended? #!/bin/bash function One() { IFS='' read -r -n1 CHAR echo "One: '$CHAR'" ...
0
votes
0answers
21 views

writefile() to file descriptor produces output with alignment issue

The command that produces weird output: $ vim -ec 'call writefile(["line1","line2"],"/proc/self/fd/9") | qall!' 9>&1 1>/dev/null 2>&1 line1 line2 $ Same command ...
0
votes
1answer
31 views

More succinct alternative to “lsof -p $(pidof postgres| sed -r 's/ /,/g')”

pidof returns a space separated list of pids. lsof -p requires a comma serparated one. This can be solved with sed via: lsof -p `pidof postgres| sed -r 's/ /,/g'` However, the extra pipe seems a ...
0
votes
0answers
85 views

extract text to csv file from output of reading multiple files into specific rows

I am trying to write a bash script to generate a csv file from text within multiple pdf documents. I have a script for converting pdf to text, but not for generating the csv file. Each text document ...
0
votes
1answer
27 views

Redirect all GnuPG output to /dev/null

I'm doing key generation in a sort of batch mode with GnuPG (don't ask why): echo -e 'addkey\n4\n2048\n120d\nsave' | gpg --command-fd 0 \ --edit-key $master_key_id >/dev/null 2>&1 I ...
4
votes
1answer
103 views

using pipe to run command in background

I was reading this question on rpi and noticed an interesting line that got me thinking: mkfifo tcp.stream nc -l -p 1234 > tcp.stream | omxplayer --live tcp.stream Notice the io redirection. ...
1
vote
0answers
62 views

Captive portal detection, popup implementation?

Based on hostapd, I m building a captive portal. - My Linux Machine provides a Wifi access. - iPad's and Android clients-tablets connect this Wifi. Generally, any client OS check if a url is ...
6
votes
1answer
50 views

zsh I/O redirection: redirecting and then piping; what is going on?

Can somebody explain what is going on in this command: echo foo >&2 | grep foo Zsh (5.0.2) prints foo twice. One seemingly to stdout and one to stderr, since running these commands: { echo ...
5
votes
2answers
131 views

Silent GnuPG password request with bash commands

I'm trying to hide the "output" of a gnupg command, but it seems that it is always printed. the command is: echo "thisprogramwørks" | gpg -q --status-fd 1 --no-use-agent --sign --local-user D30BDF86 ...
1
vote
2answers
70 views

How do I get the output of a program already running?

I have a python program that outputs to stdout and a log file. However, the person I am making this for wants to know if I can set it up so that he can see the output of the file, while it is ...
1
vote
1answer
93 views

zsh: Disable “file exists:” warning with redirection

How can I override the file exists: warning from zsh? > echo > newfile.txt > echo > newfile.txt zsh: file exists: newfile.txt In these cases I prefer my shell to not complain and ...
10
votes
2answers
3k views

Does `Segmentation fault` message come under STDERR?

I ran an executable in bash ./code > log It shows occasional error messages on terminal whereas all printf statements go into log file. I re-run it like below ./code >& log Now, the ...
24
votes
1answer
735 views

How do I redirect command completion output?

On the command line, I can redirect or pipe output of a command to a file or another command using the > or | operator after the command. I have come across a less standard situation that I would ...
1
vote
1answer
45 views

How to put “rm -i” in an iteration?

echo "$MOUNTPOINTLIST" | while read onelinefortouch; do touch "${onelinefortouch}testfileforwrite"; done echo "$MOUNTPOINTLIST" | while read onelineforrm; do rm -i "${onelineforrm}testfileforwrite"; ...
2
votes
2answers
45 views

One-liner to sort and uniq two outputs

I'm currently doing this to sort and uniq the output of two different commands: tshark -r sample.pcap -T fields -e eth.src -e ip.src > hello tshark -r sample.pcap -T fields -e eth.dst -e ip.dst ...
1
vote
1answer
36 views

How to redirect tarsnapper output to /dev/null?

I use tarsnapper's make command for managing tarsnap backups like this: tarsnapper -c /usr/local/etc/tarsnapper.conf make Which works like it should and I get an output like this Creating backup ...
0
votes
1answer
24 views

How to redirect the time a task takes to complete into a log file, given that such task is already redirecting?

I have a shell script running a python task, whose stdout is being redirected to a log file: python script.py >> log.txt I wish to also log the time this task takes to complete, into the same ...