Linked Questions

37 votes
5 answers
38k views

How can same fd in different processes point to the same file?

Say I have process 1 and process 2. Both have a file descriptor corresponding to the integer 4. In each process however the file descriptor 4 points to a totally different file in the Open File Table ...
Pithikos's user avatar
  • 3,404
21 votes
2 answers
6k views

Why is the behavior of `command 1>file.txt 2>file.txt` different from `command 1>file.txt 2>&1`?

When you want to redirect both stdout and stderr to the same file, you can do it by using command 1>file.txt 2>&1, orcommand &>file.txt. But why is the behavior of command 1>file....
fhiyo's user avatar
  • 333
25 votes
3 answers
5k views

How does this script ensure that only one instance of itself is running?

On 19 Aug 2013, Randal L. Schwartz posted this shell script, which was intended to ensure, on Linux, "that only one instance of [the] script is running, without race conditions or having to clean up ...
user avatar
6 votes
4 answers
2k views

In Linux, is there a system layer/script that handles the opening of files?

in Linux, is there a layer/script that handles program-requests to open files? Like when you open a file-descriptor in bash: exec 3 <>/documents/foo.txtor your text-editor opens /documents/foo....
von spotz's user avatar
  • 515
7 votes
2 answers
13k views

What exactly is a file offset in lsof output?

I was using lsof to track down deleted files that were still taking up space and I realized that I wasn't quite sure what an offset is with respect to a file. lsof's man page was less than helpful in ...
Sean's user avatar
  • 305
7 votes
2 answers
19k views

What's the difference between ">&1" and ">/proc/self/fd/1" redirection?

I'm working on some script that being run by rc.local at startup, and I noticed that output redirection works quite strange. If I write something like echo "foo" >&1, it ends up in syslog, and ...
alexey.e.egorov's user avatar
12 votes
3 answers
2k views

What characterizes a file in Linux/Unix?

What characterizes a file in Linux/Unix? A file can have many types: regular file, directory, symlink, device file, socket, pipe, fifo, and more that I miss. For example, a symlink: $ sudo file /...
Tim's user avatar
  • 107k
6 votes
1 answer
776 views

Application behaves weirdly with `>>`, replaces lines instead of appending

The application itself is not in question, I am just wondering how the Bash around is not behaving as I expected it to, like somehow whatever behaviour this application has, it is leaking out in a way ...
Mathias Sven's user avatar
0 votes
2 answers
518 views

Redirecting stdout with > and stderr with >> to same file leaves out stderr

I'm redirecting stdout and stderr to the same file by using > and >> respectively: rsync -a --exclude cache/ src_folder/ target_folder/ 1>out_err.log 2>>out_err.log However the ...
bit's user avatar
  • 1,196
0 votes
1 answer
115 views

Understanding bash ‘<’ and ‘>’ with parentheses

Let's say we have a folder with two files: file_empty, containing nothing file_in, containing just one line: "something" See the output of the following examples: (echo "test" &...
Bastian's user avatar
  • 25