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

learn more… | top users | synonyms (1)

0
votes
2answers
43 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
48 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
26 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
19 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
30 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
26 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
51 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
40 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
83 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
37 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
55 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
55 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
18 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
45 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
744 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
144 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
32 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
34 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
47 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
41 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
48 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
58 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
15 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
88 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
39 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
29 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 ~ ...
31
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
43 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
20 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 ...
4
votes
2answers
57 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
55 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
39 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
52 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
34 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
145 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
55 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
56 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
57 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
117 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
29 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
75 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
73 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
81 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
517 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
54 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
2answers
51 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
55 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
371 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 ...