How to find the meta-information of a file in BASH? And how to extract and print it separately using cut and grep commands?
The simplest way to view text files in Linux is the cat command. It displays the complete contents in the command line without using inputs to scroll through it. Here is an example of using the cat command to view the Linux version by displaying the contents of the /proc/version file.
To view information about a file or folder, right-click it and select Properties. You can also select the file and press Alt + Enter . The file properties window shows you information like the type of file, the size of the file, and when you last modified it.
Instead of parsing the output of ls
using cut
/grep
, you should just use stat
which takes a -c
argument to specify the output format.
anthony@Zia:~$ stat -c '%n : %A : %U : %s' afiedt.buf .XCompose
afiedt.buf : -rw-r--r-- : anthony : 178
.XCompose : lrwxrwxrwx : anthony : 38
You can change the output format however you'd like; check the stat(1) manpage for details.
I'm just guessing here, but have you tried the command file
? It will try to identify what kind of file it is.
Execute stat -l
on the file:
[~]$ stat -l test.py
-rw-r--r-- 1 burhan staff 84 Aug 3 01:08:34 2012 test.py
To store this information in a variable:
[~]$ foo=$(stat -l test.py)
[~]$ echo $foo
-rw-r--r-- 1 burhan staff 84 Aug 3 01:08:34 2012 test.py
To get specific information only man stat
and check the format specifiers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With