The tag has no usage guidance.

learn more… | top users | synonyms

1
vote
1answer
26 views

How to get file descriptor number of a output and how to redirect all of them at once

Lets take this command for example $ time ssh ec2 ls www apps real 0m0.554s user 0m0.004s sys 0m0.000s $ time ssh ec2 ls 1>/dev/null real 0m0.554s user 0m0.004s sys 0m0.000s ...
3
votes
1answer
32 views

Opening more than 10 file descriptors with ksh

The shell syntax for opening a file for writing and using its file descriptor is: exec 3>output.log With bash and zsh you also can write: exec 13>output.log Thus, later in your script you ...
11
votes
2answers
132 views

What is the difference between &6 and /dev/fd/6?

To read from file descriptor 6 I can use <&6 or </dev/fd/6 (aka /proc/self/fd/6). Usually both work equally well. However if that file descriptor happens to be a socket, strange things ...
1
vote
1answer
30 views

Problem about file descriptor

I am doing a project. But I found in the source code there are so many file descriptor left unclosed. The first glance of it, I thought this is not good. After I googled, someone says, if there are ...
5
votes
2answers
313 views

Running remote command with ssh getting “bash: /dev/fd/63: No such file or directory”

I have /root/test.sh on a remote server, which has the following content: #!/bin/bash date On the remote server, I get the following output: # ./test.sh Fri Dec 18 07:41:10 EST 2015 # bash ...
4
votes
5answers
218 views

File descriptors across exec

By default file descriptors remain open across the exec functions. The benefit is perhaps understandable for descriptors 0-2. But is there a practical use case for keeping other descriptors open? Are ...
4
votes
2answers
57 views

Do redirections operate on file descriptors or file handles?

From https://www.gnu.org/s/bash/manual/html_node/Redirections.html Before a command is executed, its input and output may be redirected using a special notation interpreted by the shell. ...
3
votes
1answer
55 views

Duplication of file descriptors in redirection

From https://www.gnu.org/software/bash/manual/html_node/Redirections.html Bash handles several filenames specially when they are used in redirections, as described in the following table: ...
3
votes
1answer
55 views

Need Explanation For Multiple Arguments And Input Redirection With Cat

Files along with their contents:- ~$cat a aaa aaa aaa ~$cat b bbb bbb bbb ~$cat c ccc ccc ccc Commands that I need explanation:- ~$cat 0< a aaa aaa aaa ~$cat 0< a b bbb bbb bbb ~$cat 0< a ...
11
votes
4answers
371 views

Program output redirection

When trying to redirect program output with the "some number greater than" syntax (eg foo 2> myfile), what are the possible numbers here and what do they represent? I believe 1 is /dev/stdout, 2 ...
1
vote
0answers
21 views

Etymology of “descriptor” in “file descriptor”

The choice of the word descriptor has always struct me as odd. "Index" or "id" seem like more obvious alternatives. Is there a known rationale for the choosing the word "descriptor"? I guess ...
4
votes
2answers
48 views

Tar is currently reading a 2GB file, and I deleted its only link. How do I stop it from running for an eternity?

Some more information: I was backing up a large directory with tar, only there were a couple of large files there that I didn't expect. This connection is over the network and very slow, so simply ...
1
vote
1answer
72 views

File descriptor to read kernel log messages?

I am using syslog to read kernel log messages with SYSLOG_ACTION_READ. I would like to know if it's possible to "obtain" a file descriptor to "something" that would send the kernel logs (like what ...
-1
votes
2answers
82 views

How do I Capture dd command output

I have a test script, which is used to estimate the filesize for a particular oracle export dumpfile. Content of the script is: mknod exp.pipe p dd if=exp.pipe of=/dev/null bs=1024 & exp ...
3
votes
4answers
71 views

How to link a log file to /dev/null and restore the space used automatically

I have a logfile which grows huge. The information that I can get from it is negligible. I want to link it to /dev/null. However, even if it is "deleted" (see below the output of lsof), it consumes ...
4
votes
2answers
90 views

SSH: Provide additional “pipe” fds in addition to stdin, stdout, stderr

When connecting to a host with SSH, usually three "pipes" are provided between host and guest, for stdin, stdout, and stderr. Is there a command-line option to create forwards for additional file ...
1
vote
3answers
154 views

in bash script; a process stdout as filename argument fails when you open it more than one time

Consider this bash script code: #!/bin/bash function bug_part() { cat $1 > sample.first cat $1 > sample.second #second time you open file $1, it contains no data } bug_part <(echo ...
0
votes
1answer
26 views

Special file descriptors

In shell scripting, are any file descriptors other than 0, 1 and 2 special in any way? The flock manpage has the following example code: ( flock -n 9 || exit 1 # ... commands executed ...
2
votes
1answer
156 views

Strace - Filedescriptor 3

I am not sure what the filedescriptor number 3 means here? Is this descriptor some kind of pointer to the connection made to the harddrive to get the file datlog.txt? I guess so because the subroutine ...
0
votes
0answers
30 views

writefile() to file descriptor produces output with alignment issue

The command that produces weird output: $ vim -ec 'call writefile(["line1","line2"],"/proc/self/fd/9") | qall!' 9>&1 1>/dev/null 2>&1 line1 line2 $ Same command ...
1
vote
1answer
204 views

How can a file descriptor be reclaimed and reused later?

In context of C and C++, is the close() system call the only way for kernel to reclaim the fd and reuse it later when calling open() in the same process lifetime? What about multi-threaded programs?
2
votes
0answers
132 views

Process exceeding max open files limit

I am counting current open files by a process pid by :- cmd1:- ls /proc/$pid/fd/* | wc -l and then I am calculating percentage by fetching Max open Files limits. cmd2:- $ cat /proc/$pid/limits ...
9
votes
1answer
207 views

OS X, bash: less works on open file descriptors, cat doesn't

In a bash script I'm working on (which has to run on Ubuntu and OS X), I need to redirect the output of hundreds of commands to a file. Rather than appending &>... to all of them, I simply do ...
0
votes
1answer
107 views

Who opened a file descriptor? (socket)

I am using strace to track a program. In this line: recvfrom(7, "\0\260R\0\0\1\364\6\215\r\257\330\210\341\0\270\240\0\260R\0\0\0\0\0\0\0\0\0\0\0\0"..., 3000, 0, {sa_family=AF_PACKET, proto=0x88e1, ...
2
votes
1answer
403 views

File descriptor limits in /etc/system vs /etc/sysctl.conf vs /etc/security/limits.conf on Solaris

Let me explain first what I understood. In Solaris 10, rlim_fd_max and rlim_fd_cur in /etc/system set the hard and soft limits at the system level. And /etc/security/limits.conf sets the limits for ...
4
votes
5answers
1k views

Testing if a file descriptor is valid

I'd like to make a bash script output additional information to file descriptors (FDs) greater than or equal to 3, when they are open. To test whether an FD is open, I devised the following trick: if ...
0
votes
1answer
36 views

FDs more than 2, more than (stdin/stdout/sterr)

I think this post is not off-topic.We had three traditional file descriptors in Unix contexts: 0 == STDIN 1 == STDOUT 2 == STDERR But in new articles, blogs, posts, answers, or so on, I read more ...
0
votes
2answers
583 views

How to display open file descriptors with thread id but not using lsof command

How to display open file descriptors with thread id but not using lsof. I know a similar question exists but the answer doesnt include thread details.
2
votes
1answer
131 views

understanding “dpkg --status-fd n”

From man dpkg (1.16.16 (i386) on a Debian (7) based Linux Distro): --status-fd n Send machine-readable package status and progress information to file descriptor n I read this ...
1
vote
1answer
28 views

Propose additional file descriptor “stdmeta” [closed]

I know that one can define additional file descriptors for ad-hoc use. However, I see real use for a "stdmeta" file descriptor that would be supported by common CLI tools. This file descriptor would ...
1
vote
2answers
318 views

why nginx holds file descriptions of logs?

on Red Hat Enterprise Linux Server release 6.6 (Santiago) nginx version: nginx/1.0.15 I use common nginx logrotate config, logrotate works fine and nginx creates new log file like access.log or ...
2
votes
4answers
308 views

What is an open file description?

When you fork a process, the child inherits its parent's file descriptors. I understand that when this happens, the child receives a copy of the parent's file descriptor table with the pointers in ...
-1
votes
1answer
104 views

Accessing array elements within process substitution bash

I've got a text file which looks like this: b4238ca2-cb8d-11e4-8731-1681e6b88ec1,https,username,password,ipaddress b4238f0e-cb8d-11e4-8731-1681e6b88ec1,https,username,password,ipaddress ...
1
vote
3answers
110 views

Store stdout and stderr in file, then recreate the output later

I've redirected output to a file like so: $ ./test.bash 2> >(sed 's/^/stderr: /' >> output) > >(sed 's/^/stdout: /' >> output) $ cat output stdout: Hello World! stderr: ...
11
votes
2answers
325 views

find out which file descriptors share the same “open file description”

If I do (in a Bourne-like shell): exec 3> file 4>&3 5> file 6>> file File descriptors 3 and 4, since 4 was dup()ed from 3, share the same open file description (same properties, ...
4
votes
1answer
574 views

Why did sshd delete my /dev/zero?

When I do lsof +c 0 | grep /dev/zero, I see the following two lines: sshd 19064 root DEL REG 0,4 497862 /dev/zero sshd 19064 root DEL REG 0,4 498725 /dev/zero ...
3
votes
5answers
638 views

Reading from file descriptor fails

This question is about reading and writing on a file descriptor. See the following example: #!/bin/sh file='somefile' # open fd 3 rw exec 3<> "$file" # write something to fd 3 printf ...
3
votes
1answer
85 views

termios settings after closing file

Are the settings altered by functions from termios.h kept after file is closed and open again? I want to use serial communication in a higher level language (Racket) which exposes only reading and ...
2
votes
1answer
168 views

Behaviour of 1>&0 in bash

So I am trying to learn more about file descriptors and their redirections. At the moment I am exploring an edge case of doing 1>&0 and I cannot quite understand what is happening there. $ ...
4
votes
2answers
954 views

How does Bash get the output of an executed program?

When I execute a program in Bash, for example, [ls][2], it sends its output to standard output (fd &1). And the ouput of the executed program is displayed in the terminal. How does Bash/terminal ...
1
vote
2answers
104 views

Map reading/writing a file to getting output from/sending input to a script?

Suppose I have two scripts, script1.sh and script2.sh. I am wondering if there is a way to make a filesystem interface such that, for example, I can go vim file and then have my system run script1.sh ...
2
votes
1answer
171 views

Capturing data from a Fluke 1620a via Bash /dev/tcp file descriptor

I am currently trying to develop a script that will connect to a Fluke DewK 1620a Themo-Hygrometer and pull the current temperature and humidity readings from the device. While these devices have a ...
2
votes
2answers
205 views

How to print total number of file descriptors with index 24

How can I print the total number of file descriptors with index 24 for all the running processes on Linux? I tried $ ls /proc/*/fd 2> errors.txt > stdout.txt | grep "^24" stdout.txt | wc -l ...
6
votes
2answers
611 views

How to read user input when using script in pipe

General problem I want to write a script that interacts with the user even though it is in the middle of a chain of pipes. Concrete example Concretely, it takes a file or stdin, displays lines ...
2
votes
1answer
60 views

Forcing write(2) to return 0

I am writing unit tests and would like to test some code's handling of the case where a call to write(2) returns zero. As ever, it would be nice to keep the test as authentic as possible. I can use a ...
5
votes
5answers
8k 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 ...
51
votes
2answers
3k 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
142 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 ...
3
votes
2answers
683 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 ...
6
votes
3answers
2k 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 ...