Viewing extended file properties via command line in Linux
You can't get all the information with ls
.
You need several commands:
Name:
ls
Owner:
ls -ld <filename> | cut -f3 -d' '
For example:
root
Date modified:
ls -ld <filename> | awk '{print $6" "$7}'
For example:
2012-03-02 06:56
(Use
stat <filename>
for date accessed and changed.)Type:
file <filename>
For example:
/lib/libiw.so.30: ELF 32-bit LSB shared object, Intel 80386 (...)
Size:
ls -hld <filename> | cut -f5 -d' '
For example:
34K
Tags: N/A
Company:
apt-cache show $(dpkg -S <filename> | cut -f1 -d:) | grep Origin
For example:
Origin: Ubuntu
(On .rpm-based systems this information can be found in
rpm -q -i -f <filename>
)Copyright:
cat /usr/share/doc/$(dpkg -S <filename> | cut -f1 -d:)/copyright 2>/dev/null || echo 'No copyright information'
For example:
(...) Copyright: Commercial (...)
(On .rpm-based systems this information can be found in
rpm -q -i -f <filename>
)Description:
apt-cache show $(dpkg -S <filename> | cut -f1 -d:) | fgrep 'Description' | fgrep -v Description-md5
For example:
Description-en: Filesystem in Userspace (library)
(On .rpm-based systems this information can be found in
rpm -q -i -f <filename>
)Long description:
apt-cache show $(dpkg -S <filename> | cut -f1 -d:) | egrep -v '^[^ ]'
For example:
GNU findutils provides utilities to find files meeting specified criteria and perform various actions on the files which are found. This package contains 'find' and 'xargs'; however, 'locate' has been split off into a separate package.
(On .rpm-based systems this information can be found in
rpm -q -i -f <filename>
)
This is a very quick and dirty shell function for Ubuntu that provides much of the information above:
function lsw { filename=$1; ( echo "XXNameXXOwnerXXDate ModifiedXXTypeXXSizeXXCompanyXXDescription"; ( echo XX$filename; echo -n XX; ls -dl $filename | cut -f3 -d' '; echo -n XX; ls -dl $filename | awk '{print $6" "$7}'; echo -n XX; file $filename | cut -f2 -d: | cut -f1 -d,; echo -n XX; ls -hld $filename| cut -f5 -d' '; echo -n XX; apt-cache show $(dpkg -S $filename 2>/dev/null| cut -f1 -d:) 2>/dev/null| egrep 'Origin:|Section:' | tail -n 1 | cut -f2 -d:; echo -n XX; apt-cache show $(dpkg -S $filename 2>/dev/null| cut -f1 -d:) 2>/dev/null| fgrep 'Description' | fgrep -v Description-md5 | cut -f2 -d:) | tr '\n' ' '; echo ) | column -t -s XX; }
Some examples:
$ lsw /home/jaume
Name Owner Date Modified Type Size Company Description
/home/jaume jaume 2013-02-19 22:01 directory 4.0K
$ lsw /opt/ibm/notes/notes
Name Owner Date Modified Type Size Company Description
/opt/ibm/notes/notes root 2012-12-08 08:47 ELF 32-bit LSB executable 47K IBM IBM Notes
$ lsw /lib/libfuse.so.2
Name Owner Date Modified Type Size Company Description
/lib/libfuse.so.2 root 2012-03-02 16:33 symbolic link to `libfuse.so.2.8.6' 16 Ubuntu Filesystem in Userspace (library)
Related videos on Youtube
jdevaney
Updated on September 18, 2022Comments
-
jdevaney almost 2 years
In Windows it is possible to open explorer and add columns to view additional information about a file. For example in the image below, I added the columns for Company, Copyright and Description:
I need to know if there is a way to obtain this information via command line on a system running linux (Ubuntu 12.04 LTS). I can use strings and grep for the company name and see that, but, it assumes I already know the company name. I can't just grep for "Company" and have it return the company name on the same or next line.
-
Eddy_Em over 11 yearsTry to run
nm file
. As for license/copyright and description - you can know it from your package manager (I don't know how to do it in ubuntu). -
jdevaney over 11 yearsTried that, returned
nm: <filename>: no symbols
on multiple files that I can see in windows that have properties I am looking for as described above. -
Eddy_Em over 11 yearsClarify: you want to watch properties of binary & library files in Ubuntu or in windows?
-
jdevaney over 11 yearsI need to be able to see them on Linux (in this instance, my server is running Ubuntu). I can see the properties on a Windows system, this is how I am trying to find them on Linux. I know what they are in Windows, I am just trying to find a way to see the same information in Linux.
-
Eddy_Em over 11 yearsrun
strings file
. (but I think, you're playing the fool) -
jdevaney over 11 yearsusing strings, I can see the data I want. The problem with this is that if I hadn't known what the company name was before running strings, I might not know that information just looking at the output of strings. In several files I looked at the information appeared to be there, and in some, it wasn't. Unfortunately, I don't think I can rely on strings alone to always have the information I need/want.
-