io redirection is the process of changing where the output and input of a program originate
9
votes
2answers
154 views
Command line: <<< instead of <<
Why is the command md5sum <<< 'ddd'
(output: d6d88f2e50080b9602da53dac1102762 -)
right, and md5sum << 'ddd' not?
What does <<< mean?
0
votes
1answer
44 views
How do I redirect output from the find command (that uses grep) to a log file?
Consider the code to search for all files containing the pattern "search string":
bash-3.2$ # The below find works fine..
bash-3.2$ find . -type f -exec grep -il "search string" {} \;
bash-3.2$ # But ...
2
votes
1answer
41 views
Always redirect error to /dev/null
I know I can redirect the error messages from a command to /dev/null using the following syntax:
command arg1 arg2 2>/dev/null
But is there a way to do this by default so that the error messages ...
4
votes
4answers
108 views
Can I write the output the of time difference command to a file?
Can I write the output of the time difference command to a file?
For example, I tried:
$ time foo.sh > bar.txt
But it only gives the output of foo.sh to bar.txt.
1
vote
2answers
47 views
Chaining mysqldumps commands to output a single gzipped file
Let's say I have these series of commands
mysqldump --opt --databases $dbname1 --host=$dbhost1 --user=$dbuser1 --password=$dbpass1
mysqldump --opt --databases $dbname2 --host=$dbhost1 --user=$dbuser1 ...
2
votes
1answer
46 views
Separate STDOUT noise from ncurses
I am trying to run an ncurses GUI application on an ARM board. I am running it using the serial console ttyAMA0 port. But when I run the ncurses program, the other processes running in the background ...
2
votes
1answer
28 views
redirection to file issues with nohup and pipe
for the following script
ssh -t esolve@hostname 'sudo nohup bash -c "ls > log 2>&1 &"'
I always got error information:
nohup: ignoring input and appending output to ...
0
votes
2answers
113 views
Redirecting stdin with stdout to file
So I have a program that takes in user input and outputs text based on the input.
EDIT2: I want to create a script that runs a C executable and the script feeds the C program input from a file and ...
1
vote
1answer
56 views
Standard I/O File Descriptors
I am new to Shell SCripting
I code this
$ ls -l 1> stdout.txt
and I get the output as desired,
1> stdout.txt
redirects the output from standard output to the file stdout.txt.
I don't ...
1
vote
2answers
49 views
Redirecting Multiple Commands as Input
What is the correct way to redirect the output of multiple commands as input for another command?
e.g.
$ command < (command2 | grep pattern)
12
votes
3answers
6k 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 ...
19
votes
5answers
5k views
How can I create a /dev/null-like “blackhole” directory?
I would like to create a "/dev/null" directory (or a "blackhole" directory) such that any files written to it are not really written, but just disappear.
I have an application that writes out large ...
3
votes
4answers
80 views
Getting stdin from a named pipe
What I am trying to do is run python in a terminal window and redirect it's stdin from a named pipe. Then I write to the named pipe in another terminal and have that command execute on python.
...
15
votes
1answer
3k views
Why is redirecting STDERR to /dev/null done this way?
This does not make sense to me.
wibble > /dev/null 2>&1
I think it would make more sense if it was something like this:
wibble 2>&1 > /dev/null
In other words
Commands ...
2
votes
2answers
57 views
What makes the shell interpret these redirects as follows?
Can anyone help me understand this seemingly odd behavior of how the shell parses the redirects..?
$ cat > test.txt
Line 1
Line 2
$ ls -i dummy.txt dummy2.txt
ls: dummy.txt: No such file or ...
7
votes
3answers
364 views
Piping STDERR vs. STDOUT
According to "Linux: The Complete Reference 6th Edition" (pg. 44), you can pipe only STDERR using the |& redirection symbols.
I've written a pretty simple script to test this:
#!/bin/bash
echo ...
5
votes
2answers
2k 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 ...
1
vote
2answers
109 views
Difference between 2>&-, 2>/dev/null, |&, &>/dev/null and >/dev/null 2>&1
Just looking for the difference between
2>&-
2>/dev/null
|&
&>/dev/null
>/dev/null 2>&1
and their portability with non-Bourne shells like tcsh, mksh, etc.
-4
votes
2answers
116 views
Redirecting the content of a file to the command “echo”
I have a file named my_file.txt whose content is just the string Hello. How could I redirect its content to the command echo?
I know I have the commands less, cat, more... but I need to do it with ...
1
vote
2answers
86 views
run a command as different user with available sudo permissions
I want to run the below command
echo 1000 > /sys/class/backlight/intel_backlight/brightness
i cannot do it it like below beecause bash is the process that actually directs output to the ...
2
votes
4answers
114 views
store and execute redirection/piped command in script
How do you store, and later execute, a command with redirection and and a pipe? (And is it the pipe, or the redirection, or both, that's causing my problem?)
I tried to print the urxvt version in a ...
3
votes
2answers
81 views
When should I use input redirection?
I used the following two commands to produce the same results:-
[root@localhost ~]# grep line comments
The line should start with a single quote to comment in VB scripting.
Double slashes in the ...
2
votes
2answers
44 views
redirecting std output and std error
I have been trying to figure out the relationship between file descriptors. One thing I don't understand is, how is:
ls -l /bin/usr > ls-output.txt 2>&1
different from:
ls -l /bin/usr ...
2
votes
1answer
128 views
starting server with nohup and redirecting input, output
I have a init.d script that starts a python socket server. Because I want this to run as a daemon, I use nohup to start it. I also want to redirect stdout and stderr to a log file. My problem is ...
3
votes
1answer
65 views
Redirecting output in the shell, permissions
I have a question about permissions.
Distro: Debian GNU/Linux 6.0.4 (squeeze)
So I have a folder with a php script in it. Both folder and file are owned by User1
If I do this:
php script.php
I ...
2
votes
2answers
854 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 ...
3
votes
2answers
156 views
echo string >> file does not work
I wrote the following script:
for filename in `find . -name '*'.cpp | grep $IN_REGEX | grep -v $OUT_REGEX`
do
echo "Output file is $OUTPUT_FILE"
count=`git log --pretty=format: --name-only ...
1
vote
1answer
106 views
How to ssh on multiple ipaddress and get the output and error on the local *nix machine?
command="ls -lrt;uname -a;uname -o"
for i in 10.38.227.229 10.38.164.103
do
ssh auto21@$i "$command 2>&1" >> log
#ssh -n auto21@$i "$command" 2> >> log
done
i am trying ...
2
votes
1answer
343 views
SSH causes while loop to stop
I have finally managed to boil down a problem I have been struggling with for a few weeks. I use SSH with "authorized keys" to run commands remotely. All is fine except when I do it in a while loop. ...
1
vote
1answer
62 views
Nested read fails
I have a list of filenames in a file and want to do let the user decide what to do with each. In bash, iterating over filenames is not trivial in itself, so I followed this answer:
#!/bin/bash
while ...
2
votes
1answer
106 views
How to wait for a subprocess used for I/O redirection?
Consider the following snippet of Bash script:
exec 3> >(sleep 1; echo "$BASHPID: here")
do-something-interesting
exec 3>&-
wait $!
echo "$BASHPID: there"
When executed, it produces:
...
8
votes
3answers
237 views
Practical use for moving file descriptors
According to the bash man page:
The redirection operator
[n]<&digit-
moves the file descriptor digit to file descriptor n, or the standard input
(file descriptor 0) if n is ...
6
votes
5answers
311 views
IO redirection and the head command
I was trying to quickly edit an .hgignore file from the Cygwin bash shell today, and I added a line that was a mistake. I'm not sure if this was the best way to do it, but I quickly thought of using ...
2
votes
1answer
98 views
Why can't I trim a file using `head`? [duplicate]
Given a file, foo.txt:
1
2
3
4
5
Say we want to change it to contain:
1
2
3
Why does head -n3 foo.txt > foo.txt leave foo.txt empty?
2
votes
1answer
73 views
Stderr of piped shell scripts isn't always displayed
I piped my own shell scripts for some testing and accidentally noticed something strange. Namely, the stderr of those piped processes isn't always displayed on the screen.
I simplified the scripts ...
2
votes
1answer
52 views
Why is it possible to refer to a closed stderr under bash?
I'd like to know why bash doesn't display an error message when we refer to a closed stderr. When it comes to other file descriptors, they have to be opened if we want to, for example, duplicate them. ...
2
votes
1answer
93 views
Significance of arrows symbols in duplicating/closing file descriptors under bash
I'm reading a book about Linux command line where author doesn't seem to follow the conventions in bash manual regarding arrows symbols used in redirection operations. Namely, he always uses left ...
3
votes
3answers
109 views
combine output from two commands in bash
Is it possible to combine output from these two commands?
node ~/projects/trunk/index.js
python ~/projects/trunk/run.py run
Neither command exits so I'm not sure how to do this.
6
votes
3answers
2k views
Non-blocking buffered named pipe?
I'm looking for something I suspect doesn't exist: A non-blocking buffered named pipe (fifo) for use from the command line. Is there such a thing?
Here's the use case: Suppose I have a process that's ...
1
vote
1answer
49 views
How get program name that produced an IO error redirected to a LOG in a nohup command?
I have a program that executes other programs in the background. The main program would be programA, and the programs executed by the main one, would be program1a, program1b and program1c.
I need the ...
40
votes
5answers
2k views
Can a command line program prevent its output being redirected?
I have become so used to do this:
someprogram >output.file
I do it whenever I want to save the output that a program generates to a file. I am also aware of the two variants of this IO ...
2
votes
4answers
247 views
How to pipe the stdout to a file if the current command is already being piped through gzip
So I have this command I need to run then disown:
innobackupex-1.5.1 --user=root --password=**** --stream=tar ./ | gzip - > /data/myfile.tar.gz
How do I pipe any output to a file?
adding ...
1
vote
1answer
42 views
Unsure about the behaviour of my script when writing to log file
I have a very simple ksh script and at certain points I want to write to a log file. I use the following commands in two places...
print "Directory listing 1:\n" > ${LogFile}
ll >> ...
2
votes
2answers
261 views
How to discard stderr in restricted Bash shell?
In my .bashrc there are a couple commands which redirect standard error to /dev/null, and this is not allowed within rbash:
bash: /dev/null: restricted: cannot redirect output
Is there some way to ...
9
votes
2answers
424 views
Redirect all subsequent commands' stderr using exec
I have a bash file that I need to redirect all output to one file, debug log as well as to the terminal. I need to redirect both stdout and stderr to the debug and log it for all commands in the ...
2
votes
1answer
111 views
How to copy the output of pacman-color into a file and to display the output with the colors in the terminal
Originally I used pacman, not pacman-color and I copied the output into a file and I displayed the output in the terminal with the following command :
pacman -Syu | tee file.log
Unfortunately, it ...
17
votes
3answers
3k views
Reading lines from a file with bash: for vs. while
I'm trying to read a text file and do something with each line, using a bash script.
So, I have a list that looks like this:
server1
server2
server3
server4
I thought I could loop over this using ...
0
votes
0answers
43 views
Root user can't do everything? [duplicate]
Possible Duplicate:
Redirecting stdout to a file you don’t have write permission on
I'm quite new to Linux and I have a permissions questions. I'm using Linux Mint.
If I go to /opt and do ...
4
votes
2answers
1k views
/dev/tcp listen instead of nc listen
With a netcat listener like:
nc -l <port> < ~/.bashrc
I can grab my .bashrc on a new machine (doesn't have nc or LDAP) with:
cat < /dev/tcp/<ip>/<port> > ~/.bashrc
My ...
17
votes
10answers
4k views
How do I reuse the last output from the command line?
This is a noob question, but I'd like to know how to reuse the last output from the console, ie:
pv-3:method Xavier$ python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
...


