io redirection is the process of changing where the output and input of a program originate
6
votes
1answer
47 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 ...
9
votes
3answers
127 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
42 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
68 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 ...
-1
votes
2answers
80 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
27 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 ...
-2
votes
0answers
42 views
Outfile has a strange name [closed]
I ran a shell-script full of awk commands like this:
awk 'do something; print "bananas"' infile >> outfile
(in fact there where two files running at the same time, if that matters)
the ...
3
votes
3answers
178 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 ...
23
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
96 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 ...
2
votes
1answer
47 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
76 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
141 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
57 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
56 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
64 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
140 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
55 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)
3
votes
4answers
113 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
65 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 ...
1
vote
2answers
167 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.
3
votes
2answers
86 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
46 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 ...
2
votes
1answer
224 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 ...
3
votes
1answer
76 views
Redirecting output in the shell, permissions
I have a question about permissions.
Distro: Debian GNU/Linux 6.0.4 (squeeze)
So I have a folder with a php script in it. Both folder and file are owned by User1
If I do this:
php script.php
I ...
3
votes
2answers
163 views
echo string >> file does not work
I wrote the following script:
for filename in `find . -name '*'.cpp | grep $IN_REGEX | grep -v $OUT_REGEX`
do
echo "Output file is $OUTPUT_FILE"
count=`git log --pretty=format: --name-only ...
1
vote
1answer
131 views
How to ssh on multiple ipaddress and get the output and error on the local *nix machine?
command="ls -lrt;uname -a;uname -o"
for i in 10.38.227.229 10.38.164.103
do
ssh auto21@$i "$command 2>&1" >> log
#ssh -n auto21@$i "$command" 2> >> log
done
i am trying ...
3
votes
1answer
508 views
SSH causes while loop to stop
I have finally managed to boil down a problem I have been struggling with for a few weeks. I use SSH with "authorized keys" to run commands remotely. All is fine except when I do it in a while loop. ...
1
vote
1answer
65 views
Nested read fails
I have a list of filenames in a file and want to do let the user decide what to do with each. In bash, iterating over filenames is not trivial in itself, so I followed this answer:
#!/bin/bash
while ...
1
vote
2answers
90 views
run a command as different user with available sudo permissions
I want to run the below command
echo 1000 > /sys/class/backlight/intel_backlight/brightness
i cannot do it it like below beecause bash is the process that actually directs output to the ...
2
votes
1answer
100 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
141 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
55 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
77 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 ...
8
votes
3answers
270 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 ...
2
votes
1answer
105 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 ...
3
votes
3answers
143 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
147 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
54 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 ...
2
votes
4answers
296 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
44 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
300 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 ...
9
votes
2answers
536 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
124 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
43 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 ...
41
votes
5answers
2k 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
302 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
116 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
548 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 ...
6
votes
1answer
277 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 ...


