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
Core Flare Protocols
Manage warnings about unsafe sites - Computer
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Pearson Correlation Coefficient
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
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.