io redirection is the process of changing where the output and input of a program originate
3
votes
3answers
101 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 ...
14
votes
2answers
399 views
Command line: <<< instead of <<
Why is the command md5sum <<< 'ddd'
(output: d6d88f2e50080b9602da53dac1102762 -)
right, and md5sum << 'ddd' not?
What does <<< mean?
0
votes
1answer
51 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
41 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
51 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
115 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
46 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
33 views
redirection to file issues with nohup and pipe
for the following script
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
56 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
116 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
49 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
80 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
58 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
112 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
82 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
44 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
133 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
65 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
156 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
107 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
358 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
62 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
87 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
99 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
107 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
52 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
73 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
239 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
93 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
109 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
120 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
49 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
249 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
43 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
265 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
435 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
111 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 ...
40
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
272 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
114 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
375 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
241 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 ...
2
votes
4answers
410 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
53 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
603 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
307 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
276 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
108 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
57 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 ...


