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

Does input redirection (<) append a newline character?

I was originally of the impression that $ ./myprog moo[CTRL-D] is exactly the same as $ echo moo > cow $ ./myprog < cow But I found that myprog always counts one more \n in the second ...
3
votes
2answers
1k views

exec < filename - what does this do?

I have found the following code snippet (sh): TESTFILE=$TEST_PATH/test.out if [ -f $TESTFILE ] then exec < $TESTFILE else echo "$TEST_PATH: no test.out file" fi ...
2
votes
2answers
2k 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 For the ...
0
votes
1answer
213 views

The “cp p2 &2 &” command makes Konsole to disappear, is it a bug?

The goal is start a background process that copies the data from the pipe p2 to the STDOUT as p2 is feed with data by some other process. I guess the command is incorrect. Nevertheless, the Konsole ...
0
votes
3answers
1k views

wget is returning an html page instead of original file

In my case the problem is with SourceForge.net. Actually I was trying to download these files: http://sourceforge.net/projects/wxpython/files/wxPython/2.9.4.0/wxPython-src-2.9.4.0.tar.bz2/download ...
10
votes
1answer
18k views

Is there a way to redirect nohup output to a log file other than nohup.out?

I frequently use the program nohup so that my processes are immune to hangups. So if I want to make the program program immune to hangups, I use the command nohup program & where & puts ...
9
votes
2answers
366 views

Trying to “locate” and then open a file

Suppose that I have a file named filename123.txt and it is the single file that is named so, and I can locate it with the command locate filename123. And it returns only this file. Now I want to open ...
5
votes
1answer
124 views

ask for comfirmation when file is replaced using a redirection

I'm a careless terminal driver scared of accidentally deleting files, hence using some aliases like alias rm='rm -i' for rm, mv, cp. How can I get a similar confirmation behavior for file redirections ...
4
votes
2answers
939 views

Behavior of stdin/stdout in conjunction with subshells and cd command

I have the following series of commands: cd / && ls | ( cd /tmp && cat >dumpfile) This series of commands does the following: it creates a file named /tmp/dumpfile. This file ...
13
votes
2answers
664 views

Redirect stderr from an already running script

I've been running a script for several days now. I redirected stdout to $HOME/mylog, but didn't redirect stderr since I thought there would be nothing on it. Suddenly thousands of lines started coming ...
5
votes
1answer
581 views

Append output to a file and redirect stderr to null

How can I append the result of a command to a file and redirect stderr to null?
94
votes
1answer
5k views

Bash: What does “>|” do?

I have just seen this written down; $ some-command >| /tmp/output.txt Vertical pipes are used in standard redirects "piping" the output of one command to another, is >| in fact completely ...
5
votes
3answers
11k 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 ...
6
votes
2answers
4k 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 ...
1
vote
2answers
832 views

On the command line, can I redirect output to a file WITHOUT >, >>, or | operators?

I am attempting to run a command on a CentOS virtual machine, and the API that I am using to run this command does not seem to allow the >, >>, or | operators. Also, I must use fully qualified paths ...
3
votes
2answers
2k views

Sending the output from 'dd' to awk/sed/grep

I'm trying to approximate the computer's write speed using dd: dd if=/dev/urandom of=/dev/null bs=1K count=10000 which gives the following output 10000+0 records in 10000+0 records out 10240000 ...
3
votes
3answers
2k views

Piping in awk scripts

I'm trying to write a ls wrapper that uses awk to parse the output of ls -lhF. Right now I've split the program into two files - my_ls.sh and my_ls.awk. my_ls.sh's only purpose is to pipe the output ...
13
votes
2answers
2k views

Does redirecting output to a file apply a lock on the file?

If I have a command $ ./script >> file.log that gets called twice, with the second call occurring before the first one ends, what happens? Does the first call get an exclusive lock on the ...
5
votes
2answers
564 views

Wrapping a shell script with tee

There is a bash script which prints some logs and allows some arguments. The script prints the logs to STDOUT. Let's say the script's name is AAA.sh I'd also like to make the script to print the logs ...
1
vote
3answers
283 views

Concise way to output to file if argument is given, to stdout otherwise

I'd like my script to output to stdout unless it gets a filename as an argument. An obvious way is like so: if [ -e "$1" ]; then command_with_output >$1 else command_with_output fi It's ...
1
vote
2answers
2k views

Show command executed along with output in log file

Is there a quick and dirty way to not only log the output of a shell file but the commands used inside as well? For example: whoami > who.dmp would output a file that contained something like: ...
4
votes
2answers
470 views

how to redirect terminal output to multiple log files

I've been trying redirect output to logfiles but should NOT be displayed on terminal, but following command does output both on terminal and in logs. Any ideas are appreciated. (some_cmd | tee -a ...
8
votes
1answer
942 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=/tmp/suppressed if ! ( "$@" > "$file" ...
2
votes
2answers
987 views

How to remove error messages when searching recursively for a string?

I use find -type f -print0 | xargs -0 -n 10 grep -i searchstring to search recursively for a string. But it also gives me error messages like "permission denied". How can I avoid such error messages ...
6
votes
1answer
343 views

differences between echo“”> and > command

I am new to Linux. There is something that is unclear to me. What is the difference between echo "" > logfile and > logfile ? When I run the first one, the logfile size doesn't become zero ...
1
vote
2answers
114 views

bash: Redirect IO , but not with suffixes

usually I use XX 2>error.log , but for debug purposes , I prefer the following syntax: function XX() { redirect_io_to "error.log" } Is there such syntax available ? It's convenient ...
1
vote
2answers
704 views

Writing both output and error stream to the same file

In Unix/Linux you can use pipes to write output and error streams to a file. One can even write them to the same file. Is there a way to write both to the file but maintaining the order. This ...
0
votes
1answer
180 views

Bash shell with problematic outcomes under Linux (C) [closed]

Following my previous post, I still have one annoying bug that won't leave . I wrote a simulator for the bash command under Linux. When I run my code in a single run, with the these commands: ls ...
5
votes
3answers
2k views

Why `> my.log 2>&1 &` causes the job to sustain log out?

I use myscript > my.log 2>&1 & to run a script and collect it's output - so that when I logout - the script will still be running. It I were to start it with myscript & - it will ...
2
votes
1answer
383 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 ...
4
votes
4answers
562 views

How to add a line to a file which has only root write permission and to continue the script execution

I am trying to learn bash scripting. I am working on a practical problem and at one point I need to add a line to a file which requires root permission to write. The code looks like this: # some ...
10
votes
2answers
396 views

Order of redirections

I don't quite understand how the computer reads this command. cat file1 file2 1> file.txt 2>&1 If I understand, 2>&1 simply redirect Standard Error to Standard Output. By that ...
0
votes
2answers
3k views

Shell script how to read input from a file [closed]

I need to read input from a file given in following format. $ ./process_data.sh arg1 < input_data.txt How do I read input_data in my shell script process_data.sh?
2
votes
4answers
2k views

Change password in headless mode

I am building a script to fully automate a VPS setup, and I need to change the root password. I would like to avoid typing it as the script is running through SSH. Is there a way to redirect an ...
2
votes
1answer
101 views

pipe and log STDOUT at the same time

Some programs output very detailed data, for readability I use awk to filter them. ./output_many_things | awk '{print $1 "\t" $2}' But I don't want to miss anything. Could I redirect the complete ...
4
votes
3answers
694 views

What does the following Bash script mean/do?

What does the following script mean? exec 4<&0 0</etc/XX/cfg read line1 exec 0<&4 UPDATE Thanks for the answer, just one part I'm not sure: It redirects fd0 to fd4, and ...
4
votes
1answer
265 views

command like wc but with tee behaviour

I want to backup a database using psql and COPY command. here is my script: psql "user=${USERNAME} host=${HOSTNAME} dbname=${DBNAME} password=${PASSWORD}" -c \ "COPY (SELECT * FROM tbl) ORDER BY id ...
4
votes
3answers
3k views

stderr redirection not working in csh

I run the following command: pkg_add emacs-23.4,2.tbz 2> output.log The output still displays in the terminal. When I press ↑, I get pkg_add emacs-23.4,2.tbz 2 > output.log with a space ...
3
votes
1answer
2k views

Why does sftp hide the log from stdout?

I have a script a.sh, which has an sftp command: echo "Starting to sftp..." sftp xxx@xxx.xxx.xxx.xx << END_SCRIPT ls mput *.csv.gz bye END_SCRIPT echo "Sftp successfully." If I run it ...
3
votes
1answer
400 views

Redirecting/grep'ing an existing shell's STDOUT

I run a lot of long running processes (simulations) that print progress to STDOUT. I occasionally forget to redirect to STDOUT to a file I can grep, and it's usually too far along to restart. ...
5
votes
2answers
5k views

tail program output to file in Linux

I know we can use below format to redirect the screen output to a file: $ your_program > /tmp/output.txt However when I used below command, it says "-bash: /home/user/errors.txt: Permission ...
2
votes
1answer
1k views

“>/dev/null 2>&1” in `if` statement

I don't understand the below if condition. I know that /dev/null 2 > &1 is sending output to error stream (please correct me if I am wrong). But I don't get it when it is in an if condition ...
4
votes
3answers
508 views

Why do I keep destroying my text files?

I have destroyed a bunch of non-essential files and I don't know why. I have been executing commands like: tr -sc 'A-Za-z' '\n' > somefile.txt | less there is no output (blank page with flashing ...
6
votes
1answer
2k views

Bash read command and stdin redirection

As I understand the bash documentation both | and < redirect stdin. So, cmd | foo and foo < <(cmd) should be more or less equivalent. However, for the bash-internal read command this doesn't ...
4
votes
2answers
3k views

Can I redirect logfiles to syslog?

I have a Node.js server that is being monitored by forever. Forever generates three logfiles: the server STDOUT, STDERR and the log of forever itself. $ forever -l forever.log -o out.log -e err.log ...
3
votes
1answer
318 views

Shell script doesn't paint last line of stdout to screen without user input

I have a shell script that's happily doing all my backup process and writing progress to stderr and stdout, with one exception — the last line doesn't get written to my terminal (if I call the script ...
2
votes
4answers
1k views

Grep for a string with list of files as source

I have a plain text file, in every line is a path to a file. Now I have to grep for a string in these files. Is there any way to use this file as "search source" for grep? Or do I have to copy and ...
1
vote
1answer
1k views

How can I send data to the STDIN of a background process?

I'm trying to: Launch several ssh sessions (processes) through a script (Python) Communicate with the sessions by sending them commands via STDIN (even though they aren't open in my current ...
6
votes
2answers
3k views

what is meant by connecting STDOUT and STDIN?

This is a newbie question. I'm reading a book, it says: Every process has at least three communication channels available to it: “standard input” (STDIN), “standard output” (STDOUT), and ...
0
votes
3answers
8k views

How do I redirect command output to a file?

I have a command that I run in a folder that outputs MD5 hashes and filenames on the terminal: ls |sort -nr | xargs md5sum I need this output in a text file that I can download and compare to ...