Skip to main content
47 votes
Accepted

How to effectively trace hardlink in Linux?

First, there is no original file in the case of hard links; all hard links are equal. However, hard links aren’t involved here, as indicated by the link count of 1 in ls -l’s output: $ ll -i /usr/bin/...
Stephen Kitt's user avatar
46 votes
Accepted

Why do the directories /home, /usr, /var, etc. all have the same inode number (2)?

They're on different devices. If we look at the output of stat, we can also see the device the file is on: # stat / | grep Inode Device: 801h/2049d Inode: 2 Links: 24 # stat /opt | ...
ilkkachu's user avatar
  • 148k
41 votes
Accepted

Does Linux support invoking a program directly via its inode number?

The short answer is no. The longer answer is that linux user API doesn't support accessing files by any method using the inode number. The only access to the inode number is typically through the ...
user10489's user avatar
  • 10.9k
40 votes
Accepted

Can two files on two separate filesystems share the same inode number?

An inode number is only unique on a single file system. One example you’ll run into quickly is the root inode on ext2/3/4 file systems, which is 2: $ ls -id / /home 2 / 2 /home If you run (...
Stephen Kitt's user avatar
40 votes
Accepted

Is '..' really a hard link?

It depends on the filesystem. Most filesystems follow the traditional Unix design, where . and .. are hard links, i.e. they're actual directory entries in the filesystem. The hard link count of a ...
Gilles 'SO- stop being evil''s user avatar
37 votes
Accepted

Why can't hard links reference files on other filesystems?

A "hard link" just is the circumstance that two (or more) entries in the hierarchy of your file system refer to the same underlying data structure. Your figure illustrates that quite nicely!...
Marcus Müller's user avatar
31 votes

Why can't hard links reference files on other filesystems?

The challenge with this question is that it's based on a falsehood. It's based on the idea that such a thing would be impossible under any circumstances. It's easy to imagine how this might work, so ...
Philip Couling's user avatar
27 votes
Accepted

Why is the inode table usually not resizable?

Say you did make the inode table a file; then the next question is... where do you store information about that file? You'd thus need "real" inodes and "extended" inodes, like an MS-DOS partition ...
derobert's user avatar
  • 113k
27 votes

How to create a hard link to an inode (ext4)?

AFAIK, not with the kernel API. If such an interface existed, it would have to be limited to the super-user as otherwise that would let anyone access files in directories they don't have search access ...
Stéphane Chazelas's user avatar
26 votes

Why do the directories /home, /usr, /var, etc. all have the same inode number (2)?

The inode number of any given file is unique to the filesystem, but not necessarily unique to all filesystems mounted on a given host. When you have multiple filesystems, you will see duplicate inode ...
John's user avatar
  • 17.4k
26 votes

Why doesn't read permission on directories reveal inode numbers?

As @muru has shown, you can definitely get the inode numbers (on any POSIX system, not just Linux) by reading the directory contents (whether directories are implemented as normal files like in the ...
Stéphane Chazelas's user avatar
25 votes

How to effectively trace hardlink in Linux?

how do I trace the original file or every hardlink using /usr/bin/bash file as reference With GNU find (or any other version of find that has the -samefile option), and assuming that /usr/bin/bash is ...
Gilles 'SO- stop being evil''s user avatar
23 votes
Accepted

How Linux kernel sees the filesystems

There is some confusion here because kernel source and documentation is sloppy with how it uses the term 'inode'. The filesystem can be considered as having two parts -- the filesystem code and data ...
user10489's user avatar
  • 10.9k
22 votes
Accepted

Reset ext4 filesystem without changing the filesystem UUID

Since you're using ext4 you could format the filesystem and the set the UUID to a known value afterwards. man tune2fs writes, -U UUID Set the universally unique identifier (UUID) of the filesystem to ...
Chris Davies's user avatar
21 votes

Quickly find which file(s) belongs to a specific inode number

btrfs man btrfs-inspect-internal says: inode-resolve [-v] <ino> <path> (needs root privileges) resolve paths to all files with given inode number ino in a given ...
Tom Hale's user avatar
  • 33.3k
21 votes
Accepted

Why directory with large amounts of entries does not shrink in size after entries are removed?

Quoting a developer (in a linux kernel thread ext3/ext4 directories don't shrink after deleting lots of files): On Thu, May 14, 2009 at 08:45:38PM -0400, Timo Sirainen wrote: > > I was rather ...
Thomas Dickey's user avatar
20 votes
Accepted

ncdu - Rank by File-Count instead of Size

If you press C (capital “C”, so ShiftC or C with Caps Lock on) while in ncdu, the display will be sorted by file count rather than size. c (lower-case “c”) will show the file count in addition to the ...
Stephen Kitt's user avatar
19 votes

Why is the inode table usually not resizable?

Many filesystems do have a dynamically allocatable inode table (or its moral equivalent) (XFS, BTRFS, ZFS, VxFS...) The original Unix UFS though had inodes that were fixed at filesystem creation time ...
BowlOfRed's user avatar
  • 3,937
19 votes

Does Linux support invoking a program directly via its inode number?

Yes, it is possible to execute a file by its inode: find / -inum 242 -exec {} \; -quit Performance motivated the question, though, and the above is not performant. Not only is the directory structure ...
bishop's user avatar
  • 3,249
17 votes

Reset ext4 filesystem without changing the filesystem UUID

You can use -U with mkfs.ext4 to specify your own UUID so when re-creating the filesystem you can simply reuse the previous UUID.
Vojtech Trefny's user avatar
17 votes

Reset ext4 filesystem without changing the filesystem UUID

Reusing UUIDs on ext3/ext4 for a new file system is a bad idea. The UUID is used in the inode checksum calculation to allow fsck to distinguish between inodes that belong to the current file system ...
Simon Richter's user avatar
15 votes

How do I count all the files recursively through directories

du --inodes (GNU version only) du --inodes --inodes List inode usage information instead of block usage. This option is useful for finding directories which contain many files, and therefore eat up ...
Sridhar Sarnobat's user avatar
14 votes

Reset ext4 filesystem without changing the filesystem UUID

Instead of re-using the UUID for each new filesystem, which has some negative implications for e2fsck, you could change your /etc/fstab to use the filesystem label to mount ("LABEL=testfs" ...
LustreOne's user avatar
  • 2,002
13 votes
Accepted

How come that inodes of directories store filenames in ext4 filesystem?

Directory entries are stored both in inode.i_block and the data blocks. See "Inline Data" and "Inline Directories" in the document you linked to.
Johan Myréen's user avatar
13 votes
Accepted

Deleting a hard link's tail file changes the change time of the head or vice versa. Why?

This is a requirement on the unlink() library function by POSIX: Upon successful completion, unlink() shall mark for update the last data modification and last file status change timestamps of the ...
Kusalananda's user avatar
  • 356k
12 votes

Why doesn't read permission on directories reveal inode numbers?

It does, at least on a Linux system I tried it on: Setup: mkdir foo touch foo/bar # remove as much permission as possible, so that the program still works (only leave `r`). chmod ugo-wx foo chmod ugo+...
muru's user avatar
  • 77.9k
11 votes

Find where inodes are being used

I find it quicker and easier to drill down using the following command: $ sudo du -s --inodes * | sort -rn 170202 var 157325 opt 103134 usr 53383 tmp <snip> You can then go in to var for ...
JonoB's user avatar
  • 211
11 votes
Accepted

Same file name different INODES

I was able to reproduce that behavior. See for example: ls -lib 268947 -rw-r--r-- 1 root root 8 Dez 20 12:32 app 268944 -rw-r--r-- 1 root root 24 Dez 20 12:33 aрр This is on my system (Linux debian ...
chaos's user avatar
  • 49.3k
11 votes
Accepted

How to copy a file by using its inode number?

All of open() (for copying), rename() and unlink() (removal) work by filenames. There's really nothing that would work on an inode directly, apart from low-level tools like debugfs. If you can remove ...
ilkkachu's user avatar
  • 148k
10 votes

How come that inodes of directories store filenames in ext4 filesystem?

cat outputs file contents, i.e. data blocks. Similar to /bin/cat. The cat command would not be useful if it wrote the bytes of the inode structure to the terminal. Compare inode_dump and stat. ...
sourcejedi's user avatar
  • 53.5k

Only top scored, non community-wiki answers of a minimum length are eligible