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
24 views

redirect output from interface?

I am echoing an AT command to a modem interface (/dev/ttyUSB3) and the command runs successfully. For instance the below command works and has an output of OK: echo -e "ATZ\r" > /dev/ttyUSB3 I ...
0
votes
1answer
39 views

“Sudo” prefixed command doesn't work; without sudo does.

I suspect this has been answered before, but I don't know what this is called, so I can't really search for it. How come this works : $ grep H=p <(udevadm info /dev/ttyUSB0) E: ...
4
votes
2answers
160 views

Appending works without >> when redirecting standard output and error

I have a file test.txt and have no file named test. When I tried ls test test.txt > new 2>new I was expecting new to be overwritten since >> is not used. But in the output file I got ...
1
vote
1answer
35 views

Correct syntax to avoid bash 'ambiguous redirect' message

I am trying to execute a command which accumulates stdout into an existing file and sends the error messages to another using the command below. commmand >> /home/user/accumulate_output.log ...
1
vote
2answers
62 views

Multiple File Redirection with awk and find

I have some files in a directory. And I want to add some lines at top and end of file using awk. Example: My awk command: awk 'BEGIN { print "line1\nline2" } { print $0 } END { print "line3\nline4" ...
1
vote
1answer
76 views

Redirection. What is “<>”, “<&” and “>&-”?

"<>" This operator I saw few months ago on the one site, but I don't remember what does it mean. Maybe I'm wrong and ksh has no "<>". "a<&b" I know that this operator merge input stream ...
4
votes
1answer
63 views

Change the status of the keyboard leds, from within an X session, without root access

I am trying to force the capslock led on. xset does not work for me, so I am trying to use setleds. In a graphical console, this command returns: > LANG=C setleds -L +caps KDGKBLED: Inappropriate ...
3
votes
1answer
77 views

How do I come by this pty and what can I do with it?

It seems that a simple shell redirect from /dev/ptmx gets me a new pseudo-terminal. $ ls /dev/pts; ls /dev/pts </dev/ptmx 0 1 2 ptmx 0 1 2 3 ptmx It disappears as soon as the process that ...
3
votes
5answers
236 views

Awk - output the second line of a number of .dat files to one file

I have searched through previously asked questions and can't find an answer to what I am trying to do. note, I am new to linux. I have multiple files something like: (in reality i have 80) file1.dat ...
13
votes
6answers
1k views

Is there another simple way to append line to end of file other than `>>`?

Recently I'm echoing short sentences to a tree_hole file. I was using echo 'something' >> tree_hole to do this job. But I was always worried of what if I mis-input of > instead of >>, ...
0
votes
0answers
13 views

Using `perf` repeatedly with file input

perf can be used to analyze the performance of a program. Say you want to test the performance of a program prgrm, with input from a file, you can run: perf stat prgrm < inp.dat Now when you ...
1
vote
1answer
41 views

Output Redirection

I am using the tee command to output the compilation errors of a program into a file along with the terminal. gcc hello.c | tee file.txt This is the command I have used. The compilation errors are ...
6
votes
2answers
914 views

What does `date 2&>$0` do?

I am looking at a co-workers shell code and I saw this: date 2&>$0 I know what date does, but what's 2&>$0 doing? He's out for a while, so I can't ask him what this part was about.
0
votes
1answer
52 views

Redirecting Standard Output And Standard Error to One File [duplicate]

I have come to understand that we have two methods of redirecting both stdout and stderr to the same file. The first method is: ls -l /bin > ls-output.txt 2>&1 As the author of this book ...
2
votes
2answers
101 views

output both stderr and stdout on console and store them in a file at same time

may I output both stdout and stderr on console screen and store one of them into a log file? I write a test shell script: #!/bin/sh echo OUT! >&1 echo ERR! >&2 I can output both of ...
2
votes
1answer
70 views

Behaviour of 1>&0 in bash

So I am trying to learn more about file descriptors and their redirections. At the moment I am exploring an edge case of doing 1>&0 and I cannot quite understand what is happening there. $ ...
1
vote
1answer
62 views

Redirection differences between &> >& and 2>&1

On this SO thread and a few other threads I have seen the following commands for redirecting stdout and stderr to a file. Are they all equivalent? Is there any difference between them? command1 ...
0
votes
1answer
31 views

How do I suppress all email notification from cron for particular job?

I am scheduling the following shell script #!/bin/bash (echo open mailserver.nowhere.local 25; sleep 1; echo EHLO; echo quit)\ | telnet | grep "?Invalid command" if [ $? -eq 1 ]; then ...
1
vote
1answer
44 views

Controlling the terminal while in the middle of a pipe [duplicate]

Say I have 3 commands linked through pipes: A | B | C I would like B to output error messages to stderr and some progress to the terminal. If stderr is the same as the terminal, then that is easy: ...
3
votes
1answer
64 views

How to redirect output while using a here document

How to redirect the output of below command in shell into logfile. sqlplus -s "/nolog" <<EOF conn / as sysdba @?/sqlpatch/19282021/postinstall.sql exit; EOF
2
votes
1answer
70 views

How does ssh prompt for a password when all input and output is redirected?

I don’t actually need to run the command below, and I am aware of ssh keys if I did want to log in without typing a password. I would just like to know how ssh seems to circumvent my file redirection. ...
0
votes
5answers
55 views

Is there a way to do a “full file buffering” inside a chain of piped commands?

Very often I do simple operations on a file, for example: cat file1.txt|sed -r 's/^ *//' to remove spaces at the beginning of the line. If I want to overwrite the file, the only way I know is: cat ...
1
vote
0answers
43 views

redirecting output of running background job in bash

in bash I have some jobs running, in background. They are always producing random irrelevant error messages that pollute the terminal. I am not always so prompt to start them with the 2>&1 > ...
3
votes
1answer
58 views

Problem with getting interactive input in while read loop

I was doing something like the following minimal example: #! /bin/sh # $1 = file containing list of files to sync # $2 = source dir ; $3 = target dir cat "$1" | while read f do cp -i "$2"/"$f" ...
1
vote
0answers
27 views

Capturing data from a Fluke 1620a via Bash /dev/tcp file descriptor

I am currently trying to develop a script that will connect to a Fluke DewK 1620a Themo-Hygrometer and pull the current temperature and humidity readings from the device. While these devices have a ...
2
votes
3answers
75 views

Using a command's output to determine the name of the file to redirect output to

I want to run smartctl -a, and use the device serial number from that output as the name of the file to store the output in. I know this can be done by invoking smartctl twice, and slicing up the ...
0
votes
0answers
63 views

how to route traffic on port to ip:port on linux?

I'm trying to route all traffic on port udp 5000 to udp 192.168.0.1:12333 with the following command: $ iptables -t nat -A PREROUTING -p udp -m udp --dport 5000 \ -j DNAT --to 192.168.0.1:12333 ...
7
votes
4answers
354 views

output to file, then use file for input

Is there a shorter way of writing this? Basically output a command to a file, then use the file as input for the next command. I also want to keep the file to view afterwards. cmd1 > verylong.txt; ...
1
vote
2answers
179 views

Redirect stdin and stdout to ports

I'd like to take a program P that reads from stdin & writes to stdout, but connect it to nc or whatever such that it reads from a certain port and outputs to another port. # The reading is easy, ...
3
votes
2answers
99 views

Syntax error: word unexpected on io redirection on file descriptor ≥10

I have the following shell script on debian 7: #!/bin/sh case "$IFACE" in lo) # The loopback interface does not count. # only run when some other interface comes up exit ...
1
vote
2answers
36 views

Capturing data from a Fluke 1620a via netcat

I am trying to pull temperature and humidity data from Fluke DewK 1620a thermo-hygrometers and write the temp/humidity readings to a log. I can connect to the device via netcat with a simple 'nc ...
1
vote
1answer
33 views

redirect to the same file as the source file processed by the command [duplicate]

Redirection is not allowed here. Is cat not allowing? But isn't redirection independent of any command running with it? $ cat bk > bk cat: bk: input file is output file Why does the following ...
-1
votes
3answers
61 views

what is the use of '<<' redirection? [duplicate]

I am looking for an example of << redirection because i don't understand it well. I know < is for sending the contents of specified file to be use as standard input like : cat < file.txt ...
3
votes
3answers
71 views

How can I base the file name off of an already existing variable?

I'm using this to delete lines that don't match a pattern: $ egrep "pattern1|pattern2|pattern3|pattern4|pattern5" But now I need to do it automatically, so I'm setting a variable like this: $ ...
4
votes
3answers
339 views

Hide ouput of bash while running automated script.

I have a couple of scripts in my bash file, that should do certain tasks, say like ... #!bin/bash yum -y update service restart nginx yum install atop cat /var/log/somelog.log > ...
1
vote
2answers
90 views

Combination of echo, pipe and cat

I have a file name called temp.csv in my script one of the intermediate step is echo "some info" > final.csv | cat temp.csv >> final.csv at times the file final.csv is created without ...
1
vote
2answers
136 views

double grep on tail -f gives no output

If I follow a file somehow like this: tail -f /var/log/syslog|grep s I see all lines containing an "s" Why does this not give any output, if I grep it again to the same "s"? tail -f ...
0
votes
3answers
119 views

Pipe/redirect a group of commands

I currently use the following setup to redirect the output of multiple commands: echo "Some normal commands" ( echo "Error: something happened" echo "Warning: this incident will be logged" ) >> ...
28
votes
2answers
2k views

How does `cat <> file` work?

cat < file prints the contents of file to stdout. cat > file reads stdin until Ctrl+D is detected and the input text is written to file. cat <> file, at least in my version of Bash, ...
0
votes
1answer
279 views

grep: input file 'X' is also the output

I use ubuntu 14.4, and attempt to redirect the output of grep command to a file, but I keep getting this error: grep: input file 'X' is also the output I've searched for this issue and just found ...
4
votes
3answers
155 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 ...
0
votes
0answers
55 views

Why is a here-string command substitution considered as a single line?

I'm experimenting with while read syntax and there is a thing I don't understand. The most basic scenario which reproduces the problem is the following: a bash script a.sh calls another script b.sh ...
5
votes
1answer
282 views

Why does “cat /tmp/out1 > /tmp/in2 &” appear as “bash” with the “ps” command?

Consider: mkfifo /tmp/out1 mkfifo /tmp/in2 cat /tmp/out1 > /tmp/in2 & When I run ps it appears as bash in the CMD section. Why?
1
vote
1answer
69 views

Pipes & redirection binding precedence with disjuncts, conjuncts etc?

I know of the relative binding precedence of operators ‘;’, ‘&’, ‘&&’, or ‘||’ http://www.gnu.org/software/bash/manual/bashref.html#Lists but when pipes come into the picture along with ...
2
votes
2answers
73 views

saving the output of command line in a text file?

I am using the following command line to analyse data: unpackdcm -scr ${in} -targ ${out} This command is printing on the screen status and description about the progress in the job. In order to ...
1
vote
1answer
57 views

Redirect output to stdout and pipe to a binary

I have a nice PS1 line in my .bash_profile, and I want to copy it to another machine. So I want to view it AND copy it to my clipboard. I can't figure out how to string the commands to do this ...
3
votes
2answers
169 views

How can a bash script write its standard output from within a pipeline? [duplicate]

I have a bash script that calls a function. The function, amongst other things, executes a pipeline that sinks its output. To simplify it, here is a contrived example: #!/bin/bash func() { ls "$@" ...
0
votes
1answer
38 views

UNIX stdout redirection

I've written a script and I want to direct the console output to a file, so I use this command: ~/simplesim-3.0/sim-cache -cache:dl1 dl1:1:64:2048:f -cache:il1 il1:1:64:2048:f \ -cache:il2 dl2 ...
1
vote
3answers
117 views

Redirect stderr and stdout to another file descriptor

exec 6>&1 will copy file descriptor 1 onto 6. But how can I copy both stderr and stdout (1 and 2)to file descriptor 6 ?
4
votes
3answers
96 views

Time required to do pipe output to head/tail [duplicate]

There are lots of txt files in a directory. If I do time wc -l *.txt | head it takes real 0m0.032s user 0m0.020s sys 0m0.008s If I do time wc -l *.txt | tail it takes real 0m0.156s ...