Questions tagged [stat]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
43 views

Properly escape a string variable that contains special characters to be used in a shell script?

I feel dumb for asking such a simple question but Im absolutely stuck on this one. I've search everywhere, tried several methods to escape or properly quote this variable, but no matter what when I ...
ProfessionalAmateur's user avatar
0 votes
0 answers
22 views

How do I get the number of hardlinks of a folder?

I am on Mac. However, I use gstat (GNU stat) so my understanding is that behavior should match linux. I cd to a folder. Then I use gstat --format=%h .. The output is 65. Next, I use gfind . -maxdepth ...
Matt Groth's user avatar
3 votes
4 answers
340 views

Apply arithmetic into piped command

So far I have this: sudo find /path/to/dir -type f | xargs -d "\n" sudo stat -c "%Y %n" | {arithmetic to check if %Y is between 1685518962 and 1685624474??} | {show ...
MonkeyZeus's user avatar
1 vote
2 answers
69 views

how to list all files in a given period according their duration(not moment) of access

under linux, how to list all files in a given directory and its subdirs, in a given period, say last 10days, according their duration of access, ideally the result ought to be sorted by access ...
user2718593's user avatar
0 votes
1 answer
132 views

How to get the most trusted and accurate linux distro stats?

I need the Linux distros usage statistics. I need this data to make a more informed decision for our future technology choices. However, I can't find the data. It seems that DistroWatch is a good ...
Saeed Neamati's user avatar
0 votes
0 answers
23 views

debugfs mi output shows different block count than the number of block references!

I have a file for which the the mi (modify inode) option gives different block count and block references : debugfs: mi <4762313> Mode [0100644] ...
Sam's user avatar
  • 1
6 votes
2 answers
784 views

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

I am trying to understand why wc and stat report different things for /proc/[pid]/cmdline. wc says my shell's cmdline file is 6 bytes in size: $ wc --bytes /proc/$$/cmdline 6 /proc/10425/cmdline stat ...
Shane Bishop's user avatar
1 vote
2 answers
186 views

A script to show the age of a linux installation in days

I want to create a command that is called Age which calls this script: From=$(stat / | grep "Birth" | sed 's/Birth: //g' | cut -b 2-11) echo $From Now=$(date) echo $Now However, I'm stuck ...
Saeed Neamati's user avatar
8 votes
1 answer
536 views

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

Note: Question although says vice versa but it really does not have any meaning since both of them point to the same inode and its not possible to say which is head and which is tail. Say I have a ...
Himanshuman's user avatar
0 votes
0 answers
103 views

Linux shows wrong file size for samba share

I got a strange error in my linux file system (Linux Mint) that drives me crazy and prevents me from using rsync without CRC. The file size is just shown wrong. The correct size is 13638, while it is ...
SWYM's user avatar
  • 1
1 vote
1 answer
172 views

Unable to figure the permissions required by lstat

I am running into this weird permission issue on Debian 10, with lstat call on XFS filesystem. I have been referring to this link to understand how extended ACLs will work The man page says that ...
mittal's user avatar
  • 121
0 votes
1 answer
106 views

How can I obtain the time stamp from a file or directory in touch format?

According to many websites I found online the touch commands' -t argument accepts the time stamp in the following format: [[CC]YY]MMDDhhmm[.ss] Here, CC: The first two digits of the year. YY: The ...
Zoltan King's user avatar
1 vote
1 answer
201 views

How can I efficiently read entries in a directory?

I would like my program to efficiently detect if a file was added to a directory between two invocations. That analysis might block user input (this would be for the fish shell), so I want it to run ...
Narrateur du chaos's user avatar
5 votes
1 answer
748 views

cp overrides my default permissions settings, when copying files with: cp -r --no-preserve=all

My default umask is 077. When I create a directory, it has permissions 700: mkdir AA $ stat -c'%A %n' AA/ drwx------ AA/ now I want to set default permissions recursively to 750: ...
Martin Vegter's user avatar
2 votes
0 answers
320 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 ...
Totor's user avatar
  • 19.4k
0 votes
2 answers
511 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 ...
Jun-Dai Bates-Kobashigawa's user avatar
1 vote
0 answers
181 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 ...
PrivateOmega's user avatar
0 votes
4 answers
476 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
CJ7's user avatar
  • 829
0 votes
1 answer
241 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, ...
TheRoguePrince's user avatar
0 votes
1 answer
27 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 ...
manifestor's user avatar
  • 2,423
1 vote
1 answer
1k 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? ...
CarLaTeX's user avatar
  • 329
0 votes
2 answers
62 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 ...
YorSubs's user avatar
  • 611
0 votes
0 answers
189 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 ...
rothloup's user avatar
  • 111
9 votes
1 answer
641 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 ...
Stéphane Chazelas's user avatar
0 votes
1 answer
70 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. ...
Johnny's user avatar
  • 101
2 votes
1 answer
45 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 ...
Angus L'Herrou's user avatar
1 vote
1 answer
153 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. ...
PerfectGamesOnline.com's user avatar
0 votes
0 answers
33 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 ...
Chris Parker's user avatar
0 votes
1 answer
883 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 ...
Porcupine's user avatar
  • 1,700
0 votes
1 answer
44 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 ...
B W's user avatar
  • 1
1 vote
1 answer
964 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: ...
alexis's user avatar
  • 407
0 votes
1 answer
399 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 ...
activedecay's user avatar
2 votes
1 answer
1k 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 ...
shaqed's user avatar
  • 853
0 votes
1 answer
208 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 ...
samshers's user avatar
  • 668
0 votes
1 answer
1k 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 ...
fa7eme's user avatar
  • 43
3 votes
1 answer
682 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 ...
genericuser99's user avatar
0 votes
0 answers
215 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 ...
John D.'s user avatar
  • 101
0 votes
1 answer
83 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 ...
user4434's user avatar
1 vote
2 answers
590 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 ...
Luka's user avatar
  • 11
0 votes
1 answer
383 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 ...
Fredrik's user avatar
  • 11
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 ...
Fredrik's user avatar
  • 11
2 votes
0 answers
587 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 (...
Paulo Tomé's user avatar
  • 3,754
5 votes
1 answer
4k 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 ...
stas's user avatar
  • 53
3 votes
2 answers
2k 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 ...
thb's user avatar
  • 1,125
1 vote
2 answers
411 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 ...
supriyo_basak's user avatar
6 votes
1 answer
8k 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 ...
finefoot's user avatar
  • 2,980
0 votes
2 answers
663 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 ...
Dan's user avatar
  • 5
1 vote
1 answer
1k 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;...
user2292524's user avatar
5 votes
1 answer
3k 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(...
liori's user avatar
  • 612
-2 votes
1 answer
439 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 ...
Adam Ledger's user avatar