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/...
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 | ...
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 ...
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 (...
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 ...
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!...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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
...
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 ...
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 ...
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 ...
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 ...
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.
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 ...
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 ...
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" ...
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.
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 ...
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+...
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 ...
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 ...
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 ...
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.
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
inode × 344filesystems × 134
linux × 64
ext4 × 56
files × 48
hard-link × 25
directory × 19
disk-usage × 19
ls × 12
stat × 12
debian × 11
find × 10
data-recovery × 10
ubuntu × 8
permissions × 8
symlink × 8
rm × 8
centos × 7
linux-kernel × 7
mount × 7
memory × 7
btrfs × 7
file-metadata × 7
ext2 × 7
debugfs × 7