Given a file descriptor, is there a way in Linux to find out how many other file descriptors refer to the same file description (i.e. how often dup was called, not how often open was called)?  I do not need to know which ones (they might be even in a different process by now). In fact I'd be quite happy knowing whether there are ANY or if this fd is a unique reference.
124067
If I do (in a Bourne-like shell):  exec 3&gt; file 4&gt;&amp;3 5&gt; file 6&gt;&gt; file   File descriptors 3 and 4, since 4 was dup()ed from 3, share the same open file description (same properties, same offset within the file...). While file descriptors 5 and 6 of that process are on a different open file description (for instance, they each have their own pointer in the file).  Now, in lsof output, all we see is:  zsh     21519 stephane    3w   REG  254,2        0 10505865 /home/stephane/file zsh     21519 stephane    4w   REG  254,2        0 10505865 /home/stephane/file zsh     21519 stephane    5w   REG  254,2        0 10505865 /home/stephane/file zsh     21519 stephane    6w   REG  254,2        0 10505865 /home/stephane/file   It's a bit better with lsof +fg:  zsh     21519 stephane    3w   REG          W,LG  254,2        0 10505865 /home/stephane/file zsh     21519 stephane    4w   REG          W,LG  254,2        0 10505865 /home/stephane/file zsh     21519 stephane    5w   REG          W,LG  254,2        0 10505865 /home/stephane/file zsh     21519 stephane    6w   REG       W,AP,LG  254,2        0 10505865 /home/stephane/file   (here on Linux 3.16) in that we see fd 6 has different flags, so it has to be a different open file description from the one on fd 3, 4 or 5, but from that we can't tell fd 5 is on a different open file description. With -o, we could also see the offset, but again same offset doesn't guarantee it's the same open file description.  Is there any non-intrusive1 way to find that out? Externally, or for a process' own file descriptors?    1. One heuristic approach could be to change the flags of one fd with fcntl() and see what other file descriptors have their flags updated as a result, but that's obviously not ideal nor fool proof
18295
Could anyone tell me what is up with so many archives, and how are they differ?  There's at least five that I can think of, .tar.tz, .tar.gz, .tar.bz2, .tar.lz, .tar.z  Which is best for what applications? It just seems silly to make so many variations of the same file but I'm sure there's a reason.
57411
How could I detect (preferably with Python) duplicate MP3 files that can be encoded with different bitrates (but they are the same song) and ID3 tags that can be incorrect?  I know I can do an  checksum of the files content but that won't work for different bitrates. And I don't know if ID3 tags have influence in generating the MD5 checksum. Should I re-encode MP3 files that have a different bitrate and then I can do the checksum? What do you recommend?
80106
I want to see how many files are in subdirectories to find out where all the inode usage is on the system. Kind of like I would do this for space usage  du -sh /*   which will give me the space used in the directories off of root, but in this case I want the number of files, not the size.
3576
I cant find any documentation or articles online online for this...  how does Windows handle page files on multiple hard drives?  Does windows treat them as a concatenation, writing to one till its full then moving to the next?  Or does it treat them like a stripe, writing to each one incrementally?  Does it write to the first one free?  Or perhaps some other method?
84447
Let's say when I do ls -li inside a directory, I get this: 12353538 -rw-r--r-- 6 me me 1650 2013-01-10 16:33 fun.txt  As the output shows, the file fun.txt has 6 hard links; and the inode number is 12353538. How do I find all the hard links for the file i.e. files with the same inode number?
111314
I have 4 hard disks and want to find out which files on this four harddisks (including sub directories) are duplicates. It should be checked not only within a harddisk but against all the others as well.  The hard disks are large (3TB) therefor it has to be efficient (first filename than checksum checks or so)
106886
In the bash tutorial I am reading, it says that if you open a file descriptor for reading, i.e.  exec 3&lt; echolist   Then you must close it like this,  exec 3&lt;&amp;-   However, if you open a file descriptor for writing, it must be closed like this:  exec 3&gt;&amp;-   Yet when I look on the internet, I see people opening files and then closing them with this:  exec 3&gt;&amp;-    NOTE: when, according to the tutorial, they should be using exec 3&lt;&amp;1.  So my question is, can all file descriptors be closed via exec n&gt;&amp;- where n is the file descriptor number? Regardless if it was opened for reading, writing, or both?
55005
What would be the best way to list 100 first files in a directory sorted by the created timestamp (oldest first). The directory is quite large (around 100000 files). ls piped to head takes an awful long time to complete.   Edit:  Filesystem is ext3. limiting the number of files in the folder is not worth the effort, since this is going to be a rare "clean-up" operation and files are generated by a 3rd party software.   Using file modified time, instead of the creation time provides and acceptable solution.
109892
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 the file descriptor in another one:  $ tail -f /proc/3844/fd/1   It doesn't print anything to the screen and hangs until ^c. Why?  Also, all of the STD file descriptors (IN/OUT/ERR) link to the same pts:  $ ls -l /proc/3844/fd/ total 0 lrwx------ 1 mg mg 64 sie 29 13:42 0 -&gt; /dev/pts/14 lrwx------ 1 mg mg 64 sie 29 13:42 1 -&gt; /dev/pts/14 lrwx------ 1 mg mg 64 sie 29 13:42 2 -&gt; /dev/pts/14 lr-x------ 1 mg mg 64 sie 29 13:42 254 -&gt; /home/user/test.sh lrwx------ 1 mg mg 64 sie 29 13:42 255 -&gt; /dev/pts/14   Is this normal?  Running Ubuntu GNOME 14.04.  If you think this question belongs to SO or SU instead of UL, do tell.
119823
Close vote notice: While the linked duplicate asks same question, the comments and the only answer do not provide an answer which draws from authoritative source. The , does in fact provide the answer I've been seeking. Thus the proposed duplicate isn't helpful, however Thomas's answer here is proper.  According to the  and personal account , directories that have large amount of entries get to a size over 4096 bytes (which can be seen with ls -l output), but once the entries are removed - the number never goes down.   The question is "why" ? Is it due to how ext4 filesystem configured to retain directory metadata ? Obviously removing the directory and recreating it isn't a solution, since it deletes original inode and creates a new one. What can be done to decrease the number manually ?
73424
$ apropos mkfifo mkfifo (1)           - make FIFOs (named pipes) mkfifo (1posix)      - make FIFO special files mkfifo (3)           - make a FIFO special file (a named pipe) mkfifo (3posix)      - make a FIFO special file mkfifoat (3)         - make a FIFO (named pipe) relative to a directory file ...   So I have man pages for Linux Programmer’s Manual and POSIX Programmer’s Manual. Which should I prefer and why? (I'm writing a Linux application, no plans to port it AIX, BSD etc)  Thanks.
70238
In the upcoming Java7, there is a  to check if two file object are same file reference.  Are there similar API provided in the .NET framework?  I've search it over MSDN but nothing enlighten me.  I want it simple but I don't want to compare by filename which will cause problems with hard/symbolic links and different style of path. (e.g. \\?\C:\, C:\).   What I going to do is just prevent duplicated file being drag and dropped to my linklist.
56356
Pretty simple question: In Linux, why does Python require the line   #!/usr/bin/python   at the start of a python file, since Windows doesn't?  What does it do? 'cause the description "Links to Python" is a bit vague...
2885
Why does /proc/pid/maps contain a few records for the same library ? Here is an example:  7fae7db9f000-7fae7dc8f000 r-xp 00000000 08:05 536861                     /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20 7fae7dc8f000-7fae7de8f000 ---p 000f0000 08:05 536861                     /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20 7fae7de8f000-7fae7de97000 r--p 000f0000 08:05 536861                     /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20 7fae7de97000-7fae7de99000 rw-p 000f8000 08:05 536861                     /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20   What does this mean ?
19512
I have a largish music collection and there are some duplicates in there. Is there any way to find duplicate files. At a minimum by doing a hash and seeing if two files have the same hash.  Bonus points for also finding files with the same name apart from the extension - I think I have some songs with both mp3 and ogg format versions.  I'm happy using the command line if that is the easiest way.
106793
I have an application writing to an ext3 directory which over time has grown to roughly three million files. Needless to say, reading the file listing of this directory is unbearably slow.  I don't blame ext3. The proper solution would have been to let the application code write to sub-directories such as ./a/b/c/abc.ext rather than using only ./abc.ext.  I'm changing to such a sub-directory structure and my question is simply: roughly how many files should I expect to store in one ext3 directory while still getting acceptable performance? What's your experience?  Or in other words; assuming that I need to store three million files in the structure, how many levels deep should the ./a/b/c/abc.ext structure be?  Obviously this is a question that cannot be answered exactly, but I'm looking for a ball park estimate.