Skip to main content
39 votes
Accepted

What is a "weird file"?

(Assuming GNU...) If stat couldn't tell what type it is (directory, (empty) regular file, link, socket, ...), it says weird file. I’d guess filesystem corruption and suggest fsck. In 2014, ...
muru's user avatar
  • 77.9k
35 votes

Birth is empty on ext4

The xstat function never got merged into mainline. However, a new statx call was proposed later on, and was merged in Linux 4.11. The new statx(2) system call does include a creation time in its ...
muru's user avatar
  • 77.9k
16 votes

Why do special device files have inodes?

Device files have permissions, too, and those are stored in an inode.
Hauke Laging's user avatar
  • 94.5k
16 votes
Accepted

Why do special device files have inodes?

The short answer is that it does only if you have a physical filesystem backing /dev (and if you're using a modern Linux distro, you probably don't). The long answer follows: This all goes back to ...
Austin Hemmelgarn's user avatar
13 votes
Accepted

On what UNIX-like system / filesystem is the st_blocks field returned by stat() not a number of 512-byte units?

st_blksize is called "the optimum I/O size" and unrelated to the units used for st_blocks. The optimum I/O size of course is filesystem specific. This is a result from the fast filesystem ...
schily's user avatar
  • 19.7k
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

Birth is empty on ext4

As of version 8.31 of GNU coreutils, stat “now prints file creation time when supported by the file system, on GNU Linux systems with glibc >= 2.28 and kernel >= 4.11.” My OS (Ubuntu 20.04, which ...
Kevin Li's user avatar
  • 231
12 votes

Why do special device files have inodes?

Directories are simply a mapping from filenames to inodes, so everything about the thing that the name refers to (a file, a symlink, a device, a FIFO, a socket) has to be in the inode, there's nowhere ...
Barmar's user avatar
  • 10.6k
11 votes
Accepted

Why does wc and stat produce different results for /proc/[pid]/cmdline?

The files under /proc are not regular your usual files, but virtual things created on the fly by the kernel. For most (all?) of them, the system doesn't bother calculating a size beforehand, but a ...
ilkkachu's user avatar
  • 148k
11 votes

Why does stat show different timezones corresponding to different files?

In that answer, note that OP says: I'm on the east coast of the United States, so I'm 4 hours behind UTC time [...] NOTE: Currently we just changed from EST to EDT for day light savings time. The ...
muru's user avatar
  • 77.9k
10 votes
Accepted

Get mtime Epoch timestamp with milliseconds from `stat`

For the GNU Coreutils implementation, you can use stat --format='%.9Y' file or just stat --format='%.Y' file From the info documentation: The ‘%W’, ‘%X’, ‘%Y’, and ‘%Z’ formats accept a precision ...
steeldriver's user avatar
  • 83.8k
9 votes
Accepted

Why is st_blocks always reported in 512-byte blocks?

st_blocks is defined as Number of blocks allocated for this object. The size of a block is implementation-specific. On Linux it’s always 512 bytes, for historical reasons; in particular, it used to ...
Stephen Kitt's user avatar
9 votes
Accepted

Change file "Birth date" for ext4 files?

Like the last change time, the birth time isn’t externally controllable. On file systems which support it, the birth timestamp is set when a file is created, and never changes after that. If you want ...
Stephen Kitt's user avatar
9 votes

Apply arithmetic into piped command

Use NUL-delimited records (-print0 for find, -0 for xargs) to process file lists, not lines as newline is as valid as any other character (or non-character) in a file path. Since you're already using ...
Stéphane Chazelas's user avatar
7 votes
Accepted

Meaning of statement that 'getcwd functions work correctly' in FreeBSD man page for mount_nullfs?

The primary differences between a virtual copy of the file system and a symbolic link are that the getcwd(3) functions work correctly in the virtual copy, getcwd’s behaviour with symlinked ...
Stephen Kitt's user avatar
6 votes
Accepted

File name too long error with command 'stat'

-0 to xargs doesn't make much sense if you don't also change the input to be 0-separated. Try find ~ -type f -iregex '.*python.*\.pdf' -print0 | xargs -0 stat -x
Henrik supports the community's user avatar
6 votes
Accepted

stats does not work with spaces?

Quote your variables in bash, not doing them will split your words in the variable to individual tokens and the command that uses that variable will be getting multiple words when it was expected a ...
Inian's user avatar
  • 13.1k
6 votes

file block size - difference between stat and ls

After digging into the source code and POSIX standard, I would say the answer by @antje-m and @Gilles are mostly correct. It's worth to quote the comment from POSIX.1-2008, as a summary: The use of ...
Eddy Xiao's user avatar
  • 171
6 votes
Accepted

How to use stat or bash to check whether FILENAME refers to a file

The -f test will be true if the given name is the name of a regular file or a symbolic link to a regular file. The -h test will be true if the given name is the name of a symbolic link. This is ...
Kusalananda's user avatar
  • 356k
5 votes

How to include hidden files in stat command?

try this it show all files ".*" to show hidden files and "*" to show not hidden files stat -c%s .* *
Hatem Badawi's user avatar
5 votes
Accepted

Can bash read the "Date Added" of a file/directory?

Some candidates include the following. File times are exposed in metadata, and mdls is "metadata list". When used with the -raw option, output from mdls contains fields separated with an NUL character....
Christopher's user avatar
  • 16.3k
5 votes

What is the fastest way to fetch last modified TS on a file in bash?

If you have GNU find (the one that supports -printf). find /filesystem/mount/point -xdev -printf '%T@\t%p\0' > timestamps is going to be the fastest. find is highly optimised to traverse directory ...
Stéphane Chazelas's user avatar
5 votes
Accepted

Why does stat show different timezones corresponding to different files?

There are many different implementations of a stat utility, all incompatible between each other, but most of them, when they display file timestamps do it in local time. The GNU implementation of stat ...
Stéphane Chazelas's user avatar
5 votes

Why does stat show different timezones corresponding to different files?

Different files appear with different timezones! Others have provided detail, but addressing this point directly - your statement is incorrect, because these are not different timezones, they're ...
Simon Geard's user avatar
4 votes

Meaning of statement that 'getcwd functions work correctly' in FreeBSD man page for mount_nullfs?

I think they mean that if /tmp/a is a symlink to /some/dir and /tmp/b is a nullfs mount of /some/dir, after chdir("/tmp/a"), getcwd() returns /some/dir. after chdir("/tmp/b"), getcwd() returns /tmp/b. ...
Stéphane Chazelas's user avatar
4 votes
Accepted

Unable to stat itself when running a bash script

This: BOOTSTRAP_MODIF="stat -c %Y '/home/agrillet/a'" Sets the variable BOOTSTRAP_MODIF to the string stat -c %Y '/home/agrillet/a'. It doesn't produce any output. If you expand the variable later, ...
ilkkachu's user avatar
  • 148k
4 votes
Accepted

Why is the number of ticks inaccurate?

The difference results from truncating the values after calculating the sums. /proc/stat calculates the sums of elapsed times in nanoseconds, and then converts the resulting values to USER_HZ using ...
Stephen Kitt's user avatar
4 votes

What is file block size in Linux?

The st_blksize field returned by stat() gives the "the preferred blocksize for efficient file system I/O." (from the stat man page). The value should be interpreted as a hint that you should read and ...
Johan Myréen's user avatar
4 votes
Accepted

Creation time anomaly

The ctime and crtime cannot be tampered with, the atime and mtime can be set by user processes to arbitrary values using the utime() or utimes() (or utimensat() for nanosecond precision) system calls ...
Stéphane Chazelas's user avatar

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