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

learn more… | top users | synonyms (1)

4
votes
1answer
255 views

Why does “cat /tmp/out1 > /tmp/in2 &” appear as “bash” with the “ps” command?

Consider: mkfifo /tmp/out1 mkfifo /tmp/in2 cat /tmp/out1 > /tmp/in2 & When I run ps it appears as bash in the CMD section. Why?
1
vote
1answer
38 views

Pipes & redirection binding precedence with disjuncts, conjuncts etc?

I know of the relative binding precedence of operators ‘;’, ‘&’, ‘&&’, or ‘||’ http://www.gnu.org/software/bash/manual/bashref.html#Lists but when pipes come into the picture along with ...
2
votes
2answers
35 views

saving the output of command line in a text file?

I am using the following command line to analyse data: unpackdcm -scr ${in} -targ ${out} This command is printing on the screen status and description about the progress in the job. In order to ...
1
vote
1answer
26 views

Redirect output to stdout and pipe to a binary

I have a nice PS1 line in my .bash_profile, and I want to copy it to another machine. So I want to view it AND copy it to my clipboard. I can't figure out how to string the commands to do this ...
3
votes
2answers
87 views

How can a bash script write its standard output from within a pipeline? [duplicate]

I have a bash script that calls a function. The function, amongst other things, executes a pipeline that sinks its output. To simplify it, here is a contrived example: #!/bin/bash func() { ls "$@" ...
0
votes
1answer
23 views

UNIX stdout redirection

I've written a script and I want to direct the console output to a file, so I use this command: ~/simplesim-3.0/sim-cache -cache:dl1 dl1:1:64:2048:f -cache:il1 il1:1:64:2048:f \ -cache:il2 dl2 ...
0
votes
3answers
27 views

Redirect stderr and stdout to another file descriptor

exec 6>&1 will copy file descriptor 1 onto 6. But how can I copy both stderr and stdout (1 and 2)to file descriptor 6 ?
4
votes
3answers
56 views

Time required to do pipe output to head/tail [duplicate]

There are lots of txt files in a directory. If I do time wc -l *.txt | head it takes real 0m0.032s user 0m0.020s sys 0m0.008s If I do time wc -l *.txt | tail it takes real 0m0.156s ...
2
votes
1answer
92 views

Writing to an interactive prompt

I’m using the ftp command line tool and want combine scripted input with user input. With only user input the prompt looks like this: ftp> But when I try to insert some input with a script, like ...
1
vote
1answer
15 views

ag output appears different in the terminal vs when piped to a file

When I run the ag command to search text files, I get output that looks like this on the command line (full results not shown): ❯ ag dependency 140317155505.md 27:The Bundler dependencies API ... ...
-1
votes
1answer
41 views

Redirect a directory as input to a script and output to a file

I want to use a directory name as a parameter for a pre-made script. Then the output goes into a newly made file in the home directory. It involves pipe/redirection. How do I do that? read dir $dir ...
4
votes
2answers
94 views

How to capture ordered STDOUT/STDERR and add timestamp/prefixes?

I have explored almost all available similar questions, to no avail. Let me describe the problem in detail: I run some unattended scripts and these can produce standard output and standard error ...
0
votes
6answers
55 views

What are some practical uses of STDIN redirection? [closed]

I am having a very difficult time trying to think of a single practical use for STDIN redirection. cat < /etc/passwd is an example of STDIN redirection, but it is silly in the same way as a useless ...
7
votes
4answers
272 views

Can I specify a redirected input before a compound command?

Bash lets you specify a redirected input before a command: $ <lines sed 's/^/line: /g' line: foo line: bar Bash also lets you redirect input to a compound command like a while loop: $ while ...
1
vote
2answers
85 views

How to grab output from command in shell script [duplicate]

I'm trying to write a shell script in RHEL which will execute grub-md5-crypt and the user will type their password. Now the problem is how can I grab the encrypted md5 hash displayed to the user in ...
2
votes
2answers
56 views

Should I use piping or redirection for input to 'sort'

I want to do awk -F "," '{print $1 }' inputfile1.txt | sort -u > distinctOutput.txt Is this good performance-wise ? Or should I redirect / use a temp file since I think it is better to make sort ...
1
vote
1answer
30 views

fuser output looks ambiguous

I am using fuser the output is like this: $ fuser / /: 1354rc 1362r 1370rc 1371rc 1395rc 1399rc 1403rc 1410rc 1414rc 1428r 1451rc 1458rc 1470rc 1472rc 1477rc 1480rc ...
-4
votes
1answer
68 views

UNIX homework question regarding piping output, I don't understand what it's asking?

Basically, I need to come up with a command that sends the contents of a file xxx into a program yyy, then the output is piped to the input of another program zzz, where the output is appended to a ...
11
votes
2answers
207 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, ...
1
vote
1answer
91 views

How do I Nohup an interactive shell-script?

My Script is having 2 command-line arguments and then just couple of questions, after these questions the script will run for itself, I'm able to pass the command-line argument by just doing, ...
1
vote
2answers
98 views

Process substitution with input redirection

I am trying to understand input redirection in combination with process substituation. I am using bash 3 An example with tr is the following $ tr "o" "a" <(echo "Foo") tr: extra operand ...
1
vote
1answer
27 views

Cannot redirect output from sed

I'm piping output from clock through sed to remove leading zeroes from numbers. It looks like this: clock -sf 'S%A, %B %d. %I:%M %P' | sed 's/\b0\+\([0-9]\+\)/\1/g' That works fine and produces the ...
0
votes
1answer
48 views

Bash STDERR still appearing after redirection [closed]

I am trying to parse the output of yum check-update in Bash 4 (Red Hat) and want to skip the first line that states: 'This system is not registered to Red Hat Subscription Management. You can use ...
5
votes
2answers
457 views

Is there any way to read lines from command output?

I have a pre process command to output a file ./preprocess.sh > preprocessed_file and the preprocessed_file will be used like this while read line do ./research.sh $line & done < ...
1
vote
3answers
88 views

How to send a output of unix command from one server to another server?

How to redirect the output of a unix command from one server to another server. I should be able to send the unix command's output from server-1. Then I should be able to receive the output in ...
3
votes
4answers
183 views

Redirect and pipe output

rpm -qa > file | wc -l returns 0. What am I doing wrong? I think it is clear what my goal is, but it isn't working. Is this a job for xargs or tee?
1
vote
3answers
57 views

How can I pipe data over network or serial to the display of another linux machine?

I have a second monitor that I'd like to use for a text-based debugging log and/or console. I don't want to have it as part of my GUI / "desktop" / main system. I have this display connected to an ...
1
vote
1answer
70 views

Why doesn't this piped script work?

#!/bin/bash rm out mkfifo out nc -l 8080 < out | while read line do echo hello > out echo $line done If I browse to the IP of the machine this script is running on (using port ...
4
votes
2answers
67 views

Inconsistent redirection behavior ssh interactive vs commands

These work, ssh remote 'echo hi > hi.txt' echo hi | ssh remote 'cat > hi.txt' but this does not work ssh remote sh -c 'echo hi > hi.txt' I expected to produce a file on remote named ...
4
votes
4answers
284 views

A command that generates both standard error and output

I want to do some troubleshooting on my bash script. Is there a short and simple command that generates both stdout and stderr so that I can use 2>&1 on it? Sorry if this looks trivial, but I ...
4
votes
3answers
375 views

pipe line with non-deterministic output

I have happened upon a command that sometimes works and sometimes does not, even when executed multiple times in rapid succession in a bash shell (I have not tested the behavior in other shells). The ...
0
votes
3answers
101 views

What does running “< ./somefile.txt” in shell do?

So I just executed < ./somefile.txt in a shell, and it doesn't appear to do anything (the text file has valid linux commands). So where are the contents of the text file being redirected to? I'm ...
1
vote
1answer
84 views

How to redirect per-CPU top output to file?

I want redirect top output to a file, but I am interested in the per-CPU usage. Doing just #I only want to see processes belonging to myuser top -b -d 1 -u myuser > top.txt gives me stats ...
1
vote
1answer
57 views

Why do I get “Permission denied” when redirecting the output of sudo echo “xyz” to a file? [duplicate]

Why do I get -bash: test: Permission denied when I run sudo echo "xyz" > test The directory permissions are: drwxr-xr-x 3 root root 4096 2014-08-05 16:26 I have no problem creating a ...
1
vote
2answers
44 views

awk - read program AND input from the standard input?

Is it possible for awk to read the program and the input from the standard input? I would like to be able to pipe a file to the following function. process_data () { awk -f - <<EOF {print} ...
0
votes
0answers
172 views

start-stop-daemon doesn't stop programs which redirect stdout/stderr

I just discovered, that start-stop-daemon doesn't work well with programs redirecting their stdout/stderr: # cat /root/_/1.sh #!/usr/bin/env bash set -eu cmd="~yuri/_/${2:-1}.sh" if [ "${3:-}" = ...
5
votes
1answer
66 views

Is it possible to use multiple here-docs in bash?

Can one use multiple here-docs to provide input to a command in bash? $ cat <<<foo <<<bar bar $ cat <<EOF1 <<EOF2 > foo > EOF1 > bar > EOF2 bar Obviously, ...
7
votes
1answer
59 views

How can I send reads and writes on a single file descriptor to different places?

I have a Linux executable foo that reads input from fd 0 and writes output to fd 0 (not fd 1). This works just fine for interactive use in the terminal. From the shell command line, how can I execute ...
-1
votes
3answers
228 views

cat /dev/null emptied my log file but size did not change

I'm quite new to Unix. Using Solaris 10 I faced the below issue. There is a large log file with size 9.5G. I tried to empty the file using the below command. # cat /dev/null file_log.txt By doing ...
3
votes
1answer
56 views

Does cat never read from terminal?

Chapter 43. Redirecting Input and Output of Unix Power Tools, Third Edition has to say this about cat command: Standard input (stdin) normally comes from your keyboard. Many programs ignore ...
3
votes
2answers
78 views

Decoding “prog > file 2>&1”

I am having some difficulty understanding the construct prog > file 2>&1. I have read that it means "Send stdout and stderr to file". But my question is how? I understand that prog > ...
4
votes
2answers
114 views

How to redirect stdout to a file and read from the same file simultaneously with another task?

I want to run a task (which takes quite a long time) remotely in Ubuntu Linux Bash via nohup and redirect stdout to a file, e.g.: nohup task > out.txt & From time to time I would like to ...
2
votes
2answers
233 views

Pass argument to script, then redirect script as input to bsub

I am currently working with the bsub job submission system from Platform LSF. I need to submit job scripts, but I am running into a problem with passing arguments to the job script. What I need is as ...
8
votes
2answers
261 views

Redirecting output depending on grep regex

I am using gradle run to start a REST server. The output of the REST server looks like this: XXX.XXX.XX.XXX - <moreinfo> randomtext randomtext XXX.XXX.XX.XXX - <moreinfo> XXX.XXX.XX.XXX - ...
3
votes
1answer
73 views

redirect output for a command that takes in multiple arguments

this command is to redirect output of time to with multiple args: $ time wc test >wc.out 2>time.out unix programming environment book shows that the error output of time redirects to ...
5
votes
3answers
174 views

Combining brace expansion and output redirection

Often, I use parameter expansion on the command-line, such as cp a.{ext1,ext2} which is expands to cp a.ext1 a.ext2 However, in many cases I do not use cp, but another tool, let's call it cat, ...
4
votes
1answer
122 views

How to make a variable from a subshell available in the parent shell

I've written a quick-and-dirty script to time some reports from a web service: BASE_URL='http://example.com/json/webservice/' FIRST=1 FINAL=10000 for report_code in $(seq 1 $FINAL); do (time -p ...
1
vote
2answers
58 views

Hiding Script Command Output

I'm building a shell script to automatically configure a specific computer with the best settings. I would like to hide all output from this script except for echo output. Is it possible?
1
vote
2answers
270 views

What does “batch mode” mean for the top command?

I was reading about the top command and I came across something I don't quite understand: top options: -b Run in batch mode. This is useful for sending output from top to other programs or to ...
12
votes
7answers
369 views

How do you remember the syntax for 2>&1 redirection [closed]

Do you have a mnemonic or system? This has bothered me for years I always have to look it up