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, ...
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 ...
16
votes
Why do special device files have inodes?
Device files have permissions, too, and those are stored in an inode.
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 ...
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 ...
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
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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
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 ...
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 ...
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 ...
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 .* *
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....
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 ...
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 ...
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 ...
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.
...
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, ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
stat × 193linux × 39
filesystems × 35
files × 32
timestamps × 23
bash × 22
find × 20
ls × 19
inode × 12
date × 9
macos × 8
permissions × 7
coreutils × 6
shell × 5
command-line × 5
mount × 5
disk-usage × 5
ext4 × 5
time × 5
ubuntu × 4
directory × 4
solaris × 4
symlink × 4
system-calls × 4
bsd × 4