The tag has no wiki summary.

learn more… | top users | synonyms

2
votes
5answers
110 views

Stripping directory paths to get file names

What I am doing is converting mp3's with LAME. I already have an old script I wrote that works but I want to add to it this ability--to no longer delete the file but instead save it in a new root ...
32
votes
2answers
1k views

Is >&- more efficient than >/dev/null?

Yesterday I read this SO comment which says that in the shell (at least bash) >&- "has the same result as" >/dev/null. That comment actually refers to the ABS guide as the source of its ...
0
votes
1answer
27 views

How to find file/device given the resource ID on Linux?

On a gentoo Linux system I am printing the value of a file descriptor from within a PHP script yielding the following output: Resource id #1234 How to find the corresponding file/device given this ...
1
vote
2answers
101 views

Process substitution with input redirection

I am trying to understand input redirection in combination with process substituation. I am using bash 3 An example with tr is the following $ tr "o" "a" <(echo "Foo") tr: extra operand ...
5
votes
3answers
471 views

Why can't I `tail -f /proc/$pid/fd/1`?

I wrote a simple script which echo-es its PID: #/bin/bash while true; do echo $$; sleep 0.5; done I'm running said script (it says 3844 over and over) in one terminal and trying to tail ...
2
votes
1answer
49 views

Is there a system call to bind a file descriptor directly into another?

A read() & write() loop would probably be as good as what I'm looking for, but nevertheless is anything like that around or is it impossible because of an obstacle I didn't envisage ? I'm curious
7
votes
1answer
59 views

How can I send reads and writes on a single file descriptor to different places?

I have a Linux executable foo that reads input from fd 0 and writes output to fd 0 (not fd 1). This works just fine for interactive use in the terminal. From the shell command line, how can I execute ...
7
votes
3answers
624 views

How can a log program continue to log to a deleted file?

From the Unix Power Tools, 3rd Edition: Instead of Removing a File, Empty It section: If an active process has the file open (not uncommon for log files), removing the file and creating a new ...
5
votes
2answers
90 views

“command | less” vs “less <(command)”

A common "idiom" for viewing large amounts of command output is to pipe it to less, via command | less. However, it's also possible (perhaps only in bash, haven't tested in other shells) to use the ...
1
vote
2answers
56 views

What fd's are used when doing diff <(cat old) <(cat new)?

If I do: diff <(cat old) <(cat new) Hoe does that work internally for the diff program? And how I do the same trick with a bash script?
7
votes
1answer
267 views

stderr over ssh -t

This sends output to STDERR, but does not propagate Ctrl+C (i.e. Ctrl+C will kill ssh but not the remote sleep): $ ssh localhost 'sleep 100;echo foo ">&2"' This propagates Ctrl+C (i.e. ...
2
votes
0answers
15 views

Is it safe to create a regression test that relies on running out of file descriptor limit?

I'm writing a regression test for my modification of Nmap and I'm wondering if it's a good idea to create a test that would basically perform a large-scale connect() scan on 127.0.0.1/8, which would ...
2
votes
2answers
233 views

Any way in Bash to write to a file every X seconds without closing it?

The hardware watchdog on my system needs a 0 written to /dev/watchdog at less than 60 seconds interval or it will fire. The file handle must be kept open however or the watchdog is then disabled. ...
2
votes
1answer
217 views

closing the unwanted file descriptors

I am trying to understand how pipes work . This code snippet is from some website . So my understanding of the program goes like this : When we do pipe(fd) then fd[0]=3 and fd[0]=4 ( assuming only ...
3
votes
0answers
64 views

Some puzzles of how to close file descriptors on sh or bash [duplicate]

Question 1. What will happen if we close a input file descriptor as if it is a output file descriptor? (or vice versa). For Example, $ exec 5<&2 $ exec 5>&- In my linux box, ...
4
votes
2answers
589 views

Process substitution from curl to bash as root

I'm trying to run a script from URL as root with this command: sudo bash <(curl -s http://copy.com/gLVZIqUubzcS/popcorn) But I'm getting this error: bash: /dev/fd/63: Aucun fichier ou dossier ...
5
votes
2answers
505 views

Portability of file descriptor links

I've always wondered this but never took the time to find out, so I'll do so now - how portable is the usage shown here of either /proc/$$/fd/$N or /dev/fd/$N? I understand POSIX guarantees /dev/null, ...
2
votes
4answers
106 views

Can a running script identify the logging context?

Let us say I redirect the STDOUT, STDERR of a program to files. ./script.sh 1> output.log 2> error.log Can the running program find this out i.e. know the paths to these files?
2
votes
2answers
1k views

Close all file descriptors in bash

Is there a way to close all the open file descriptors, without having an explicit list of them beforehand?
2
votes
3answers
146 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 ...
3
votes
1answer
492 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
190 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 ...
4
votes
3answers
747 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 ...
3
votes
1answer
76 views

What is the relationship between a program's output, standard output, and its file descriptors?

Let's assume that I am running wget which is downloading something. It's printing some text to my terminal and writes the downloaded data into a file. From a terminology point of view, what is the ...
1
vote
0answers
210 views

Which socket is gnome-shell reading from continuously?

strace shows that the GNOME shell is continuously trying to read from a socket, which is often not available (or doesn't contain any data to read from): strace -p gnome-shell-pid -e trace=recvfrom ...
11
votes
2answers
206 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 ...
4
votes
2answers
478 views

Does OpenBSD have a limit to the number of file descriptors?

What's the maximum number of file descriptors that a process can get on OpenBSD successfully? For example, there is an openfiles limit in login.conf(5) in OpenBSD. If I want to have as many file ...
3
votes
3answers
98 views

Print a message from the left-hand side of a pipe

I want to use a variable from the main shell in a sub shell. I did: export mysql_root_password="test" ( echo $mysql_root_password ) | dialog --gauge "Working hard..." 6 50 There is no output. ...
4
votes
1answer
314 views

Why doesn't the process substitution <() work with ssh -F

I have some vagrant virtual machines. To log into them I issue the vagrant ssh command. I want to log into them using regular ssh command. The vagrant ssh-config outputs the suitable config file $ ...
2
votes
2answers
389 views

AIX open() : file descriptor is zero (!?)

A daemon process, on detecting the presence of a text file in a particular directory then launches an executable file which opens the aforementioned text file in order to read and then transmit its ...
0
votes
0answers
273 views

Embedded device GadgetFS connects to Linux machine and receives one USB setup request more than with a windows machine connected

I am using this GadgetFS implementation http://www.linux-usb.org/gadget/usb.c to have my embedded device connect to a Host. What's weird is, when I connect it to a Windows machine everything works ...
5
votes
1answer
108 views

Replacing stdout with stderr

Is it possible to redirect the output from a command to replace the text sent to stdout with the text from stderr? $ ./script this line is redirected to stdout this line is redirected to stderr $ ...
3
votes
2answers
1k views

File descriptor and fork

When a child is forked then it inherits parent's file descriptors, if child closes the file descriptor what will happen ? If child starts writing what shall happen to the file at the parent's end ? ...
6
votes
1answer
3k views

How to circumvent “Too many open files” in debian

If I want to see all relevant log files of my apache2 server at once, I use tail -f /var/kunden/logs/*log /var/kunden/logs/*log /var/log/apache2/*log |grep -v robots|grep -v favicon But since those ...
5
votes
1answer
2k views

Limits on the number of file descriptors

I'm trying to install 389-ds, And it gives me this warning : WARNING: There are only 1024 file descriptors (hard limit) available, which limit the number of simultaneous connections. I understand ...
2
votes
1answer
2k views

How to find speed of wlan interface?

I'm trying to find speed of network interface using file-descriptor. It's easy to do it for ethX, just calling cat /sys/class/net/eth0/speed. Unfortunately this method doesn't work with wireless ...
4
votes
2answers
473 views

Cross-process dup on Linux

I'd like to dup a file descriptor running in an unrelated process on Linux. I know about sendmsg(2) and SCM_RIGHTS (e.g. ...
4
votes
3answers
1k views

Something's special about /dev/fd/3

I've been trying to learn about file descriptors. When I type "ls -l /dev/fd/" I get lrwx------ 1 me users 64 May 2 16:02 0 -> /dev/pts/5 l-wx------ 1 me users 64 May 2 16:02 1 -> ...
1
vote
3answers
1k views

How to check which process is using a given file descriptor?

Somewhere in the middle of my application, the framework I'm using (ROOT) gives me the following error: *** Break *** write on a pipe with no one to read it SysError in ...
2
votes
1answer
322 views

open() console for default file descriptors

I'm reading a shell program implementation in C ( the xv6 shell from MIT's 6.828 Operating System Engineering course ). The main() function for this shell starts with the following code: //Assumes ...
14
votes
2answers
13k 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.
1
vote
1answer
481 views

Understand file descriptors and nodejs

I'm having a bit of a confused time understanding what a file descriptor is and if I even need one! I am trying to spawn a process in nodejs and have its out put be written directly to an out put ...
2
votes
1answer
137 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. ...
12
votes
3answers
851 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 ...
3
votes
1answer
257 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
2answers
768 views

What sets a child's STDERR, STDOUT, and STDIN?

If a program runs fork() what sets standard streams STDOUT, STDIN and STDERR?
0
votes
2answers
212 views

Why doesn't Bash accept `&>&3`, i.e. redirecting stdout and stderr to file descriptor 3?

Given the preamble, foobar function and invocations of it: exec 3>/dev/null function foobar { echo foo; echo bar >&2; } foobar >/dev/null foobar 2>/dev/null foobar ...
2
votes
1answer
68 views

How is the inherited file descritor vulnerability dealt with in Unices?

Ulrich Drepper describes a vulnerability in programs that have open file descriptors then they fork() and execve() without lots of very careful locking in place. He also talks about new kernel ...
2
votes
2answers
172 views

Where to place a Bash shell redirection for a command? [duplicate]

Possible Duplicate: Order of redirections Apart from the standalone exec >&2 to redirect the current shell's input and output are there any behavioral differences in the following ...
5
votes
1answer
514 views

Timestamp of socket in /proc/<pid>/fd

If I list /proc/<pid>/fd I see a number of entries for sockets. These entries have timestamps. At first I thought they were when the socket was created. But it doesn't always appear to be the ...