Questions tagged [io-redirection]

I/O redirection is used in shell scripting. This feature enables one to take the output of a command and redirect it as an input for another command, or a command can take the input from a file instead of from the standard input stream or from the terminal. The whole process helps connect data streams in various ways.

Filter by
Sorted by
Tagged with
-1 votes
1 answer
35 views

Can you make nohup.out get created only on errors without manually specifying the file name?

Can you make nohup ./file $1 $2 & (which runs ./file in the background) create nohup.out only for errors and not for standard output? But please without manually specifying nohup.out i.e. nohup ./...
LWC's user avatar
  • 103
2 votes
1 answer
123 views

How to stop redirection via exec

I want to redirect some output of a script to a file. REDIRECT_FILE="foo.txt" echo to console # starting redirect exec > $REDIRECT_FILE echo to file echo ... echo ... # stop redirect ...
Andy A.'s user avatar
  • 187
1 vote
2 answers
41 views

Print on stdout and log with logger

I have a bash script with several "echo STRING" commands. I would like to log STRING with logger but still print it on stdout. echo STRING | logger obliviously does not do it. EDIT: echo ...
mifrey's user avatar
  • 25
0 votes
1 answer
73 views

How to pass the standard input of a shell script to a background command

In a shell script, I am trying to start a background command that has the same stdin as that of the shell script. #!/bin/sh # ... the-program & However, the-program above will not have access to ...
Flux's user avatar
  • 2,770
1 vote
0 answers
52 views

Log jdupes output in unRAID User Script

I have an unRAID server and I use jdupes to manage duplicate files. I set up a User Script with jdupes -rL /dir1 /dir2. However, the log of the User Script does not display the output of jdupes. ...
SvbZ3r0's user avatar
  • 111
0 votes
0 answers
16 views

Redirect \t \t output in bash [duplicate]

While doing some random thing I checked the commands using ⇥-completion (⇥⇥ on an empty prompt), it then proceeded to show me the longest paged list ever made, or so it seemed. That's when it occurred ...
Vita's user avatar
  • 141
2 votes
2 answers
88 views

tee /dev/stderr inside script truncates output file if you redirect stderr

Given a script like below if I try to redirect stderr to a file, then the file is truncated at the point tee is used: $ cat test.sh #!/bin/bash set -eux echo before echo '{ "foo": "...
Jakub Bochenski's user avatar
0 votes
1 answer
69 views

Using awk -v with Shell variable works great and prints to terminal, but when redirect to a file only the 1st record prints to the file

I am reading a file with a matching pattern then getting the first five lines after the matching pattern. The patterns are not in proper numeric order, so I am using a numeric variable in the pattern ...
Joey Simon's user avatar
0 votes
0 answers
31 views

Difference between saying "error redirected to output channel" vs "output redirected to error channel"? [duplicate]

https://community.unix.com/t/difference-between-2-1-and-2-1/392167 I was reading this post. ls name 2>&1 makes bash run ls with its stderr assigned to the same stream as its stdout (not the ...
achhainsan's user avatar
0 votes
1 answer
61 views

how to execute command and log only the command to a file

I'm trying to run a command and log only the command to a file. I've tried using exec 4>test|command >&4|exec 4>&- but doesnt' work. If I run the commands separately it works but ...
dsaizt's user avatar
  • 11
3 votes
2 answers
376 views

Piping and input stream redirection to same command, which input does command take?

I was trying to run the command given below cat numbers.txt | sort < words.txt The above command has a pipe from cat command feeding to input stream of sort command. But at the same time, input ...
Abhishek P G's user avatar
0 votes
0 answers
18 views

Why does the output in following command get written to second file rather than first file [duplicate]

I was learning about I/O redirection and tried out the following command. ls -l /bin/ > bin_contents.txt > bin_contents_copy.txt I do understand that redirection doesn't work between files. But,...
Abhishek P G's user avatar
0 votes
0 answers
20 views

Pipe or Redirect output: Linux (Remote) to Win (Local)

the following answer the question, but they're either using the HEREDOC syntax, as part of the SSH command itself, or a combination of both. @askubuntu - output-from-remote-machine-to-local-file-via-...
Sylvester DeMouser's user avatar
7 votes
1 answer
2k views

When redirecting top to a file, why does cat command on that file display output of multiple top attempts?

I am customizing a Linux system with a kernel of 6.4.0, and I have noticed a strange issue. When I execute top > a.txt and then open a window to execute cat a.txt, I find that the cat a.txt result ...
ABeginner's user avatar
0 votes
1 answer
93 views

When simply `| cat -`, I get file descriptor errors

Here's the working diff command: $ diff -u <(echo 'foo:bar:baz' | tr : "\n") <(echo 'foo:baz' | tr : "\n") --- /dev/fd/11 2023-08-30 13:11:50 +++ /dev/fd/13 2023-08-30 13:...
Scoobie's user avatar
  • 101
0 votes
1 answer
52 views

mkfs.xfs completely ignoring "|more" redirect

trying to install gentoo linux and can't format the drive with xfs because when I run mkfs.xfs /dev/sda3 it throws an error and then displays help, but the help is so big that it takes up the entire ...
Zack's user avatar
  • 1
2 votes
3 answers
60 views

Redirect stderr to stdout to a file in a script

I have several different algorithms, that I need to prototype. So I make prototype programs and a script. the script called time.sh looks like this echo "Timing algorithm1:" time algo1 >...
Thad_The_Man's user avatar
-1 votes
2 answers
172 views

Difference in bash 3 between pipe and here-string

If I run: IFS=':' cat <<< $(echo $PATH) then the ":" are used for word splitting and the output contains spaces instead of ":", but if I run: echo $PATH | IFS=':' cat ...
Allen's user avatar
  • 206
0 votes
0 answers
46 views

Simultaneous input from fifo and terminal in bash

I am running ffmpeg inside a script and I want to be able to quit ffmpeg either by pressing 'q' in the terminal it's running in (default behaviour) or by inputting 'q' into a fifo file, whichever I ...
Mouse'nKeyboard's user avatar
0 votes
1 answer
134 views

Continuously display last line of command output without clearing the screen

I want to print only the last line of the output of a command on the same line continuously without clearing the screen. This would be part of another function. Let's say my script has the following ...
houss's user avatar
  • 1
1 vote
1 answer
117 views

Permisson denied installation to USB flash

I'm trying to use basic command utilites to write ISO to USB flash. I'm writing: sudo cat path/to/archlinux-version-x86_64.iso > /dev/disk/by-id/usb-My_flash_drive but I have response: zsh: ...
S1mY's user avatar
  • 11
1 vote
0 answers
57 views

Required help with extremely hacky Bash script to view Readline's killring

I devised a contraption to visualize the killring in Bash. It work like this: $ killring Killring: 1 Line one in killring 2 Line two in killring 3 Line three in killring However, there are some ...
Sebastian Carlos's user avatar
-1 votes
1 answer
44 views

Portable temporary file descriptors inside `sh -c` [duplicate]

cat <(echo yes) Displays "yes". And running this inside sh -m results in the same thing on Bash 5.2.15. Yet on Bash 4.4.20 it throws an error: sh -c "cat <(echo yes)" sh: -c:...
Zaz's user avatar
  • 2,529
0 votes
2 answers
68 views

Why Bash redirects even when there's no command?

The Bash manual says that, after performing expansions If no command name results, redirections are performed, but do not affect the current shell environment. Now, what's a use-case for this? What'...
Sebastian Carlos's user avatar
0 votes
0 answers
67 views

Process pv output to write status to a file while running

I want to monitor the progress of a very large tarball extraction in a shell script. The monitoring process can watch files, so I am thinking if I could get the output of pv to pipe to a script I ...
Jim B.'s user avatar
  • 101
0 votes
0 answers
25 views

Capture stderr of program into a variable without affecting stdout and interactive features [duplicate]

I have a program that asks the user for input and provides interactive features such as moving the cursor, deleting text, and more. After the user completes entering the input, the program clears the ...
sudormrfbin's user avatar
0 votes
0 answers
17 views

When redirecting error to sto, should the command comes after the file or before? [duplicate]

Are there any differences among three commands below? some_command >> $logfile 2>&1 some_command 2>&1 >> $logfile ( some_command ) >& $logfile I originally just ...
Lunartist's user avatar
  • 385
1 vote
1 answer
56 views

Find number of process running using fuser

We are using fuse to find the logs associated to particular port. fuser /test/log* This results in a list of logs associated with port How to find the number of lines on the output? I tried with |wc -...
Varja's user avatar
  • 69
0 votes
2 answers
120 views

Which file descriptor numbers are safe to use in (POSIX) shell scripts?

Chapter 3.6 Redirections of the Bash manual says: Redirections using file descriptors greater than 9 should be used with care, as they may conflict with file descriptors the shell uses internally. ...
finefoot's user avatar
  • 3,010
0 votes
1 answer
70 views

bash: clarification on order of redirection and pipes

In an attempt to further understand bash, I am trying to replicate some functionalities of it. Right now I am in the process to implementing the redirecting and pipeline features. To further ...
Fernando Gómez de la Varga's user avatar
0 votes
1 answer
540 views

Can't create a SSL certificate. [bash:server.key:Permission Denied] [duplicate]

i'm a student and i'm trying to make a SSL certificate because i'm following this guide: https://www.server-world.info/en/note?os=Fedora_27&p=httpd&f=13 I'm running in vbox Fedora Server 38 I ...
Wilson Lima's user avatar
0 votes
3 answers
117 views

retrieve std out redirect to /dev/null

is there a way to retrieve std out redirected to /dev/null? I tried tail -f /proc/{PID}/fd/1, looks like only works except redirects to /dev/null. i.e. tail -f /proc/${cmd_pid}/fd/1 works on cmd > ...
furynerd's user avatar
4 votes
1 answer
703 views

How can I remove this annoying message: "Failed to find cgroup2 mount"?

I run this command ss -tulpnoea|grep -i water|grep -v 127 Failed to find cgroup2 mount Failed to find cgroup2 mount Failed to find cgroup2 mount Failed to find cgroup2 mount Failed to find cgroup2 ...
elbarna's user avatar
  • 12.4k
0 votes
0 answers
57 views

Why do I get "Not a terminal" error during output redirection in csh?

Background: We have put some command outputs (both stdout and stderr) into the same file under the csh shell. Question: Why do we get the "Not a terminal" message in the following ...
lylklb's user avatar
  • 193
0 votes
1 answer
35 views

When processing multiple files, can output be redirected to a separate file for each input file?

I execute something like this: % command *bin > log.txt *b expands to a.bin, b.bin, c.bin. I would like stdout from each file to end up in a separate log.txt (or rather, a.txt, b.txt, c.txt). How ...
d-b's user avatar
  • 1,853
1 vote
2 answers
65 views

Why doesn't this function work for soak up stdin?

This: echo 'some text' > file.txt cat file.txt > file.txt Obviously gives me an empty file. But to my surprise also: cat2 () { cat "$@" > tmp.txt cat tmp.txt return $? }...
Mario Palumbo's user avatar
0 votes
1 answer
74 views

Write command used and its output to a file

I have a simple problem that is getting hidden underneath answers to an even more simpler problem. Let's say I use the command ls > file.txt which redirects the stdout of ls into file.txt. The ...
Austin Benny's user avatar
1 vote
1 answer
98 views

Redirect stderr doesn't show python input

I am running the following command on the terminal: python -c "input('Message')" 2> log but the Message doesn't appear on the screen. Any ideas why this happens?
ado sar's user avatar
  • 133
5 votes
1 answer
883 views

In >&N, why is N treated as file descriptor instead of as file name (as the manual seems to say)?

I am struggling with understanding IO redirection in bash. I have seen many examples like the following (which is literally taken from the accepted answer here): exec 3<> /tmp/foo #open fd 3. ...
Binarus's user avatar
  • 3,220
0 votes
2 answers
104 views

mysqldump failing when launched from script

Running next command in terminal is working fine like expected. /var/www$ sudo mysqldump --defaults-extra-file=/mnt/./.sql/mysqldump.cnf --databases site3 --hex-blob | sudo tee /mnt/site3/...
jwa's user avatar
  • 13
1 vote
0 answers
56 views

Permission denied using mounting point / redirection in mysqldump command [duplicate]

The following commands work as expected except for the mysqldump command: /var/www$ sudo mount -t ext4 /dev/sda11 /mnt /var/www$ cd /mnt /mnt$ sudo mkdir blabla /mnt$ ls -la drwxr-xr-x 5 root root ...
jwa's user avatar
  • 13
1 vote
0 answers
50 views

How to redirect stderr in FreeBSD? [duplicate]

How to redirect stderr in FreeBSD? Neither of below worked : ls 2> out.log ls: 2: No such file or directory : ls -al 2> error.log ls: 2: No such file or directory : (ls -al) 2> error.log ...
Dims's user avatar
  • 3,225
0 votes
1 answer
55 views

Why are commands reading from /dev/stdin get a status "[1]+ Stopped" when sent to background?

I have tried running the following commands: cat base64 /dev/stdin md5sum /dev/stdin tail /dev/stdin In all cases when I do: ^Z $ bg $ jobs I get the status: [1]+ Stopped instead of [1]+ Running. ...
Marinos An's user avatar
0 votes
1 answer
155 views

Run a scheduled command on open terminal

A task/script scheduled with cron or at (AFAIK) can not run inside a specific terminal: it can only print the output (through redirection) of a task/script to a specific terminal. Instead, I would ...
BowPark's user avatar
  • 4,861
0 votes
3 answers
437 views

Why does < exist to redirect to stdin? [closed]

Question Why do shells implement alternative means like <<<, < <(command) and < /dev/fd/* to redirect something to stdin when pipes do exist? Example The | way (classic pipes) echo '...
Semnodime's user avatar
  • 347
13 votes
2 answers
2k views

Why is appending different streams to a file safe?

It's well known that redirecting standard output and error to the same file with cmd >out_err.txt 2>out_err.txt can lead to loss of data, as per the example below: work:/tmp$ touch file.txt work:...
Sweet Shell O'Mine's user avatar
0 votes
1 answer
36 views

How to force a program to write log into standard output In spite of redirection?

Background Today I am trying perconna's innobackupex with this command: innobackupex --stream=xbstream /root/backup/ > /root/backup/backup.xbstream However, I noticed logs show up on my terminal: ....
Steve Wu's user avatar
0 votes
1 answer
44 views

maintain appended logs in separate file despite tail command termination

I have tomcat catalina.log file that keeps getting updated. I wish to maintain its past 500 lines + any appended logs into a new file catalina.log_new for the next 2 hours. To start off I run nohup ...
Ashar's user avatar
  • 469
0 votes
1 answer
35 views

clamtk does not redirect stdout for its cron job

I have noticed that clamtk only redirects stderr to /dev/null and not stdout. if I change the cronjob it creates to also redirect stdout, will that effect the log file it creates? I want to use the ...
stacking and exchanging woohoo's user avatar
0 votes
1 answer
308 views

why isn’t all the output (`stdout` and `stderr`) redirected?

I have some understanding of how the stdout and stderr file descriptors work. But sometimes they don’t catch all the output and I trying to understand why. For example, cloning into a git repo gives ...
alex23ro's user avatar

1
2 3 4 5
30