Linux Commands Examples

A great documentation place for Linux commands

stat

display file or file system status

Synopsis

stat [OPTION]... FILE...


add an example, a script, a trick and tips

: email address (won't be displayed)
: name

Step 2

Thanks for this example ! - It will be moderated and published shortly.

Feel free to post other examples
Oops ! There is a tiny cockup. A damn 404 cockup. Please contact the loosy team who maintains and develops this wonderful site by clicking in the mighty feedback button on the side of the page. Say what happened. Thanks!

examples

1
source
            
T=`stat -c %Y $F`
1
source
            
T=`stat -c %y $F`
1
source

how to know if noatime or relatime is default mount option in kernel?

This should list all the options a file system was mounted with:

cat /proc/mounts
0
source

stat and ls show wrong file size (terabytes wrong)

vCard appears to be a text file format. This is a good thing as text files should not contain nulls - this will help if the OS mistakenly thinks the file is a sparse file containing very long sequences of nulls.

You can use ls -lks bigfile to see if the occupied space differs from the apparent space.

You can use dd to extract chunks of data (e.g. the first 500 bytes only) into a new file. You can then used hexdump to see if there is recoverable text in that chunk.

If you find the file is filled with long sequences of nulls, you can try using a script to read the file and only write the non-null data to a new file. In this way you may be able, at some effort, to construct a valid vCard file of the usual size.

alternatively use strings bigfile to extract text from the huge file

Many of these operations will take a long time on a ig file. You may want to practise on something smaller ...


Here's a vCard file

$ cat gump.vcard
BEGIN:VCARD
VERSION:2.1
N:Gump;Forrest
FN:Forrest Gump
...
EMAIL;PREF;INTERNET:forrestgump@example.com
REV:20080424T195243Z
END:VCARD

$ file gump.vcard
gump.vcard: vCard visiting card

let's make a corrupt sparse version

$ dd of=sparse-file bs=1k seek=5120 count=0
0+0 records in
0+0 records out
0 bytes (0 B) copied, 0 s, Infinity B/s

$ cat gump.vcard sparse-file > sparse-gump.vcard

$ cp --sparse=always sparse-gump.vcard really-sparse-gump.vcard

$ ls -lks *sparse*
   0 -rw-r--r-- 1 rgb rgb 5120 Jul 11 18:09 sparse-file
5136 -rw-r--r-- 1 rgb rgb 5121 Jul 11 18:10 sparse-gump.vcard
   4 -rw-r--r-- 1 rgb rgb 5121 Jul 11 18:18 really-sparse-gump.vcard

Note that the size on disk of the last file is 4 blocks but it contains 5121 blocks of data.

Lets see what is in there

$ hexdump really-sparse-gump.vcard | head -n 3
0000000 4542 4947 3a4e 4356 5241 0a44 4556 5352
0000010 4f49 3a4e 2e32 0a31 3a4e 7547 706d 463b
0000020 726f 6572 7473 460a 3a4e 6f46 7272 7365

$ hexdump really-sparse-gump.vcard | tail
0000230 4120 656d 6972 6163 450a 414d 4c49 503b
0000240 4552 3b46 4e49 4554 4e52 5445 663a 726f
0000250 6572 7473 7567 706d 6540 6178 706d 656c
0000260 632e 6d6f 520a 5645 323a 3030 3038 3234
0000270 5434 3931 3235 3334 0a5a 4e45 3a44 4356
0000280 5241 0a44 0000 0000 0000 0000 0000 0000
0000290 0000 0000 0000 0000 0000 0000 0000 0000
*
0500280 0000 0000
0500284

Note the * line between offsets 290 and 0500280 - that's where all the imaginary nulls live.

$ strings really-sparse-gump.vcard > new-gump.vcard

$ ls -lks new-gump.vcard
4 -rw-r--r-- 1 rgb rgb 1 Jul 11 18:30 new-gump.vcard

$ cat new-gump.vcard
BEGIN:VCARD
VERSION:2.1
N:Gump;Forrest
FN:Forrest Gump
...
EMAIL;PREF;INTERNET:forrestgump@example.com
REV:20080424T195243Z
END:VCARD

We have recovered our normal sized vCard from the huge file. Your Mileage May Vary.

0
source

tar --files-from complains "Cannot stat: No such file or directory"

Most likely tar would love to be noticed about the current path. So instead of

admin/memberinformation.php

the changeset.txt should read

./admin/memberinformation.php

or alternatively contain the full path.

0
source

Does stat/lstat on nonexistent file cause a disk seek?

Somehow the OS needs the information, wether the file is there or not. Obviously it has to read in the folder list of all parent folders where you are looking for the file.

But don't worry too much. Once read in, these informations will remain in the caches, so it does not have to search on the disk every time - only if for some reason the cached informations have been dropped (maybe the OS needed this space in memory for more recent data) the OS will have to look on the disk again.

description

Display file or file system status.
-L
, --dereference

follow links

-f, --file-system

display file system status instead of file status

-c --format=FORMAT

use the specified FORMAT instead of the default; output a newline after each use of FORMAT

--printf=FORMAT

like --format, but interpret backslash escapes, and do not output a mandatory trailing newline. If you want a newline, include \n in FORMAT

-t, --terse

print the information in terse form

--help

display this help and exit

--version

output version information and exit

The valid format sequences for files (without --file-system):

%a

access rights in octal

%A

access rights in human readable form

%b

number of blocks allocated (see %B)

%B

the size in bytes of each block reported by %b

%C

SELinux security context string

%d

device number in decimal

%D

device number in hex

%f

raw mode in hex

%F

file type

%g

group ID of owner

%G

group name of owner

%h

number of hard links

%i

inode number

%m

mount point

%n

file name

%N

quoted file name with dereference if symbolic link

%o

optimal I/O transfer size hint

%s

total size, in bytes

%t

major device type in hex

%T

minor device type in hex

%u

user ID of owner

%U

user name of owner

%w

time of file birth, human-readable; - if unknown

%W

time of file birth, seconds since Epoch; 0 if unknown

%x

time of last access, human-readable

%X

time of last access, seconds since Epoch

%y

time of last modification, human-readable

%Y

time of last modification, seconds since Epoch

%z

time of last change, human-readable

%Z

time of last change, seconds since Epoch

Valid format sequences for file systems:

%a

free blocks available to non-superuser

%b

total data blocks in file system

%c

total file nodes in file system

%d

free file nodes in file system

%f

free blocks in file system

%i

file system ID in hex

%l

maximum length of filenames

%n

file name

%s

block size (for faster transfers)

%S

fundamental block size (for block counts)

%t

file system type in hex

%T

file system type in human readable form

NOTE: your shell may have its own version of stat, which usually supersedes the version described here. Please refer to your shell’s documentation for details about the options it supports.

copyright

Copyright © 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

reporting bugs

Report stat bugs to bug-coreutils[:at:]gnu[:dot:]org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
Report stat translation bugs to <http://translationproject.org/team/>


see also

stat

The full documentation for stat is maintained as a Texinfo manual. If the info and stat programs are properly installed at your site, the command

info coreutils 'stat invocation'

should give you access to the complete manual.


author

Written by Michael Meskes.

How can this site be more helpful to YOU ?


give  feedback