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

Possible redirection bug in zsh 5x

[This post's title needs some work; suggestions welcome.] The following command produces different outputs in zsh v. 4.x and 5.x: { ( printf "X\nY\n" printf "WARNING: foo\nWARNING: bar\n"...
1
vote
2answers
74 views

shell stderr to /dev/null

I have PID file and I want to get PID number so this is what I am doing. [root@linux ~]# PID=`cat /usr/local/foo/var/run/foo.pid` [root@linux ~]# echo $PID 3414 sometimes this file doesn't ...
0
votes
2answers
200 views

Why we need to have 2>&1 in /dev/null 2>&1?

I saw in linux script there was a command argument > /dev/null 2>&1, I know it is to redirect the output to null, means silencing it. I also know about the numbering for 0,1,2 (STDIN, STDOUT,...
0
votes
0answers
18 views

Redirect stderr to stdout and tee to file and check return value [duplicate]

I know how to redirect stderr and stdout to a file: curl -sSo file http://foo.bar >> log 2>&1 I know how to get stdout to appear on the console and in a file: curl -sSo file http://...
0
votes
2answers
36 views

Output pings with time greater than 100ms to file with a timestamp appended

I want to save in a file every ping with a time greater than 100ms and append a timestamp to every line. Searching I have managed to get this: ping HOST | grep --line-buffered "time=[0-9][0-9][0-9]" ...
6
votes
3answers
685 views

Does the shell fork when I use built-in commands?

When I run the command type type, this gives me a result to standard output. So, now I try this command: type type > abc.txt It redirects the standard output to abc.txt. So, if this command ...
0
votes
1answer
37 views

using command line arguement with redirecting

#include <fcntl.h> #include <stdio.h> #include <stdlib.h> int main(int argc, char** argv) { int val; if(argc!=2) { printf("Usage: %s <...
-1
votes
2answers
48 views

Is the delimiter in here document seen and used by the program which takes it as input?

The format of here-documents is: <<[−]word here-document delimiter Is the delimiter seen and used by the program which takes the here document as stdin input? Or is the delimiter used by the ...
3
votes
2answers
142 views

Order between `nohup`, `&` and redirection?

What is the correct order between nohup, & and redirection, when using together? Why are other orders not correct? For example, $ nohup firefox& &> /dev/null $ nohup firefox &&...
3
votes
1answer
134 views

Stdin input to a command with nohup

from http://www.gnu.org/software/coreutils/manual/html_node/nohup-invocation.html nohup runs the given command with hangup signals ignored, so that the command can continue running in the ...
0
votes
2answers
81 views

bash: tee eats newlines after exec

To output both stdout and stderr from a script to the console and to a log file, I’ve found a beautiful solution with tee: exec &> >(tee log.file) The problem is, that sometimes tee seems ...
2
votes
3answers
46 views

Script output depending on parameter

I have script that prints out few lines of text. This text is used as configuration by other process. When I normally run program I redirect standard output to file which is fine: ./generateConfig....
7
votes
1answer
326 views

How can I pipe only stderr in zsh?

In bash: $ echo hi 2>&1 1>/dev/null | cat $ While in zsh: $ echo hi 2>&1 1>/dev/null | cat hi $ Is there a way to pipe only standard error while redirecting standard out?
1
vote
1answer
38 views

trap echo does print not write to console when writing to file

When I terminate "CTRL+C" the following script #!/bin/bash function waa(){ for i in {1..10} do echo "start.sh: sleeping $i" sleep 1s done } trap "echo 'GAGA'" TERM waa >&...
2
votes
1answer
58 views

Two input pipes through file descriptor shuffling and /dev/fd

I want to pipe two programs into one. If my shell supports it, I can use Process substitution. For example, to list the common lines of two files in indifferent order, I can use comm -12 <(sort a) ...
0
votes
2answers
310 views

Bash - Redirect output to a variable or file descriptor, then read from the variable or file descriptor

Here's an example of a bash script that redirects all output to a file (and shows output on the screen too): # writing to it exec > >(tee --ignore-interrupts ./log) exec 2>&1 echo "here ...
1
vote
1answer
122 views

patch: “bad file descriptor” in combination with pipe and LD_PRELOAD/ libtrash

Very short summary: cat "$file" | patch produces a Bad file descriptor-error, but patch < "$file" works, when libtrash is preloaded with LD_PRELOAD, and only on bigger projects. Description: For ...
1
vote
1answer
43 views

How to get file descriptor number of a output and how to redirect all of them at once

Lets take this command for example $ time ssh ec2 ls www apps real 0m0.554s user 0m0.004s sys 0m0.000s $ time ssh ec2 ls 1>/dev/null real 0m0.554s user 0m0.004s sys 0m0.000s $...
1
vote
2answers
28 views

Trying to direct variable contents into command gives Ambigious Redirect

I'm trying to write a script which tests the http response from various Node servers I have running and which then emails me if any respond with a 502 error from Nginx (meaning one or more server has ...
1
vote
3answers
36 views

How do I organize and cut this portion of a directory into a file?

I'm new to unix and I'm not sure how to name my title but my main objective is to copy the contents of a directory and send it to a file. Then cut out the directory location to just have the name. ...
4
votes
1answer
31 views

Prevent customized bash autocomplete from affecting io redirection (< and >)

I've used complete -W 'firstdatabase databasetwo etc' mysql to save a list of databases, so that I can autocomplete them using the mysql command. However, in many cases I would type mysql db < /...
1
vote
2answers
97 views

Unable to run a process on background

I need help with a Solaris system. I have used the following command to run the cp.sh script in the background. nohup sh cp.sh < /dev/null & > /dev/null & output: Invalid null ...
1
vote
2answers
158 views

Copy output of curl to file

I'm running raspbian and using this bash script to take a photo every minute and upload it to my FTP server: #!/bin/bash while [ 1 ]; do DATE=$(date +"%Y-%m-%d_%H_%M_%S") raspistill -q 10 -th none ...
2
votes
1answer
95 views

What kind of redirection is >>&?

I'm looking at a cron file that has the following line: 35 0 * * * /bin/csh -c "/home/abc/.cshrc;/home/abc/appTools/bin/xxx.pl >>& /home/abc/appTools/log/xxx.cronlog" Is this another ...
3
votes
1answer
40 views

How do I turn off redirection once I've turned it on? [duplicate]

I found a great solution at Redirect all subsequent commands' stderr using exec. I used the example: exec > >(tee $somelog) 2>&1 ...and managed to get everything to tee great. Now,...
1
vote
3answers
217 views

How to exclude the output file from ls output

Let's say I have these files on desktop: aaa.jpg bbb.jpg I want to list these two jpg's and output them to a .txt file: #!/bin/bash cd ~/Desktop ls -1 > all.txt With this code the all....
2
votes
2answers
24 views

exclude target redirection file from being processed in for loop

This will cause LIST to grow very large (even a couple of GB in a short time etc): $ for i in *; do echo $i; cut -d ' ' -f1 $i ; done > LIST For example, after 10 seconds: $ wc -l LIST ...
1
vote
3answers
75 views

Can I redirect the output of a program to cat with a pipe?

I have a folder with three files and basic contents: $ tail * ==> file1 <== file 1 contents ==> file2 <== file 2 contents ==> file3 <== file 3 contents I would like to see the ...
0
votes
1answer
38 views

TCSH: I want to display command output and redirect to a file

I looked at the TSCH man page, which said "Either output-file or error-file may be '/dev/tty' to send output to the terminal." So if I can redirect to two different locations, that would work. But ...
3
votes
2answers
63 views

How to write a “compose” function of bash pipelines with named pipes

This page details psuedocode for creating a compose function that takes n commands and executes them in a pipeline: We program a command compose such that compose cmd1 cmd2 ... cmdn behaves ...
16
votes
5answers
810 views

Write output of `time` in a file, why are parentheses needed?

time writes to stderr, so one would assume that adding 2>&1 to the command line should route its output to stdout. But this does not work: test@debian:~$ cat file one two three four test@...
7
votes
2answers
345 views

Redirecting standard error output to bash variable

Here's a C code snippet that will cause segfault: // segfault.c #include <string.h> int main() { memset((char *)0x0, 1, 100); return 1; } Compile it with: gcc segfault.c -o ...
3
votes
1answer
61 views

Opening more than 10 file descriptors with ksh

The shell syntax for opening a file for writing and using its file descriptor is: exec 3>output.log With bash and zsh you also can write: exec 13>output.log Thus, later in your script you ...
0
votes
2answers
70 views

How can I copy the output of a command in the terminal to my clipboard? [duplicate]

I have a script that operates on enormous files and outputs an enormous amount of content (almost 7000 lines). I need to copy the output of this to my clipboard so I can then paste it into paste2.org ...
5
votes
2answers
72 views

Understanding i/o redirection in the context of _process substitution_

Running GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu). I don't really understand process substitution (ProcSub) from the perspective of a user interested in lifting the hood on i/o ...
0
votes
1answer
52 views

Some errors are not logged, after redirecting both stderr and stdout to a file

In a Linux server, I run a program and log its stdout and stderr outputs to a file by: myprogram.py > logfile 2>&1 All the outputs to stdout and stderr are logged, except that some errors ...
1
vote
2answers
140 views

Understanding redirected if-statement in bash

if [ -z "$OPTION" ] # if option is not given(empty) then: then command1 --defaultOption else command1 $OPTION fi \ 2> >( function1 "$DETAILS" ) \ < <( command2 ...
0
votes
2answers
98 views

echo $variable > file in a loop outputs only the last value of variable

Here's what I'm trying to do: I have several git repos. I want to setup a push-to-deploy script for each of them. being so lazy to do that for each and every repo, I wanted to script it. My script ...
0
votes
1answer
19 views

GDB - Call second program

I have a program which I want to debug gdb. And I want to call a second program to redirect the output to the first program. How this is done in gdb. I tried it like that: run -2 < $(python ...
2
votes
1answer
98 views

is linux redirect “>>” slower with bigger files?

I have a shell script which makes some analysis and prepares (i.e.: writes) some commands to run in a separated file. So I have something like that: echo my_command_to_run >> /tmp/...
1
vote
1answer
64 views

Bash : ambiguous redirect

I am trying to collect dump of java process with jstack and I have tried below command. But its saying ambiguous redirect as I cant redirect to a command. jstack -l `pgrep java` > /tmp/TD_`...
1
vote
1answer
47 views

Find files and send to a temp file

Vim does support a nice option to accept a file with list of files that are then opened in a Quickfix list. Rough example, I find all files in ~ that are smaller than 1KB and pass this to Vim: find ~ ...
32
votes
7answers
3k views

Is it a UUOC (useless use of cat) to redirect one file to another?

If I want to make the contents of file2 match the contents of file1, I could obviously just run cp file1 file2. However, if I want to preserve everything about file2 except the contents—owner, ...
0
votes
1answer
91 views

Run git command to save output but consume STDERR too

I've tried: status=$(git status -s ./$name>&1) status=$(git status -s ./$name >2 /dev/null >&1) status=$(git status -s ./$name >2 /dev/null) status=$(git status -s ./$name > /...
0
votes
1answer
26 views

How to redirect output of cowsay to be the input of zwrite

I run cowsay, which asks me to input text string. Then, it prints the result to stdout. I want to redirect that result to zwrite instead of stdout. The issue is that I can't do cowsay | zwrite ...
3
votes
2answers
64 views

Do redirections operate on file descriptors or file handles?

From https://www.gnu.org/s/bash/manual/html_node/Redirections.html Before a command is executed, its input and output may be redirected using a special notation interpreted by the shell. ...
3
votes
1answer
76 views

Duplication of file descriptors in redirection

From https://www.gnu.org/software/bash/manual/html_node/Redirections.html Bash handles several filenames specially when they are used in redirections, as described in the following table: /...
0
votes
1answer
60 views

Starting job via SSH and detaching from a composite command

I'd like to start a long running script via SSH and immediately return. Afterwards, I want to check the remote host every 5 minutes to see if the job is done. In order to accomplish the first part, I ...
1
vote
1answer
89 views

How to read from stdin in process substitution? [duplicate]

I would like to send stdout to multiple commands, however I'm not sure how do I read from standard input within process substitution? My attempts: $ echo foo >(cat /dev/stdin) >(cat /dev/stdin)...
0
votes
1answer
48 views

Why cron not outputting to file? [duplicate]

I scheduled a cron task: 0 */10 * * * aapa bash /home/aapa/scripts/es_backup.sh &>> /var/log/super/es_backup.log It is running as logged into syslog: Dec 4 08:17:01 dexter CRON[15552]: (...