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
120 views

Why can't I trim a file using `head`? [duplicate]

Given a file, foo.txt: 1 2 3 4 5 Say we want to change it to contain: 1 2 3 Why does head -n3 foo.txt > foo.txt leave foo.txt empty?
2
votes
1answer
482 views

How to wait for a subprocess used for I/O redirection?

Consider the following snippet of Bash script: exec 3> >(sleep 1; echo "$BASHPID: here") do-something-interesting exec 3>&- wait $! echo "$BASHPID: there" When executed, it produces: ...
2
votes
1answer
113 views

Why is it possible to refer to a closed stderr under bash?

I'd like to know why bash doesn't display an error message when we refer to a closed stderr. When it comes to other file descriptors, they have to be opened if we want to, for example, duplicate them. ...
2
votes
1answer
112 views

Stderr of piped shell scripts isn't always displayed

I piped my own shell scripts for some testing and accidentally noticed something strange. Namely, the stderr of those piped processes isn't always displayed on the screen. I simplified the scripts ...
11
votes
3answers
702 views

Practical use for moving file descriptors

According to the bash man page: The redirection operator [n]<&digit- moves the file descriptor digit to file descriptor n, or the standard input (file descriptor 0) if n is ...
3
votes
1answer
233 views

Significance of arrows symbols in duplicating/closing file descriptors under bash

I'm reading a book about Linux command line where author doesn't seem to follow the conventions in bash manual regarding arrows symbols used in redirection operations. Namely, he always uses left ...
4
votes
3answers
2k views

combine output from two commands in bash

Is it possible to combine output from these two commands? node ~/projects/trunk/index.js python ~/projects/trunk/run.py run Neither command exits so I'm not sure how to do this.
-4
votes
2answers
2k 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 ...
1
vote
1answer
94 views

How get program name that produced an IO error redirected to a LOG in a nohup command?

I have a program that executes other programs in the background. The main program would be programA, and the programs executed by the main one, would be program1a, program1b and program1c. I need the ...
3
votes
4answers
1k views

How to pipe the stdout to a file if the current command is already being piped through gzip

So I have this command I need to run then disown: innobackupex-1.5.1 --user=root --password=**** --stream=tar ./ | gzip - > /data/myfile.tar.gz How do I pipe any output to a file? adding ...
1
vote
1answer
97 views

Unsure about the behaviour of my script when writing to log file

I have a very simple ksh script and at certain points I want to write to a log file. I use the following commands in two places... print "Directory listing 1:\n" > ${LogFile} ll >> ...
2
votes
2answers
1k views

How to discard stderr in restricted Bash shell?

In my .bashrc there are a couple commands which redirect standard error to /dev/null, and this is not allowed within rbash: bash: /dev/null: restricted: cannot redirect output Is there some way to ...
13
votes
2answers
3k views

Redirect all subsequent commands' stderr using exec

I have a bash file that I need to redirect all output to one file, debug log as well as to the terminal. I need to redirect both stdout and stderr to the debug and log it for all commands in the ...
2
votes
1answer
241 views

How to copy the output of pacman-color into a file and to display the output with the colors in the terminal

Originally I used pacman, not pacman-color and I copied the output into a file and I displayed the output in the terminal with the following command : pacman -Syu | tee file.log Unfortunately, it ...
0
votes
0answers
49 views

Root user can't do everything? [duplicate]

Possible Duplicate: Redirecting stdout to a file you don’t have write permission on I'm quite new to Linux and I have a permissions questions. I'm using Linux Mint. If I go to /opt and do ...
43
votes
5answers
3k views

Can a command line program prevent its output being redirected?

I have become so used to do this: someprogram >output.file I do it whenever I want to save the output that a program generates to a file. I am also aware of the two variants of this IO ...
2
votes
1answer
483 views

How redirect input while process is running?

I have an interactive application that takes input from the keyboard. Whenever I run the application I always write the same things in the beginning. So I was thinking I could make a file with those ...
2
votes
4answers
151 views

store and execute redirection/piped command in script

How do you store, and later execute, a command with redirection and and a pipe? (And is it the pipe, or the redirection, or both, that's causing my problem?) I tried to print the urxvt version in a ...
2
votes
2answers
2k views

How to change the output redirection of a running process?

I know how to redirect output and how to suppress them in bash. Now, suppose I accidentally forgot to append the output redirection part to the command (e.g. 2>&1 or > /tmp/mystdout) and my ...
9
votes
2answers
1k views

echo vs <<<, or Useless Use of echo in Bash Award?

By now the Useless Use of cat Award is very well known, and there's also a mention of a Useless Use of echo (not relevant for this question). I'm wondering if there should be a "Useless Use of echo in ...
6
votes
4answers
8k views

How to view the output of a running process in another bash session?

I have left a script running on a remote machine from when I was locally working at it. I can connect over SSH to the machine as the same user and see the script running in ps. $ ps aux | grep ...
2
votes
1answer
153 views

Why doesn't the output get redirected into the file?

have the following command line that outputs vmstat every second with a time stamp on each line via the perl script: vmstat 15 | /home/Beer/addtimestamp.pl > File_1 the contents of the ...
11
votes
2answers
638 views

Why is it that these two 'cat' commands result differently?

Let's assume that infile contains a specific text, and I were to execute the following set of commands: exec 3<infile cat -n <&3 cat -n <&3 The first instance of cat ...
2
votes
1answer
705 views

Redirecting syslogd Error Messages to an Error Log or to a Null File?

I have an old PowerPC laptop (old Mac Powerbook G4) that I am running a variant of Debian Squeeze on (MintPPC 9). I keep getting Kernel error messages when I am connected to a particular wireless ...
1
vote
1answer
938 views

Behavior of while loop and for loop in unix script

I am trying to read user and server details from file tempo.txt and then check the disk space usage of the file system on that unix account using another script server_disk_space.sh.But I am not able ...
0
votes
2answers
191 views

Why doesn't Bash accept `&>&3`, i.e. redirecting stdout and stderr to file descriptor 3?

Given the preamble, foobar function and invocations of it: exec 3>/dev/null function foobar { echo foo; echo bar >&2; } foobar >/dev/null foobar 2>/dev/null foobar ...
0
votes
1answer
100 views

Redirecting head output for update hosts file [duplicate]

Possible Duplicate: How can I make iconv replace the input file with the converted output? I'm writing a script to change the content of my hosts file but I got stuck on the head output ...
2
votes
1answer
367 views

Redirect all standard out for rest of script

I have a bash script that I want to redirect all the rest of the output into a file. #!/bin/bash # the part i dont know ${file} echo spo echo car cat ${file} output should be spo\ncar\n
2
votes
3answers
2k views

Count running processes using wc and ps

I tried using ps r > log | wc log but this returns Ambiguous output redirect.. Can someone explain why and provide another solution?
1
vote
1answer
104 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
3k 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
168 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
2k 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
530 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' | ...
8
votes
1answer
13k 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. ...
3
votes
1answer
549 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
238 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
851 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
717 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
2k 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) ...
7
votes
2answers
5k 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
279 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
1k 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
305 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
2k 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 ...
4
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
645 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
97 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
440 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
178 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 ...