Questions tagged [stat]
The stat tag has no usage guidance.
170
questions
0
votes
0
answers
55
views
Change file creation timestamp on an exFAT volume from Linux
The question
As of today, Unix standards don't support a file "creation time" attribute. However, many filesystems, like ext4, exFAT and NTFS, internally do save a creation time for their ...
0
votes
2
answers
92
views
What is the fastest way to fetch last modified TS on a file in bash?
If you have a list of hundreds of thousands of files across an enormous filesystem, what's the fastest way in bash to get the last modified time of all of them?
Assuming there's no way to sort them ...
1
vote
0
answers
42
views
ls displays no files even though folder contains files
This question is actually derived from a problem I have with a python library which deletes a file tree and then recreates the content, but on attempt of execution of a file inside the directory, the ...
0
votes
4
answers
60
views
How to get date string from stat command?
I have this to get the timestamp of a directory:
stat -c %Y directory_name
What can I pipe this to, to get the date formatted like this?
20220201
0
votes
1
answer
71
views
"stat /etc" size mismatch: 24 blocks, size 8192 instead of 12288
My stat /etc command shows that the number of blocks is 24. I understand that a block here means 512 bytes. So the total size is 24 × 512 which makes it 12288 bytes.
But it shows 8192 bytes instead, ...
0
votes
1
answer
22
views
Changing rights and owner in one command to safe resources
I have a backup script with the following function:
function change_rights()
{
chown -R ${OWNER}:${GROUP} ${DIR}
find ${DIR} -type f -exec chmod 0640 {} \;
find ${DIR} -type d -exec chmod ...
0
votes
1
answer
223
views
Convert date format of a stat command output
With the command stat * --format='%A %h %U %G %s %z %n' I get:
-rwxrwxrwx 1 myuser mygroup 131072 2021-11-12 14:52:23.495595927 +0100 myfile
Is it possible to have a stat output like the following? ...
0
votes
2
answers
47
views
Can I post-format column tab sizes so that spacing is at lowest common denominator in Linux?
I can use stat to create an ls output that shows both formats of permission information which can be handy:
stat --printf="%A\t%a\t%h\t%U\t%G\t%s\t%.19y\t%n\n" . .*
drwxr-xr-x 755 ...
1
vote
0
answers
86
views
can't stat file more than once?
So I've got a bizarre error that occurs when I use ffmpeg.ffprobe on an MP4 file that is hosted my NAS.
When I login to a shell and switch to any directory on my network storage that contains a MP4 ...
8
votes
1
answer
507
views
On what UNIX-like system / filesystem is the st_blocks field returned by stat() not a number of 512-byte units?
I always assumed the st_blocks field returned by stat()/lstat()... system calls and which du uses to get the disk usage of files was expressed in 512 bytes units.
Checking the POSIX specification, I ...
0
votes
1
answer
40
views
How to monitor calls to stat?
I'd like to monitor calls to stat on any file within a directory. I know inotifywait can listen for file creation etc. but I don't know anything that can listen for stat. This is on Amazon Linux 2. ...
2
votes
1
answer
37
views
Ensuring no files were deleted from directory at a certain time
I accidentally started an rm -rf on a large directory that I was working in. The directory contains, among other things, a data directory containing a number of subdirectories that each contain ...
0
votes
1
answer
70
views
Can stat show if file is hidden?
I'm using stat like this:
stat -f "%Sp %p %l %Su %u %Sg %g %z %a %N %Y" /*
I need also to tell if the file is hidden or not (MacOS).
The . notation is not enough. MacOS hides more files.
...
0
votes
0
answers
24
views
Directory changed into a regular file upon a UI drag/drop, now how do I change it back?
I'm on Ubuntu 16.04LTS with the latest Linux kernel 4.4.0-206-generic from Canonical (which could be bugged), and I've never seen anything like this before!
Somehow, simply dragging and dropping a ...
0
votes
1
answer
251
views
`noatime` mount option's effect on `stat` access time
I have mounted ext4 partition in Ubuntu 20.04 with noatime mount option in my /etc/fstab
From stat: Access time doesn't change when the file is opened on the editor or modified and saved, while ...
1
vote
0
answers
170
views
How can I display nanoseconds with stat command on Unix?
I am using FreeBSD but it does not show nanoseconds for the file with stat command. The file system is ZFS.
stat -f "Access (atime): %Sa%nModify (mtime): %Sm%nChange (ctime): %Sc%nBirth (btime): ...
0
votes
1
answer
39
views
Ipad 4 mini Date says 12,31,1969
I used terminal code stat in my iPad, and it came back as show below. Why does it say that date, how can I fix this? And is there other things I should check?
GFY iPad 2 $ stat
0 9870584235507384862 ...
1
vote
1
answer
252
views
Birth time after Modify time in stat command
I have a folder with a Birth time later than its Modify time:
File: Pictures
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 804h/2052d Inode: 31724953 Links: 4
Access: ...
0
votes
1
answer
112
views
How do I read the terse outout of stat?
There are no clues given about how to interpret the results of running the stat command with terse output.
[root@kvm devicemapper]# stat -t data
data 107374182400 3887728 8180 0 0 fd01 559688 1 0 0 ...
2
votes
1
answer
776
views
Why is the type of stat.st_size not unsigned int?
I was trying to rely on the stat(2) system-call to determine the size of a file in order to allocate an appropriate buffer for it. More specifically I was using the stat.st_size of the structure that ...
0
votes
1
answer
114
views
Linux find command - find files based on inode and device?
I want to find the files with a given inode number. Using find with -inum is not entirely helpfull as its listing files with the inode number from every file system/device. How to confine this search ...
0
votes
1
answer
811
views
partition size vs file system size
I am writing a c++ program that I need to get partitions and hhd's total, free and used space. I'm so confused with all commands and codes that can be used to get these data from system and all ...
3
votes
1
answer
303
views
How are minor device numbers assigned for unnamed/non-device mounts (major number 0)?
I generally get how the whole major/minor device number thing works for a given device (though please correct me if I'm way off here), and how a major device number essentially relates to a class of ...
0
votes
0
answers
141
views
Inconsistent st_blocks and st_size values for inaccessible file
I have a small text file (some metadata redacted)
-rw-r--r-- 1 **** **** 17198 Sep 29 2019 230999.txt
But it can't be viewed
% cat 230999.txt
cat: 230999.txt: Attribute not found
I'm not sure ...
0
votes
1
answer
48
views
I did something to my bashrc or something in UNIX, not listed in sudoers file anymore and can not get access to directories
I am using REDHAT/CENTOS 6.5.
I used to have access to directories, but now when I try to go into them after I rebooted by UNIX, it tells me that permission is denied.
Using stat command on these ...
1
vote
2
answers
198
views
Find the age of the oldest file in one line
I tried
stat -c %Y ./* 2>/dev/null | awk -v d="$(date +%s)" 'BEGIN {m=d} $0 < m {m = $0} END {print d - m}'
to find the age of the oldest file in the current directory, and I get a number in ...
0
votes
1
answer
157
views
Using stat for time or date -r?
I have listed properties of a folder this way
stat -c $'--------------
File: %n
Size: %s
Owner: %U
Group: %G
Permissions: %A'
but I am having ...
0
votes
1
answer
53
views
How do I account for a variable number of extra arguments in a bash script?
It is set up so that $1 is the flag for what the program is going to do, $2 can be a username or anything else. This works great except for one thing: I have to be able to add a comment to a user, and ...
2
votes
0
answers
287
views
Portable way of finding files whose birth date is after a given timestamp
According to How to find creation date of file?, in Linux filesystems, such as ext4, Btrfs and JFS, that store the file creation time (aka birth time), it is possible to display the file birth time (...
1
vote
1
answer
2k
views
Change file "Birth date" for ext4 files?
Is it possible to change a file "Birth date" (according to the stat file "Birth" field)?
I can change the modification/access time with touch -t 200109110846 file, but can't find the corresponding ...
3
votes
2
answers
1k
views
How to use stat or bash to check whether FILENAME refers to a file
Does the stat command offer, or does bash offer, a straightforward way to check whether FILENAME refers to a file rather than, say, a directory?
Using bash and stat, here is my ugly solution:
if ...
1
vote
2
answers
253
views
How to get difference between 2 dates in Linux?
I know this is a common question, but I do not understand how the solutions provided work. Everyone advises to change the date to seconds from the epoch and then divide by (24 * 3600) to get the ...
5
votes
1
answer
5k
views
Get mtime Epoch timestamp with milliseconds from `stat`
If I'm using stat to display the mtime, I get a date with milliseconds:
$ stat -c '%y' test.log
2019-07-04 14:32:10.730059167 +0200
However, if I want to display the Epoch timestamp, I don't get ...
0
votes
2
answers
443
views
Chaining find exec and a while loop
I'm trying to stack a find command so that the results it returns only contains files with "warning:" or "error:" text within them. I also require those results in a specific format so I'm using exec ...
1
vote
1
answer
576
views
Stat -c command in UNIX
I am using the stat commands to show information of all files in a directory, by using the below commands in a script:
stat -c"%n|%s|%y" <FOLDER>/* | sed -r 'h; s/\|.*$//; s/^/wc -l </e; G;...
3
votes
1
answer
2k
views
Why is st_blocks always reported in 512-byte blocks?
I was debugging a fuse filesystem that was reporting wrong sizes for du. It turned out that it was putting st_size / st_blksize [*] into st_blocks of the stat structure. The Linux manual page for stat(...
-2
votes
1
answer
300
views
Bash Script general questions [closed]
The first part of what i am mucking around with simply creates a folder entitled command_manuals that contain text file copies of all the commands available at the bash shell, the filenames which are ...
1
vote
1
answer
445
views
Translating Linux stat(1) command into BSD stat(1) command
Background
CLion's remote project feature currently doesn't support FreeBSD as a remote host OS, but I want to do some hacking and see if it works. By reading the log file, I think I have spotted (...
4
votes
1
answer
881
views
Can bash read the "Date Added" of a file/directory?
With programs like stat you see access, modify and change, but with Finder on macOS there is a "Date Added" field. Can I get the "Date Added" for a file or directory displayed in the Terminal, like ...
1
vote
2
answers
3k
views
modify time for extracted folder
I just (today is 31-jan-2019) downloaded some random source.tar.gz and extracted it. When I do stat on the resulting folder, I see:
Access: 2019-01-31 10:37:26.308991485 +0100
Modify: 2018-11-18 00:...
6
votes
2
answers
251
views
Why does GNU Core Utilities stat (including du and ls) report the following sizes (ext4 in GNU/Linux)?
If I have the following contents in a directory:
empty_dir: Empty directory.
empty_file: Empty file.
one_char: File consisting of one character.
several_blocks: File consisting of several blocks (but ...
0
votes
3
answers
206
views
Using find to list directories that haven't been accessed since a certain date?
Using the stat command one can see and format the last date a directory was accessed. The adate
Is it possible to use find to find the directories that were changed before a certain date using a ...
2
votes
1
answer
1k
views
How to use istat on AIX like stat on Linux distributions
In Linux, I use the following command to show this output:
find /backup/$INSTANCE/tsm/* -exec echo '"{}" ' \; | xargs stat --printf "chown %U:%G '%n'\nchmod %a '%n'\n" >> /tmp/permissions.txt
...
6
votes
2
answers
269
views
Is it normal that bash stat() and access() much, before commands?
Running strace on the bash shell that is instructed to run mkdir provided this output which shows lots of stats prior to execve the actual mkdir binary:
BASH$> strace -f sh -c "bash -c \"mkdir /...
-3
votes
1
answer
1k
views
List files that are larger than 100 kB
I would like to list all the files in ~ whose size is greater than 100 kB but without using the find command. I need to do it with stat.
1
vote
1
answer
370
views
Inode Timestamp Plus/Minus Interpretation
What does +0200 mean after the Access/Modify/Change timestamps?
File: task-system.md
Size: 197 Blocks: 24 IO Block: 4096 regular file
Device: 33h/51d Inode: 14155787 Links: ...
1
vote
2
answers
420
views
How can I use 'stat' to detect a new file and then move it to a different directory?
Ultimately I want to detect a new backup file being dropped into a directory and then move that new file to another location for other operations.
This needs to work when there is nobody logged into ...
0
votes
1
answer
1k
views
What can f_bsize be used for? (Is it similar to st_blksize?)
stat() on a file, returns several fields including st_blksize. This is documented as "the 'preferred' block size for efficient filesystem I/O". The value is not used as a unit for other stat() ...
-1
votes
1
answer
496
views
Command-line Equivalent to MacOSX stat -f "%m%t%Sm %N" on Linux?
I need to extract the timestamp of when a file has been created modified for the first time. The files are on a server and can be accessed from MacOSX via sshfs, as well as from a Ubuntu server. Under ...
1
vote
1
answer
707
views
mounted g_mass_storage doesn't delete files
I'm having a strange problem with g_mass_storage gadget where deleted files from the PC are not 'actually' being deleted, which causes further problems when indexing.
Here is the procedure:
mount ...