Intro To 'stat' Command In Linux (2024)

2023-06-15 - By Robert Elder

I use the 'stat' command to show file system attributes of files on my system:

stat README.txt
 File: README.txt Size: 13 Blocks: 8 IO Block: 4096 regular fileDevice: 10303h/66307dInode: 1837700 Links: 1Access: (0664/-rw-rw-r--) Uid: ( 1000/ robert) Gid: ( 1000/ robert)Access: 2023-04-10 22:14:51.642526898 -0400Modify: 2023-04-10 22:14:51.642526898 -0400Change: 2023-04-10 22:14:51.642526898 -0400 Birth: -

Many of the pieces of information that are shown by the 'stat' command are also shown by the ls command:

ls -li README.txt
1837700 -rw-rw-r-- 1 robert robert 13 Apr 10 22:14 README.txt

Intro To 'stat' Command In Linux (1)

When compared to the 'ls' command, the output from the 'stat' command focuses mainly on file system details like inodes, block sizes, and verbose descriptions of the file's permissions and timestamp attributes.

You can use the '-f' flag to show information about a file's host file system:

stat -f README.txt
 File: "README.txt" ID: ae86a3cf56bc3662 Namelen: 255 Type: ext2/ext3Block size: 4096 Fundamental block size: 4096Blocks: Total: 23883881 Free: 5196751 Available: 3971958Inodes: Total: 6111232 Free: 5582899

The 'stat' command allows you to specify a format string to selectively output only the information that you need. Here are several different types of files that we can use for this example:

ls -ld README.txt /dev/null /usr /run/initctl
crw-rw-rw- 1 root root 1, 3 Jun 10 10:35 /dev/null-rw-rw-r-- 1 robert robert 13 Jun 10 13:44 README.txtprw------- 1 root root 0 Jun 10 10:35 /run/initctldrwxr-xr-x 14 root root 4096 Feb 9 2021 /usr

This command prints the file type of each argument:

stat -c "'%n' is a %F." README.txt /dev/null /usr /run/initctl
'README.txt' is a regular file.'/dev/null' is a character special file.'/usr' is a directory.'/run/initctl' is a fifo.

This command prints the file size and the number of blocks that each file uses:

stat -c "'%n' has size %s and uses %b blocks." README.txt /dev/null /usr /run/initctl
'README.txt' has size 13 and uses 8 blocks.'/dev/null' has size 0 and uses 0 blocks.'/usr' has size 4096 and uses 8 blocks.'/run/initctl' has size 0 and uses 0 blocks.

This command reports the access rights in both human readable and octal format:

stat -c "'%n' has access rights: %A (%a in octal)." README.txt /dev/null /usr /run/initctl
'README.txt' has access rights: -rw-rw-r-- (664 in octal).'/dev/null' has access rights: crw-rw-rw- (666 in octal).'/usr' has access rights: drwxr-xr-x (755 in octal).'/run/initctl' has access rights: prw------- (600 in octal).

And that's why the 'stat' command is my favourite Linux command.

Intro To 'stat' Command In Linux (2)

Intro To 'stat' Command In Linux (3)

$1.00 CAD

Intro To 'stat' Command In Linux (4)Intro To 'stat' Command In Linux (5)
Intro To 'stat' Command In Linux (6)Intro To 'stat' Command In Linux (7)Intro To 'stat' Command In Linux (8)Intro To 'stat' Command In Linux (9)
Join My Mailing ListPrivacy PolicyWhy Bother Subscribing?
  • Free Software/Engineering Content. I publish all of my educational content publicly for free so everybody can make use of it. Why bother signing up for a paid 'course', when you can just sign up for this email list?
  • Read about cool new products that I'm building. How do I make money? Glad you asked! You'll get some emails with examples of things that I sell. You might even get some business ideas of your own :)
  • People actually like this email list. I know that sounds crazy, because who actually subscribes to email lists these days, right? Well, some do, and if you end up not liking it, I give you permission to unsubscribe and mark it as spam.
Intro To 'stat' Command In Linux (2024)
Top Articles
Roblox Promo Codes for 2024
Smart Mining | Smart Solutions
Danielle Moodie-Mills Net Worth
J & D E-Gitarre 905 HSS Bat Mark Goth Black bei uns günstig einkaufen
Immobiliare di Felice| Appartamento | Appartamento in vendita Porto San
Cad Calls Meriden Ct
Grange Display Calculator
Undergraduate Programs | Webster Vienna
Aces Fmc Charting
Produzione mondiale di vino
Geometry Escape Challenge A Answer Key
Seafood Bucket Cajun Style Seafood Restaurant in South Salt Lake - Restaurant menu and reviews
Winterset Rants And Raves
Craigslist Alabama Montgomery
Dignity Nfuse
Csi Tv Series Wiki
Site : Storagealamogordo.com Easy Call
Is The Yankees Game Postponed Tonight
Craigslist Appomattox Va
Veracross Login Bishop Lynch
2021 Volleyball Roster
Two Babies One Fox Full Comic Pdf
Naval Academy Baseball Roster
F45 Training O'fallon Il Photos
Hesburgh Library Catalog
Page 2383 – Christianity Today
Papa Johns Mear Me
Labcorp.leavepro.com
SOGo Groupware - Rechenzentrum Universität Osnabrück
Vera Bradley Factory Outlet Sunbury Products
Craigslist Brandon Vt
Alternatieven - Acteamo - WebCatalog
Bi State Schedule
Atlantic Broadband Email Login Pronto
Sadie Sink Doesn't Want You to Define Her Style, Thank You Very Much
To Give A Guarantee Promise Figgerits
Zasilacz Dell G3 15 3579
Mixer grinder buying guide: Everything you need to know before choosing between a traditional and bullet mixer grinder
Review: T-Mobile's Unlimited 4G voor Thuis | Consumentenbond
Joey Gentile Lpsg
The Conners Season 5 Wiki
Hazel Moore Boobpedia
Sour OG is a chill recreational strain -- just have healthy snacks nearby (cannabis review)
Noga Funeral Home Obituaries
Julies Freebies Instant Win
Msatlantathickdream
Osrs Vorkath Combat Achievements
Immobiliare di Felice| Appartamento | Appartamento in vendita Porto San
Uncle Pete's Wheeling Wv Menu
When Is The First Cold Front In Florida 2022
Intuitive Astrology with Molly McCord
Latest Posts
Article information

Author: Terrell Hackett

Last Updated:

Views: 6091

Rating: 4.1 / 5 (72 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Terrell Hackett

Birthday: 1992-03-17

Address: Suite 453 459 Gibson Squares, East Adriane, AK 71925-5692

Phone: +21811810803470

Job: Chief Representative

Hobby: Board games, Rock climbing, Ghost hunting, Origami, Kabaddi, Mushroom hunting, Gaming

Introduction: My name is Terrell Hackett, I am a gleaming, brainy, courageous, helpful, healthy, cooperative, graceful person who loves writing and wants to share my knowledge and understanding with you.