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

learn more… | top users | synonyms (1)

13
votes
2answers
545 views

What does redirection with >| do?

When should you use >| for redirecting output to a file instead of just >? The explanation given when I was shown this was that it guaranteed the target file was truncated first. But I thought ...
4
votes
1answer
5k views

What does 2>&1 in this command mean? [duplicate]

I understand that this command attempts to write to nowhere or a null device but what does 2>&1 mean here? wget -q -O - http://yourwebsite.com/wp-cron.php?doing_wp_cron > /dev/null ...
2
votes
2answers
222 views

How do I redirect only stderr?

I am having a bit of trouble doing this. I am required to run a compiled .java file and redirect only stderr to a file called error. So the .java file is named javaProgram.java. This is what I have ...
2
votes
1answer
891 views

How do I redirect all writes and reads from /sdcard/whatsapp/ to /sdcard/shared/ on android?

I am using bluestacks appplayer beta with a rooted android, I want to redirect all writes and reads from one directory to another, how do I do that? I have a terminal available to put commands in..
2
votes
2answers
285 views

What is the use of “&>>” in bash?

I was studying a bash script code where I encountered operator "&>>". I didn't understand its use. So, I referred to http://www.gnu.org/software/bash/manual/html_node/Redirections.html . It is ...
2
votes
3answers
123 views

How can a command have more than one output?

In this answer, at the very bottom, Gilles mentions that a command can have more than one output or input. Yes, there's cat foo bar | something, for having both foo and bar as inputs, and there's tee ...
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
670 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
123 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
609 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
208 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
265 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
111 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
466 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
523 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
81 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
119 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
184 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
1k 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
751 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
149 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
710 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
61 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
523 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?
7
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
234 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
9k 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
408 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
174 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
489 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
36k 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
307 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
757 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?
1
vote
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
7k 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
431 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
368 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
390 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
135 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
585 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
679 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)