Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find the meta information of a file using BASH [closed]

How to find the meta-information of a file in BASH? And how to extract and print it separately using cut and grep commands?

like image 977
Andy Avatar asked Aug 10 '12 09:08

Andy


People also ask

How do I view file details in Linux?

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.

How do I see file properties in Linux terminal?

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.


3 Answers

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.

like image 84
derobert Avatar answered Oct 14 '22 22:10

derobert


I'm just guessing here, but have you tried the command file? It will try to identify what kind of file it is.

like image 8
HonkyTonk Avatar answered Oct 15 '22 00:10

HonkyTonk


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.

like image 7
Burhan Khalid Avatar answered Oct 15 '22 00:10

Burhan Khalid