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
Binance Coin (BNB) Price Prediction And Forecast 2023 - 2030 | Trading Education
How to Bridge from Ethereum to Polygon (2023)
Ffxiv Palm Chippings
Gamevault Agent
Valley Fair Tickets Costco
Davante Adams Wikipedia
Mohawkind Docagent
Emmalangevin Fanhouse Leak
123 Movies Black Adam
Mndot Road Closures
Erskine Plus Portal
13 The Musical Common Sense Media
World Cup Soccer Wiki
Craigslist Heavy Equipment Knoxville Tennessee
Slag bij Plataeae tussen de Grieken en de Perzen
Oscar Nominated Brings Winning Profile to the Kentucky Turf Cup
Love In The Air Ep 9 Eng Sub Dailymotion
Leader Times Obituaries Liberal Ks
Committees Of Correspondence | Encyclopedia.com
Vanessawest.tripod.com Bundy
Huntersville Town Billboards
Timeforce Choctaw
Ford F-350 Models Trim Levels and Packages
Routing Number For Radiant Credit Union
Sofia the baddie dog
City Of Durham Recycling Schedule
Urbfsdreamgirl
Table To Formula Calculator
Sandals Travel Agent Login
Orange Park Dog Racing Results
Maths Open Ref
DIY Building Plans for a Picnic Table
Otis Offender Michigan
Have you seen this child? Caroline Victoria Teague
The Pretty Kitty Tanglewood
Steven Batash Md Pc Photos
Tamil Play.com
Atlantic Broadband Email Login Pronto
Spinning Gold Showtimes Near Emagine Birch Run
Asian Grocery Williamsburg Va
Directions To 401 East Chestnut Street Louisville Kentucky
Academic important dates - University of Victoria
Gpa Calculator Georgia Tech
T&Cs | Hollywood Bowl
Immobiliare di Felice| Appartamento | Appartamento in vendita Porto San
Sdn Fertitta 2024
St Vrain Schoology
Online College Scholarships | Strayer University
Understanding & Applying Carroll's Pyramid of Corporate Social Responsibility
Unpleasant Realities Nyt
Tyrone Unblocked Games Bitlife
How To Connect To Rutgers Wifi
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.