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
25 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
3answers
25 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. ...
1
vote
2answers
48 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
37 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 ...
6
votes
3answers
499 views

Dash equivalent of self-redirection of script output

In Bash you can redirect all future stdout output of the currently running script. For example with this script, exec > >(logger -t my-awesome-script) echo 1 echo 2 echo 3 This will end up in ...
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
2answers
1k views

What stream does perf use?

What stream does the perf command use!? I've been trying to capture it with (perf stat -x, -ecache-misses ./a.out>/dev/null) 2> results following http://stackoverflow.com/q/13232889/50305, ...
3
votes
1answer
36 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. ...
2
votes
2answers
6k views

What's the difference between STDIN and arguments passed to command?

I could use the either form to execute the cat method: cat file_name cat < file_name The result is the same Then I want to execute man in the format of stdin man < file_name While ...
15
votes
5answers
732 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 ...
1
vote
3answers
54 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 ...
20
votes
4answers
5k 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 ...
1
vote
3answers
53 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 ...
3
votes
2answers
550 views

zsh: Disable “file exists:” warning with redirection

How can I override the file exists: warning from zsh? > echo > newfile.txt > echo > newfile.txt zsh: file exists: newfile.txt In these cases I prefer my shell to not complain and ...
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 ...
0
votes
1answer
16 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 ...
39
votes
5answers
46k views

Using while loop to ssh to multiple servers

I have a file servers.txt, with list of servers: server1.mydomain.com server2.mydomain.com server3.mydomain.com when I read the file line by line with while and echo each line, all works as ...
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 ...
11
votes
2answers
2k views

Suppress output unless non-zero exit code

What's the best way to suppress output (stdout and stderr) unless the program exits with a non-zero code? I'm thinking: quiet_success() { file=$(mktemp) if ! ( "$@" > "$file" 2>&1 ); ...
7
votes
2answers
140 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 ...
4
votes
1answer
763 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
5
votes
2answers
45 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
2answers
32 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 ...
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
45 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
55 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
38 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` > ...
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, ...
1
vote
1answer
27 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 ~ ...
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
19 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
56 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
52 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: ...
6
votes
3answers
286 views

Silent GnuPG password request with bash commands

I'm trying to hide the "output" of a gnupg command, but it seems that it is always printed. the command is: echo "thisprogramwørks" | gpg -q --status-fd 1 --no-use-agent --sign --local-user D30BDF86 ...
0
votes
1answer
38 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
50 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 ...
49
votes
4answers
31k views

How to redirect output of wget as input to unzip?

I have to download a file from this link. The file download is a zip file which I will have to unzip in the current folder. Normally, I would download it first, then run the unzip command. $ wget ...
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
142 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?
26
votes
4answers
38k views

How to view the output of a running process in another bash session?

I have left a script running on a remote machine from when I was locally working at it. I can connect over SSH to the machine as the same user and see the script running in ps. $ ps aux | grep ...
3
votes
1answer
54 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 ...
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 ...
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 ...
1
vote
2answers
248 views

fuser output looks ambiguous

I am using fuser the output is like this: $ fuser / /: 1354rc 1362r 1370rc 1371rc 1395rc 1399rc 1403rc 1410rc 1414rc 1428r 1451rc 1458rc 1470rc 1472rc 1477rc 1480rc ...
9
votes
2answers
4k views

Restoring output to the terminal after having issued “exec &>filename”

I am trying to execute the following: exec &>filename After this I am not able to see anything including what I typed, alright. I frantically try , exec 1>&1 and exec 2>&2 , ...
41
votes
2answers
36k 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 ...
0
votes
1answer
55 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 ...