Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [io-redirection]

I/O redirection is used in shell scripting. This feature enables to take the output of a command and redirect it as an input for another command. Or command can take the input from a file instead of the keyboard. The whole process helps connect commands in various ways.

0
votes
2answers
93 views

What happens when redirecting with 3>&1 1>/dev/null?

I'm playing around with file descriptors to better grok them and I'm failing to understand the following. $ grep "..." 3>&1 1>/dev/null 1 12 13 123 321 3 The above does not show in the ...
0
votes
1answer
32 views

Redirecting to both screen and file

I'd like to redirect all of the output of the commands I ran to a file, in addition to having them printed on the screen. I want this to happen automatically, I don't want to pipe into tee everytime ...
25
votes
3answers
1k views

Is it safe to redirect stdout and stderr to the same file without file descriptor copies?

I start off in empty directory. $ touch aFile $ ls aFile Then I ls two arguments, one of which isn't in this directory. I redirect both output streams to a file named output. I use >> in order ...
28
votes
5answers
2k views

How to redirect stdout to a file, and stdout+stderr to another one?

How can I achieve cmd >> file1 2>&1 1>>file2 That is, the stdout and stderr should redirect to one file (file1) and only stdout (file2) should redirect to another (both in append ...
2
votes
1answer
33 views

Difference between Piping and Reading Input

What is the difference between cmd1 > tmp && cmd2 < tmp and cmd1 | cmd2, besides the creation of a tmp file (obviously) ? If my comprehension of pipe is right, I expect cmd2 to read ...
4
votes
1answer
199 views

stdout and stderr redirection to different files

How can I redirect stdout to 2 different files and stderr to another, different file? I want something like <my_cmd> 1> file1 file2 2>file3 I know: <my_cmd> | tee file1 file2 > /...
1
vote
2answers
28 views

Non-Root User SSH Privileged Command with File Piping

I have an a SSH server where root login is disabled. I'm hoping to run a privileged command that will want input from a file I have after being executed. I'm hoping to do all without user interaction ...
0
votes
1answer
33 views

How to send stdin to while loop using redirection operator

Not sure if I used the right words in the title, I am trying to do this: while read line; do echo "$line" exit; done; <( echo "foo\n"; exit ) but it hangs, I don't think the while loop ...
2
votes
1answer
31 views

Open output of a command using libreoffice

I am running certain commands in a loop and would like to open its output in libreoffice (calc), without storing it. This is what I have tried: libreoffice --calc <(process m n) libreoffice --...
2
votes
2answers
71 views

Difference between `touch file` and `>file`

Say there is an empty directory and I run the commands >file1 and touch file2 while in that directory, but I forget which command created which file. I don't know what command I ran first and I ...
1
vote
1answer
37 views

File Descriptors and Redirection

Several resources state the file descriptor 0 is connected to the keyboard. I have learned that echo does not receive input from stdin (or 0). This feels contradictory to me. When I run echo foo I'm ...
3
votes
1answer
53 views

Exit status of command in pipeline

I have come across this code but cannot understand exec >&p edit 1 to my understanding : #! /usr/bin/ksh exec 4>&1 ## standard output is first saved as file descriptor 4 ...
1
vote
2answers
30 views

Capture git output into variable

If I run a command in a subshell, I can collect the stdout into a variable, such as: var=$(echo 'hello world') echo $var Will print 'hello world' as expected. If I add colour and a new line, this ...
-2
votes
1answer
31 views

Allow redirection for a user [duplicate]

I'm going to permit redirections ">>" and ">" for the www-data user in sudoers but I can't find this.
2
votes
2answers
57 views

What's the POSIX specification on behavior of built-in commands with redirections and/or piping?

Consider the following commands: exit > /dev/null exit | cat On a few shells (ksh, bash, (d)ash), the behavior is the same: The first command causes the shell to quit immediately, while the ...
1
vote
0answers
23 views

Redirecting input from cron job [duplicate]

I'm using a plugin manager for vim (vim-plug), and have a cron job to perform updates: vim +PlugUpgrade +qall &>/dev/null; vim +PlugUpdate +qall &>/dev/null This job occasionally ...
0
votes
0answers
20 views

Redirection vs Process substitution: `echo foo | bar` vs `bar <( echo foo)` [duplicate]

What is the difference between these two constructs, echo foo | bar bar <( echo foo ) I thought both of them would set up STDIN the same way. However, that seems to not be the case for me (exact ...
0
votes
1answer
46 views

sed command working only when no outfile is written

I'd like to change this file eq.txt 2018-05-03T18:46:05.050Z 11.8314 44.0586 10 4.3 USGS 2018-05-01T05:16:59.270Z 11.0366 43.2334 10 4.1 USGS 2018-04-26T11:13:20.590Z -5.4109 36.5557 10 4 USGS 2018-...
0
votes
1answer
34 views

Split ssldump output into multiple files for every incoming connection

I am capturing SSL Handshake data using ssldump on the terminal, and using the command sudo ssldump -i enp0s8 -a -A -H -n -x > new_trace to output it into a single file. Currently, the output ...
1
vote
0answers
39 views

Shell redirection - follow name, not a descriptor

I have a shell script that is run in the background and the only thing it does is run 1 command, STDOUT of which is being appended to a file. my_blocking_command >> my_file I want to stop the ...
0
votes
1answer
36 views

How can I store output in bash variable and suppress output to stderr and stdout? [duplicate]

If i'm doing oidvalue=$(snmpget -v 2c -c public localhost 1234) This will store the output of that command in oidvalue, however as it is now, it will print some error to the screen. How can I ...
5
votes
1answer
121 views

Process substitution and redirection using tee

Suppose that you redirect, in bash, the standard output of a command cmd to a file named f.out, and the standard error to f.err, using tee to preserve console printing: cmd 1> >(tee f.out) 2>...
0
votes
0answers
43 views

Storing output in variable for redirection [duplicate]

My question is about the application of redirecting output and input. I have a text file that contains 30 or so trackers. I have a torrent file I'd like to add the trackers to. transmission-edit is ...
3
votes
2answers
60 views

Output redirection is not working with top piped to grep

When I run this command in Linux: $ top -b -d 20 | grep "load average" -A 20 > top.log top.log is always empty. But when I run this command: $ top -b -d 20 | grep "load average" -A 20 | tee top....
1
vote
2answers
42 views

Partial Redirection with additional Piping

There's an auto generated file on a remote location that is constantly changing, I can only view the remote file via ssh user@ip cat luckyNumbers it tells me today's lucky numbers and also passes ...
1
vote
0answers
61 views

Log python http server output to file

I want to start a python webserver in the background and log all of its output to file. Instead the the servers output appears in the terminal. Even tho i guess this is pretty basic ... I've got no ...
2
votes
1answer
50 views

redirect awk exec results to another folder [duplicate]

Trying to capitalize the content of the files that match the filename pattern "_base.txt"; then output the results to another folder with the original filename plus the "_cap.txt" in the end. I plan ...
2
votes
1answer
67 views

concurrent processing in bash using process expansion, and redirection

Apart from possible races that have to be controlled by using proper synchronisation, it's possible in bash to feed a data source concurrently into multiple pipelines and collect all their outputs ...
2
votes
1answer
65 views

Redirect standard error of one command to standard input of another command

I wish to redirect standard error of one command to standard input of another command like g++ filename.cpp 'redirection' less
0
votes
1answer
44 views

“nohup cat” — write the complete content to the log file rather to concatenate file

I used the below command nohup cat fastp-filtered/OZBenth*_R1.fastp.fq.gz > fastp-filtered-merged4racon/merge_R1.fq.gz > merge_R1.out.log 2>&1 & but unfortunately, the output went ...
0
votes
2answers
26 views

Overwrite file with stdoutput from cron execution

I have this cron in my crontab 00 01 * * * /srv/python/proj/acquisizione/acquisizioneAOK.sh >> /home/crontab_logs/acquisizioneAOK.out 2>&1; mailx -s "Cron output: acquisizioneAOK" ...
0
votes
1answer
44 views

Permanently redirect stderr to stdout

I have a bash script with many commands, some of which might generate error messages. often, the error messages and output messages are mixed in an apparently incorrect order (for example, I see the ...
0
votes
0answers
34 views

send hex as characters to output to remote end

I'm doing a project for a microcontroller that involves sending and receiving special (non-printable character) data through its serial port. I found myself a simulator (ucsim) so I can test things ...
0
votes
0answers
23 views

save input and output data has passed in adb

i want save all input and output commands has executed in adbd I tried to pull adbd file in sbin folder and extract it to modify and Implement of the idea to write a few lines for create file and do ...
0
votes
2answers
24 views

Showkey with timestamp

How can I record keyboard actions with the timestamp, either to console, or preferably to a file? I have showkey output like: keycode 28 release keycode 30 press keycode 30 release keycode 48 ...
3
votes
1answer
219 views

How to use variables inside back-quotes

I have a bash script that accepts a parameter "$input" and (among other things) directs it into a program and collects the output. Currently my line is: OUTPUT=`./main.exe < $input` But I get ...
0
votes
1answer
79 views

Remote overwrite crontab file with sudo

I'm trying to build a script that automatically takes a file on the remote server and replace with crontab file, but I get permission denied. My idea is to create a shell function for it: ...
0
votes
0answers
63 views

Redirecting input bash

I have a program, that runs on only one Raspberry Pi, but could be run from multiple other computers (through SSH). When I run my program on the Pi, it runs as expected. To be able to run from crontab ...
5
votes
1answer
822 views

What's going on with this dash '-' thing?

I was trying to export the Python environment requirements and this is what I intended to do: conda list -e > requirements.txt However I mistakenly typed this instead: conda list -e -> ...
0
votes
2answers
74 views

How could I know inside a script if stdout has been redirected for it?

I have a script in ksh; depending whether there is a redirection from the command line, I redirect the output via a exec 1>file. How can I test from inside the script itself if the command calling ...
0
votes
2answers
212 views

Nohup: Redirect stderr to file and dismiss stdout

Per default, nohup writes stdout to nohup.out and dismisses stderr. I would like to have it the other way around: write stderr to a file and dismiss stdout.
0
votes
1answer
57 views

redirect created files in a directory from command line

I was wondering if there is any way to redirect created files from a .sh script to a specific directory without modifying the script itself but straight from command line. Let's say: I've a script ...
2
votes
1answer
113 views

Redirect script output both to console and to log

Take a look on the following # more /tmp/myscript #!/bin/bash echo I AM echo BIG GUY echo AND ALSO SMART # bash /tmp/myscript | tee -a >/tmp/log why we not get the output from echo in the ...
3
votes
4answers
181 views

Why does `… | sed 's/^/stdout: /'` print on empty stdin when `… > >(sed 's/^/stdout: /')` doesn't?

I'm trying to understand what causes the difference in these 2 constructs that I thought were functionally equivalent: $ ( echo foo >&2 ) 2> >(sed 's/^/stderr: /') | sed 's/^/stdout: /' ...
0
votes
1answer
49 views

Spaces after io redirection operator? [duplicate]

I've noticed that when writing a shell script, there's a lot of inconsistency in whether people put a space after the I/O redirection operators. For example: foo >bar.txt Will work, but so will ...
-1
votes
3answers
47 views

Oneliner for outputting to file only if string is matched (bash)?

I am making a script where I curl a URL and output to a file like this: curl http://example.com/$1 > $1 Is there any way to make it dismiss anything that doesn't include, say <head>? I ...
21
votes
3answers
2k views

How does this script ensure that only one instance of itself is running?

On 19 Aug 2013, Randal L. Schwartz posted this shell script, which was intended to ensure, on Linux, "that only one instance of [the] script is running, without race conditions or having to clean up ...
1
vote
2answers
177 views

Run parallel command and redirect the output to files with specific name

I can't undestand well how the parallel command works. I need to run this simple command: (100 times) curl https://jsonplaceholder.typicode.com/todos/1 curl https://jsonplaceholder.typicode.com/...
5
votes
3answers
249 views

Portable way to invoke tar with a list of files from stdin

I want to create a .tgz from the content of a directory. I also want to strip the leading "./" from the tar'ed content. I had done this as follows: cd /path/to/files/ && find . -type f | cut -...
2
votes
1answer
21 views

Ambigious redirect error on different volumes with mysql

i want to import a database with mysql (running with MAMP): #! /bin/bash # variables currdir=$PWD dbname=TEST dbuser=root dbpass=root dbpath="/applications/MAMP/Library/bin" exname=database if [ "$1"...