io redirection is the process of changing where the output and input of a program originate
4
votes
2answers
110 views
Unable to capture program exit
I started a program written using Node.js and started it using launch pipe into logfile and send it to background.
Half way running the program exited w/o any error both on the console nor the log, I ...
8
votes
4answers
3k views
Difference between 2>&1 > output.log and 2>&1 | tee output.log
I wanted to know the difference between the following two commands
2>&1 > output.log
and
2>&1 | tee output.log
I saw one of my colleague use second option to redirect. I know ...
10
votes
1answer
3k views
View stdout/stderr of systemd service
I have created a simple systemd service file for a custom application. The application works well when I run it manually, but my CPU gets maxed out when I run it with systemd.
I'm trying do track ...
3
votes
1answer
247 views
Removing redirection operator does not change output. Why?
I saw this usage of redirection somewhere, and thought it was a typo:
grep root < /etc/passwd
But after I run it, I saw that it gives the same output with
grep root /etc/passwd:
$ grep root ...
2
votes
1answer
525 views
shorthand for feeding contents of multiple files to the stdin of a script
Hi good people of this community,
Say I have a script called script, that reads from stdin and spits out some results to the screen.
If I wanted to feed it contents of one file, I would have typed:
...
3
votes
1answer
2k views
Why can't sudo redirect stdout to /etc/file, but sudo 'nano' or 'cp' can?
Why does redirection, using sudo give me an error for the following commands?
$ sudo printf "foo" >/etc/file
bash: /etc/file: Permission denied
$ sudo printf "foo" ~/file; cat ~file ...
4
votes
1answer
911 views
All about ssh ProxyCommand
I am looking for an in-depth explanation of the following ProxyCommand, down to the nuts and bolts of its operation, please. Can you kindly completely dissect it for me and improve on it if you can? ...
1
vote
1answer
315 views
Why can I append to a file but not overwrite it?
If I do this:
iptables -nvL > output.txt
output.txt ends up empty. If I do:
iptables -nvL >> output.txt
It works fine. Appending is working, but overwriting is not. Why?
0
votes
0answers
286 views
Shell redirection all of a sudden not working? [closed]
I have a Canon camera mounted with gphotofs and I'm trying to essentially do an md5sum on all of the files, but I need to rename the files before I write them to my file, so sed is in the equation. ...
3
votes
4answers
405 views
Bash Reuse Process Substitution File
I have a big script which takes a file as input and does various stuff with it. Here is a test version:
echo "cat: $1"
cat $1
echo "grep: $1"
grep hello $1
echo "sed: $1"
sed 's/hello/world/g' $1
I ...
1
vote
1answer
474 views
Taking output of /dev/tty into a variable
I created a two backup scripts - one for files (filebackup.sh) and another for database (dbbackup.sh). filebackup.sh calls dbbackup.sh and stores the output in a variable. The output returned by ...
2
votes
4answers
563 views
How can I run a process in a terminal window and then hide that window?
I want to run python ~/program/proxy.py in a terminal when I boot up. And then hide this terminal window (because it is just a proxy program, and I don't want to see the debug info). So how can I get ...
5
votes
1answer
190 views
stdin/stdout names in BASH?
I have a program that takes a -o log_file option, which writes extra data to log_file.
Is there any way for me to redirect that to stdout?
i.e. is there a "special name" for stdout that can be used ...
15
votes
4answers
1k views
What happens to the output of a process that has been disowned and lost its terminal?
If I close the virtual terminal, where some process was started, does the output just go straight to /dev/null, or can it pollute memory somehow?
Can I anyhow grab the output to continue reading it at ...
8
votes
5answers
2k views
How to limit log file size using >>
How can I limit the size of a log file written with >> to 200MB?
$ run_program >> myprogram.log
3
votes
2answers
490 views
Performance difference between stdin and command line argument
For some commands, it is possible to specify certain input as either stdin or a command line argument.
Specifically, suppose command can take stdin input and a filename as command line argument, and ...
14
votes
4answers
1k views
Process substitution and pipe
I was wondering how to understand the following:
Piping the stdout of a command into the stdin of another is a powerful
technique. But, what if you need to pipe the stdout of multiple
...
2
votes
3answers
198 views
Output exceeding terminal window width
I had run a program that resulted in many more lines of output than my current terminal window width. As a result, I could only see partial results...is there any way to get the full output?
I am ...
5
votes
1answer
1k views
Why does redirection (>) not work sometimes but appending (>>) does?
While studying for the RHCE, I came across a situation where stdin redirection does not work in bash:
# file /tmp/users.txt
/tmp/users.txt: cannot open `/tmp/users.txt' (No such file or directory)
...
2
votes
4answers
149 views
append string where it belongs in sorted file
Suppose I have a sorted file, named sorted.txt, like this:
beautiful
easy
fast
functional
handy
Now, doing echo fine-grained >> sorted.txt will put "fine-grained" at the end of the file, ...
0
votes
1answer
182 views
Is 'some_program <some_file' faster than 'cat some_file | some_program'? [duplicate]
Possible Duplicate:
Should I care about unnecessary cats?
Both would be functionally equivalent, but when using cat wouldn't it be slower because you have a process first reading the file ...
3
votes
2answers
705 views
Why is piped input okay to zenity, but <file malfunctions?
My question is as simple as what the zenity --text args say in the example... but what is causing this 100% CPU grab by the redirection?
...(and by the way, is this particular usage of < actually ...
5
votes
3answers
1k views
How to get file descriptor other than stdin stdout and stderr (to do something like $ program 1>file_1 3>file_2)?
When an executable produces an output I prefer to let the executable print the output to stdout in order to redirect them in a file as well to pipe them to another command.
Let suppose that an ...
-1
votes
2answers
333 views
Copying a few lines from stdout to stderr - but only if stderr is different from stdout
I have a bash script "backup.sh", which prints out everything to stdout, including all the files that are transferred during backup.
I'd like to make it possible to keep that full output, but when ...
5
votes
2answers
495 views
redirection and pipeline
I was wondering about differences and relation between redirection and pipeline.
Is pipeline only used to connect
stdout output of a command to stdin
input of another command?
Is redirection only ...
5
votes
2answers
86 views
understand a sequence of redirections
If several redirections are used together, does changing their order make difference?
How shall one understand the meaning of their order? Is the chained channel of redirections built as reading the ...
4
votes
4answers
126 views
Make mistakenly thinks rule succeeded because of 0-sized file generated by output redirect
In a makefile, I have several rules that look like this:
out.txt: foo.sh input.txt
./foo.sh -i input.txt > out.txt
If foo.sh fails, then out.txt will be created as a 0-sized file. If I run ...
6
votes
1answer
6k views
Bash: assign ls | grep to a variable and echo it with a string
I want to assign the result of an expression to a variable and concatenate it with a string, then echo it. Here's what I've got:
#!/bin/bash
cd ~/Desktop;
thefile= ls -t -U | grep -m 1 "Screen Shot";
...
5
votes
2answers
1k views
Howto create a permanent client connection with netcat?
I'm writing a bash script that constantly read a folder in a loop to send data to a server at a defined time interval. I'm using netcat as the tool to connect to the server and send the data. My ...
6
votes
5answers
311 views
IO redirection and the head command
I was trying to quickly edit an .hgignore file from the Cygwin bash shell today, and I added a line that was a mistake. I'm not sure if this was the best way to do it, but I quickly thought of using ...
7
votes
2answers
1k views
See the STDOUT redirect of a running process
If I start an app with this command:
/path/to/my/command >> /var/log/command.log
And the command doesn't return, is there a way, from another prompt, to see what the STDOUT redirect is set ...
6
votes
2answers
361 views
How to detect if input is from argument, file or terminal
In bash, is there a way to know if a given script has been invoked with:
$ myscript.sh myfile
or:
$ myscript.sh < myfile
Inside some scripts I always have accessed the contents of myfile with ...
5
votes
4answers
4k views
view stdout for another pts
Here is the situation. I left my pc at home doing an rsync from a 2TB hard drive to another 2TB hard drive (it's going to take a while since they are both USB 2.0). I am now at work and I have ssh-ed ...
4
votes
3answers
310 views
script to use the output of a command (ls) and use it in another command
I have a collection of pdf files I would like to convert to epub. I know Calibre's command ebook-convert will do the trick (nicely might I add). However
I have more than one file.
I'd like to be able ...
1
vote
1answer
293 views
Which process/program create/write the file which I/O is redirected to?
When learning SELinux, I executed semanage fcontext -l > fcontext.txt under /root directory to dump massive fcontext information to a file. The funny result is: fcontext.txt was created, but the ...
7
votes
2answers
643 views
Precedence of stdin and stdout redirection in Bash
My question is about redirection precedence is bash. Suppose you have a command:
cmd1 < cmd2 > cmd3
Would it translate to:
(cmd1 < cmd2) > cmd3
Or
cmd1 < (cmd2 > cmd3)
6
votes
1answer
3k views
File descriptors & shell scripting
I am having a very hard time understanding how does one use file descriptors in shell scripts.
I know the basics such as
exec 5 > /tmp/foo
So fd 5 is attached to foo for writing.
exec 6 < ...
0
votes
1answer
556 views
Unix > overwrite command?
I'm doing a shell command (such as sh run.sh > log.txt). How do you overwrite the file each time (so each time I run it log.txt doesn't get appended)
I'm doing this in a python script and I'm ...
5
votes
2answers
702 views
Use HERE file and redirect output of command
I have the following code in a batch script:
mpirun -np 6 ./laplace <<END
100
100
100
0.01
100
3
2
1
END
| tail -n 1 > output
But it isn't working. What I want it to do is to use the HERE ...
3
votes
2answers
3k views
Output progess of the scp/sftp command to both standard out and a file on linux server
I am writing a release script, which uses scp/sftp to get the the file from a remote server, we want to log the output of this script to a release.log file as well. I am using "tee" to achieve this, ...
1
vote
2answers
388 views
writing a command transcript to file
Here is a script from Mercurial issue 2743. Call it mq.sh. I'm trying to get it to do the following things, on Debian squeeze.
Echo commands + standard output +
standard error to a file.
Prefix with ...
3
votes
1answer
550 views
using system command in awk script
In an AWK script I am using a command
system(date)
to print the current date in a file but after this command is executed next line is also added implicitly. Is there any way in AWK to print ...
6
votes
3answers
1k views
How do i open all files that are the result of a ls command?
I'd like to open all text files that are the result of a ls command using a text editor. How do i do this?
10
votes
2answers
1k views
How to diff a file and output from the command?
Normally you would write:
diff file1 file2
But I would like to diff a file and output from the command (here I make command a trivial one):
diff file1 <(cat file2 | sort)
Ok, this work when I ...
13
votes
2answers
4k views
How can I make iconv replace the input file with the converted output?
I have a bash script which enumerates through every *.php file in a directory and applies iconv to it. This gets output in STDOUT.
Since adding the -o parameter ( in my experience ) actually writes ...
11
votes
5answers
5k views
Show only stderr on screen but write both stdout and stderr to file
How can I use BASH magic to achieve this?
I want to only see stderr output on the screen,
but I want both stdout and stderr to be written to a file.
Clarification:
I want both stdout and stderr to ...
19
votes
5answers
6k views
How can I create a /dev/null-like “blackhole” directory?
I would like to create a "/dev/null" directory (or a "blackhole" directory) such that any files written to it are not really written, but just disappear.
I have an application that writes out large ...
17
votes
10answers
4k views
How do I reuse the last output from the command line?
This is a noob question, but I'd like to know how to reuse the last output from the console, ie:
pv-3:method Xavier$ python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
...
1
vote
1answer
374 views
Splitting stdin to different outputs in bash [duplicate]
Possible Duplicate:
Is there a way in bash to redirect output and still have it go to stdout?
How would I send /dev/stdin to both /dev/stdout and a $logfile in one command?
One solution ...
5
votes
2answers
2k views
Write to a file without redirection?
I am writing a regular compiled application that needs to create a special file and write a magic cookie into it. I can’t write the file directly from the application, the system security model ...
