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

learn more… | top users | synonyms (1)

1
vote
1answer
101 views

What is the difference between who > lp and who | lp?

Why does the who > lp creates a file but who | lp leads the output to program lp? What is the underlying principle behind these two simple commands? Can somebody explain it with an example?
1
vote
2answers
2k views

How can I get vsftpd version into shell variable?

I want to get vsftpd version into shell variable. I can get it to console with ease: # vsftpd -version vsftpd: version 2.2.2 Also I can get a lot of other info into variable: # i=`bash --version ...
2
votes
2answers
162 views

Where to place a Bash shell redirection for a command? [duplicate]

Possible Duplicate: Order of redirections Apart from the standalone exec >&2 to redirect the current shell's input and output are there any behavioral differences in the following ...
7
votes
2answers
1k 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 ...
1
vote
2answers
445 views

Print/Tee to console without passing output to pipe

Is there a way to print or tee one thing to the console and still pass something else through to the next pipe? Something like: echo dog | printOrWhatnot "PUTTING MY THING DOWN" | sed 's/dog/cat/g' | ...
4
votes
1answer
9k views

How to redirect output to a file from within cron?

I have a backup script which I need to run at a particular time of a day so I am using cron for this task and from within cron am also trying to redirect the output of backup script to a logfile. ...
2
votes
1answer
444 views

Parameretrize file descriptor number to open a tcp socket in shell script

I'm tried to parameretrize in a variable the file descriptor number to open a tcp socket using exec command but it failed. Only work correctly when file descriptor number is a constant. In the next ...
4
votes
2answers
215 views

Redirect stderr of the double-parentheses construct

I'd like to be able to redirect the stderr of a double-parentheses construct. For example: a=$(($var/$var2)) would output some error messages if $var2 = 0, I do not want the user to see this. I ...
3
votes
2answers
697 views

How can i redirect the output to a file when the program is build with ncurses library [duplicate]

Possible Duplicate: Removing control chars (including console codes / colours) from script output If we redirect output to file in this pattern top >> somefile.txt, we get lot of ...
7
votes
1answer
503 views

Append same text to many files using cat or echo?

How can I write the same content to many text files by using cat or echo in only one command? For example I want to write "hello" to file1 and file2. I tried: echo "hello" >> file1 file2 ...
24
votes
6answers
1k views

Why can't I redirect a path name output from one command to “cd”?

I am trying to get cd to accept a directory name redirected to it from another command. Neither of these methods work: $ echo $HOME | cd $ echo $HOME | xargs cd This does work: $ cd $(echo $HOME) ...
6
votes
2answers
4k views

/dev/tcp listen instead of nc listen

With a netcat listener like: nc -l <port> < ~/.bashrc I can grab my .bashrc on a new machine (doesn't have nc or LDAP) with: cat < /dev/tcp/<ip>/<port> > ~/.bashrc My ...
2
votes
1answer
256 views

su and redirection

The following line shows the principle of a construct which I can use under Red hat 5.5: $ echo "foo" | ssh myhost "echo \"cat <&1\" | su --login" foo Actually it was never clear to me why ...
10
votes
2answers
971 views

Interactively deleting files from a list

I'd like to remove a list of files and be asked for confirmation. The list is in the list.txt file. Why the following command doesn't work properly? while read i; do rm -i $i; done < list.txt ...
1
vote
2answers
202 views

Redirecting tr stdout to a file [duplicate]

Possible Duplicate: How can I make iconv replace the input file with the converted output? Can I read and write to the same file in Linux without overwriting it? $ cat test.txt This is a ...
5
votes
1answer
1k views

How to send output to both screen and mail?

I use the following to send an email at the end of a script. echo "Script finished on `date`" | /usr/bin/Mail -s "Script complete" "myaccount@myserver.com". However, I want to echo the same message ...
3
votes
1answer
2k views

piping strace to grep

I'm trying to run strace trough ccze, and the pipe doesn't work as expected. The command-line I'm running to test is sudo strace -p $(pgrep apache2) | grep open, and all lines are output, ignoring ...
4
votes
1answer
500 views

'watch'-ing curl yields unexpected output

I'm trying to watch curl for live feedback on HTTP tweaks. However, when I execute the command, the output is garbled with some download stats. I've tried sending curl's stderr to /dev/null, to no ...
1
vote
1answer
92 views

Redirection doesn't show up as an argument to a sourced script

My problem is that I can't print to the screen when I write a bash script . myBashScript.sh < text.txt In myBashScript.sh I just print out echo $2 But instead of printing "text.txt", it ...
1
vote
3answers
375 views

Redirecting without color [duplicate]

Possible Duplicate: Removing control chars (including console codes / colours) from script output How do I disable all color codes when redirecting to file? I previously asked how to ...
2
votes
1answer
162 views

Redirecting output to file

I am looking forward to run commands and log their output in a temporary log file to be read later on by different processes. So, for example: rc.d start ntpd > progress.txt Returns: ::Daemon ...
2
votes
1answer
149 views

Inconsistent input redirection behavior

I wrote a 10000010-byte file (99010 rows of 100 consecutive a's) named big for experimentation purposes. I then copied the entire text into my clipboard, ran wc, and pasted it into stdin. Next, I did ...
0
votes
2answers
337 views

Write to error stream in while loop

I’ve got approximately the following code: cat infile | while read line; do echo 2> 'log ' $line echo $line done > outfile outfile is created correctly. However, the STDERR output ...
3
votes
1answer
452 views

Does input redirection (<) append a newline character?

I was originally of the impression that $ ./myprog moo[CTRL-D] is exactly the same as $ echo moo > cow $ ./myprog < cow But I found that myprog always counts one more \n in the second ...
3
votes
2answers
961 views

exec < filename - what does this do?

I have found the following code snippet (sh): TESTFILE=$TEST_PATH/test.out if [ -f $TESTFILE ] then exec < $TESTFILE else echo "$TEST_PATH: no test.out file" fi ...
2
votes
2answers
2k views

What's the difference between STDIN and arguments passed to command?

I could use the either form to execute the cat method: cat file_name cat < file_name The result is the same Then I want to execute man in the format of STDIN man < file_name For the ...
0
votes
1answer
205 views

The “cp p2 &2 &” command makes Konsole to disappear, is it a bug?

The goal is start a background process that copies the data from the pipe p2 to the STDOUT as p2 is feed with data by some other process. I guess the command is incorrect. Nevertheless, the Konsole ...
0
votes
3answers
1k views

wget is returning an html page instead of original file

In my case the problem is with SourceForge.net. Actually I was trying to download these files: http://sourceforge.net/projects/wxpython/files/wxPython/2.9.4.0/wxPython-src-2.9.4.0.tar.bz2/download ...
8
votes
1answer
13k views

Is there a way to redirect nohup output to a log file other than nohup.out?

I frequently use the program nohup so that my processes are immune to hangups. So if I want to make the program program immune to hangups, I use the command nohup program & where & puts ...
9
votes
2answers
336 views

Trying to “locate” and then open a file

Suppose that I have a file named filename123.txt and it is the single file that is named so, and I can locate it with the command locate filename123. And it returns only this file. Now I want to open ...
5
votes
1answer
119 views

ask for comfirmation when file is replaced using a redirection

I'm a careless terminal driver scared of accidentally deleting files, hence using some aliases like alias rm='rm -i' for rm, mv, cp. How can I get a similar confirmation behavior for file redirections ...
4
votes
2answers
754 views

Behavior of stdin/stdout in conjunction with subshells and cd command

I have the following series of commands: cd / && ls | ( cd /tmp && cat >dumpfile) This series of commands does the following: it creates a file named /tmp/dumpfile. This file ...
12
votes
2answers
587 views

Redirect stderr from an already running script

I've been running a script for several days now. I redirected stdout to $HOME/mylog, but didn't redirect stderr since I thought there would be nothing on it. Suddenly thousands of lines started coming ...
4
votes
1answer
338 views

Append output to a file and redirect stderr to null

How can I append the result of a command to a file and redirect stderr to null?
90
votes
1answer
4k views

Bash: What does “>|” do?

I have just seen this written down; $ some-command >| /tmp/output.txt Vertical pipes are used in standard redirects "piping" the output of one command to another, is >| in fact completely ...
5
votes
3answers
6k views

ssh input from text file

These two question is driving me crazy and I don't have good expertise of ssh. (but I suspect it is to do with redirection only) The questions are, You want to pass multiple lines of input from a ...
6
votes
2answers
3k views

Why does `exec 2>&1` fail in this bourne shell script?

I am porting an old ksh script to Bourne shell. The old ksh script contains the following code: #!/bin/sh tmpLog=/var/tmp/logfile.$$ exec 1> $tmpLog exec 2>&1 eval $* another_command_1 ...
1
vote
2answers
647 views

On the command line, can I redirect output to a file WITHOUT >, >>, or | operators?

I am attempting to run a command on a CentOS virtual machine, and the API that I am using to run this command does not seem to allow the >, >>, or | operators. Also, I must use fully qualified paths ...
3
votes
2answers
1k views

Sending the output from 'dd' to awk/sed/grep

I'm trying to approximate the computer's write speed using dd: dd if=/dev/urandom of=/dev/null bs=1K count=10000 which gives the following output 10000+0 records in 10000+0 records out 10240000 ...
3
votes
3answers
1k views

Piping in awk scripts

I'm trying to write a ls wrapper that uses awk to parse the output of ls -lhF. Right now I've split the program into two files - my_ls.sh and my_ls.awk. my_ls.sh's only purpose is to pipe the output ...
13
votes
2answers
1k views

Does redirecting output to a file apply a lock on the file?

If I have a command $ ./script >> file.log that gets called twice, with the second call occurring before the first one ends, what happens? Does the first call get an exclusive lock on the ...
5
votes
2answers
506 views

Wrapping a shell script with tee

There is a bash script which prints some logs and allows some arguments. The script prints the logs to STDOUT. Let's say the script's name is AAA.sh I'd also like to make the script to print the logs ...
1
vote
3answers
243 views

Concise way to output to file if argument is given, to stdout otherwise

I'd like my script to output to stdout unless it gets a filename as an argument. An obvious way is like so: if [ -e "$1" ]; then command_with_output >$1 else command_with_output fi It's ...
1
vote
2answers
1k views

Show command executed along with output in log file

Is there a quick and dirty way to not only log the output of a shell file but the commands used inside as well? For example: whoami > who.dmp would output a file that contained something like: ...
4
votes
2answers
410 views

how to redirect terminal output to multiple log files

I've been trying redirect output to logfiles but should NOT be displayed on terminal, but following command does output both on terminal and in logs. Any ideas are appreciated. (some_cmd | tee -a ...
8
votes
1answer
832 views

Suppress output unless non-zero exit code

What's the best way to suppress output (stdout and stderr) unless the program exits with a non-zero code? I'm thinking: quiet_success() { file=/tmp/suppressed if ! ( "$@" > "$file" ...
2
votes
2answers
765 views

How to remove error messages when searching recursively for a string?

I use find -type f -print0 | xargs -0 -n 10 grep -i searchstring to search recursively for a string. But it also gives me error messages like "permission denied". How can I avoid such error messages ...
6
votes
1answer
306 views

differences between echo“”> and > command

I am new to Linux. There is something that is unclear to me. What is the difference between echo "" > logfile and > logfile ? When I run the first one, the logfile size doesn't become zero ...
1
vote
2answers
112 views

bash: Redirect IO , but not with suffixes

usually I use XX 2>error.log , but for debug purposes , I prefer the following syntax: function XX() { redirect_io_to "error.log" } Is there such syntax available ? It's convenient ...
1
vote
2answers
558 views

Writing both output and error stream to the same file

In Unix/Linux you can use pipes to write output and error streams to a file. One can even write them to the same file. Is there a way to write both to the file but maintaining the order. This ...