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

learn more… | top users | synonyms (1)

2
votes
1answer
43 views

Inner logic of chained redirections

When I type cat some_file > new_file1 > new_file2 I got output from some_file in new_file2 and empty new_file1. What is the inner logic in it? More specifically what is the stdout of file? ...
3
votes
2answers
644 views

Who is file owner if the file is created using sudo command?

I logged in using my username ravbholua: ravbholua@ravbholua-Aspire-5315:~$ echo $LOGNAME ravbholua I create file named a1: ravbholua@ravbholua-Aspire-5315:~$ echo>a1 ...
1
vote
1answer
119 views

Pipe not picking up stdout

I am running a java program from a OS X 10.8 bash terminal, and are trying to rederect the output it is producing. However, when either running this throug a pipe, or rederecting it to a file, the ...
3
votes
2answers
46 views

io redirection to “cross” 2 programs

How to "cross" stdin and stdout of two programs? Specifically, I have 2 programs call pgm1 and pgm2, they are interactive tic-tac-toe games. They both output a number (0to8) indicating position where ...
4
votes
3answers
592 views

Split stdin by lines

I want to invoke a command for every line of the standard input, much like xargs, but the line should be passed as standard input, not as a command-line argument: cat some-file.txt | <magic> | ...
2
votes
1answer
190 views

input output redirection in bash [duplicate]

In Ksh for redirecting i/o from a command away from standard output/error I do , [ where command is any command that produces output/error ] command 2>filename command 2>/dev/null or command ...
7
votes
3answers
260 views

How to run a command while logging output to a file?

I have a console application that needs to be run as part of the deployment of a new application version on my server. This console application is designed to output to the console, and cannot be ...
5
votes
1answer
109 views

Replacing stdout with stderr

Is it possible to redirect the output from a command to replace the text sent to stdout with the text from stderr? $ ./script this line is redirected to stdout this line is redirected to stderr $ ...
6
votes
3answers
1k views

Restoring output to the terminal after having issued “exec &>filename”

I am trying to execute the following: exec &>filename After this I am not able to see anything including what I typed, alright. I frantically try , exec 1>&1 and exec 2>&2 , ...
0
votes
1answer
38 views

Output redirect complexities

I'm trying to have a script exit with an error in the event it can't reach an X server: xset -q &> /dev/null || { echo "The Display Server is BROKEN. Aborting."; exit 1; } However, I'm getting ...
16
votes
2answers
465 views

Why does this command create an enormously large file?

I was experimenting today with some append operations and, in my curiosity, ran this (where file1.txt was non-empty and file2.txt was empty): $ cat file1.txt >> file2.txt >> file1.txt ...
1
vote
2answers
501 views

What stream does perf use?

What stream does the perf command use!? I've been trying to capture it with (perf stat -x, -ecache-misses ./a.out>/dev/null) 2> results following http://stackoverflow.com/q/13232889/50305, ...
5
votes
1answer
79 views

Is it possible to create sticky redirection from stdout/stderr

Consider such code: echo hello >> log.txt echo world >> log.txt I execute command with stdout redirection. Is it possible to create sticky redirection? Something like this: redir ...
2
votes
1answer
118 views

Redirecting an active port

Environment: Web server that requests pages on a specific port from an application server. Problem: If a page request comes into the application server during the restart of a certain web application ...
3
votes
1answer
180 views

Pipeline and redirection understanding

Please explain this script (from ABSG. Ch. 20): exec 3>&1 # Save current "value" of stdout. ls -l 2>&1 >&3 3>&- | grep bad 3>&- # ...
13
votes
4answers
983 views

Is it possible for a sysadmin to eavesdrop on his/her users' terminals?

When logged in to a machine, I can find out each user's pseudo-terminal device(s) from the output of w. Being a sysadmin, is it possible for me to eavesdrop on this terminal without the user being ...
4
votes
2answers
713 views

What does “sh a.sh <&0 >&0” mean?

It's a question about bash shell command. "sh a.sh <&0 >&0" What dose it mean? Especially, I'm not very clear about what does &0 mean?
2
votes
1answer
146 views

xargs and < and > to the same files

I want to run git stripspace on all my source code files, on each build (or precommit or just manually), to remove extraneous whitespace, and later maybe to format the code in a standard way, So ...
10
votes
3answers
280 views

Is this a typo in Bash manual's redirection section?

Note that the order of redirections is significant. For example, the command ls > dirlist 2>&1 directs both standard output and standard error to the file dirlist, while ...
3
votes
2answers
122 views

Is it possible to create a “file” that can be used by any process without actually saving the file on disk?

Suppose I do a grep that gives me a lot of results. I want to use the output of grep and pass it to a command that takes a filename as it's first argument. For example - myCommand filename.txt I ...
3
votes
3answers
644 views

Pipe command output to input of running/backgrounded command

In Bash 4.X It it possible to do something like: command that expects input & echo some output | %1 Where %1 represents the first backgrounded command?
0
votes
1answer
60 views

Resume input from user after file is read [duplicate]

I have a program that reads user input—moves, it's a boardgame—from the user. Like so: $ game enter your move: # etcetera The first N moves I need to repeat each time, so I put them in a text ...
1
vote
3answers
505 views

How to capture the standard output of a script that depends on the user for some input?

There is a script that requires me to enter the password before it continues: bash-3.2$ ./script.sh <parameter_list> Enter the password for the Database: .. .. I am interested in capturing ...
3
votes
3answers
2k views

How to stop redirection in bash

I use : exec >script.log 2>&1 in my script to redirect all output to a file. At the end of the script I would like to print a message to the screen. How do I stop the redirection?
6
votes
1answer
5k views

Redirect both stderr and stdout to /dev/null with /bin/sh

Tried all sorts of ways to redirect both stdout and stderr to /dev/null without any success. I have almost my entire life run bash which i've never had this issue with but for once in BSD i'm stuck ...
3
votes
2answers
112 views

Diverting a file write to process

I have an OSX GUI application which I can't change - it writes new CVS lines to a log file when it completes a job. I'd like to work with these new lines, but they are constantly being added. Is ...
0
votes
1answer
224 views

no stderr output when using stdbuf -o 0 |& tee log

I want to log the standard output and error info from running my program, using the following command: stdbuf -o 0 ./myprogram|& tee mylog it works fine in one computer, I can see both ...
10
votes
1answer
8k views

How to redirect stdout and stderr to a file and display stderr to console?

I know how to redirect to a file, and use tee; on a basic level. So $ alias outanderr='bash -c "echo stdout >&1; echo stderr >&2"' # A fake "application" displaying both output and ...
12
votes
3answers
406 views

When to use redirection to stderr in shell scripts

I know that well-behaved utilities like grep output "normal" messages to stdout, and error messages to stderr. $ grep '^foo' file1 file2 file1:foo grep: file2: No such file or directory When I'm ...
3
votes
2answers
169 views

Do redirection operators always open file descriptors in parallel?

1. Consider snippet#1: $ cat test.txt > test.txt cat: test.txt: input file is output file It seems that cat makes its input file descriptor point to test.txt and then when it tries to set its ...
2
votes
3answers
449 views

How to use arguments with 'find -exec'? [duplicate]

I'm trying to generate static html files for all php scripts inside dir: find . -name "*.php" -exec php {} > {}.html \; But it just dumps all results to {}.html. How to do it properly? And how ...
12
votes
3answers
31k views

How to append multiple lines to a file with bash

I am writing a bash script to look for a file if it doesn't exist then create it and append this to it: Host localhost ForwardAgent yes So "line then new line 'tab' then text" I think its a ...
3
votes
1answer
304 views

Running time command with cron

So I have a crontab that have this line: 30 16 * * * (time sysbench --test=cpu --cpu-max-prime=20000 run) 2>> ~/cpu.out I use this because time output goes by default to stderr and I want to ...
3
votes
3answers
701 views

Concatenating thousands of files: > vs >>

I found two seemingly contradictory answers on StackOverflow to the following questions: Concatenating Thousands of Text Files Across Hundreds of Directories (while keeping some structure) How do I ...
27
votes
2answers
1k views

Command line: <<< instead of <<

Why is the command md5sum <<< 'ddd' (output: d6d88f2e50080b9602da53dac1102762 -) right, and md5sum << 'ddd' not? What does <<< mean?
0
votes
1answer
5k views

How do I redirect output from the find command (that uses grep) to a log file?

Consider the code to search for all files containing the pattern "search string": bash-3.2$ # The below find works fine.. bash-3.2$ find . -type f -exec grep -il "search string" {} \; bash-3.2$ # But ...
4
votes
1answer
6k views

Always redirect error to /dev/null

I know I can redirect the error messages from a command to /dev/null using the following syntax: command arg1 arg2 2>/dev/null But is there a way to do this by default so that the error messages ...
1
vote
2answers
413 views

Chaining mysqldumps commands to output a single gzipped file

Let's say I have these series of commands mysqldump --opt --databases $dbname1 --host=$dbhost1 --user=$dbuser1 --password=$dbpass1 mysqldump --opt --databases $dbname2 --host=$dbhost1 --user=$dbuser1 ...
4
votes
4answers
358 views

Can I write the output the of time difference command to a file?

Can I write the output of the time difference command to a file? For example, I tried: $ time foo.sh > bar.txt But it only gives the output of foo.sh to bar.txt.
2
votes
1answer
384 views

Separate STDOUT noise from ncurses

I am trying to run an ncurses GUI application on an ARM board. I am running it using the serial console ttyAMA0 port. But when I run the ncurses program, the other processes running in the background ...
2
votes
1answer
2k views

redirection to file issues with nohup and pipe

For the following command: ssh -t esolve@hostname 'sudo nohup bash -c "ls > log 2>&1 &"' I always got error information: nohup: ignoring input and appending output to ...
1
vote
1answer
131 views

Standard I/O File Descriptors

I am new to Shell SCripting I code this $ ls -l 1> stdout.txt and I get the output as desired, 1> stdout.txt redirects the output from standard output to the file stdout.txt. I don't ...
0
votes
2answers
575 views

Redirecting stdin with stdout to file

So I have a program that takes in user input and outputs text based on the input. EDIT2: I want to create a script that runs a C executable and the script feeds the C program input from a file and ...
1
vote
2answers
638 views

Redirecting Multiple Commands as Input

What is the correct way to redirect the output of multiple commands as input for another command? e.g. $ command < (command2 | grep pattern)
4
votes
4answers
1k views

Getting stdin from a named pipe

What I am trying to do is run python in a terminal window and redirect it's stdin from a named pipe. Then I write to the named pipe in another terminal and have that command execute on python. ...
2
votes
2answers
110 views

What makes the shell interpret these redirects as follows?

Can anyone help me understand this seemingly odd behavior of how the shell parses the redirects..? $ cat > test.txt Line 1 Line 2 $ ls -i dummy.txt dummy2.txt ls: dummy.txt: No such file or ...
17
votes
2answers
15k views

Difference between 2>&-, 2>/dev/null, |&, &>/dev/null and >/dev/null 2>&1

Just looking for the difference between 2>&- 2>/dev/null |& &>/dev/null >/dev/null 2>&1 and their portability with non-Bourne shells like tcsh, mksh, etc.
8
votes
2answers
254 views

When should I use input redirection?

I used the following two commands to produce the same results:- [root@localhost ~]# grep line comments The line should start with a single quote to comment in VB scripting. Double slashes in the ...
2
votes
2answers
80 views

redirecting std output and std error

I have been trying to figure out the relationship between file descriptors. One thing I don't understand is, how is: ls -l /bin/usr > ls-output.txt 2>&1 different from: ls -l /bin/usr ...
3
votes
1answer
2k views

starting server with nohup and redirecting input, output

I have a init.d script that starts a python socket server. Because I want this to run as a daemon, I use nohup to start it. I also want to redirect stdout and stderr to a log file. My problem is ...