file and stat
What is this file?.
On Windows, a file's type is decided by its extension, like dot JPG. Linux doesn't really care about extensions. A file called photo could be a picture, a text file, or a program. So how do you find out what's inside?

- Extensions are just hints
- Linux doesn't rely on them
- So what's inside?
Asking with file
The file command looks inside a file, and tells you what it really is. Notes is plain text. The hello script is a bash script. And slash bin slash LS, the LS program itself, is a compiled program, called an ELF executable.
file notes.txt notes.txt: ASCII text file projects/scripts/hello.sh projects/scripts/hello.sh: Bourne-Again shell script, ASCII text executable file /bin/ls /bin/ls: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=00a639537eef557c0dcb20ad52892bc84863ed94, for GNU/Linux 3.7.0, stripped
Every detail with stat
Stat shows everything Linux knows about a file. Its size, its permissions, its owner, and three times. When it was last read, when its contents last changed, and when its details last changed. You won't need stat every day, but it's good to know it's there.
stat notes.txt File: notes.txt Size: 30 Blocks: 8 IO Block: 4096 regular file Device: 0,101 Inode: 472044 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/ sam) Gid: ( 1000/ sam) Access: 2026-01-05 09:00:00.000000000 +0000 Modify: 2026-01-05 09:00:00.000000000 +0000 Change: 2026-01-05 09:00:00.000000000 +0000 Birth: 2026-01-05 09:00:00.000000000 +0000
Text or not?
Why does this matter? Text files are safe to open with cat, less, or nano. Other files, like images, zip archives, or programs, will print garbage, and can even mess up your terminal. If that happens, type reset, and press Enter. So when you're unsure, ask file first.
| key | value |
|---|---|
| Text | cat, less, nano are fine |
| Not text | prints garbage |
| Messed up terminal | type reset |
| Unsure? | run file first |
Summary
File tells you what kind of file something really is, and stat shows all of its details. Next, finding files, wherever they are.
Key takeaways- file <name>
- stat <name>
- reset fixes a messy terminal