Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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:

enter image description here

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.

share|improve this question
    
Try 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). –  Eddy_Em Feb 19 '13 at 14:26
    
Tried 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. –  jdevaney Feb 19 '13 at 14:31
    
Clarify: you want to watch properties of binary & library files in Ubuntu or in windows? –  Eddy_Em Feb 19 '13 at 14:36
    
I 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. –  jdevaney Feb 19 '13 at 14:38
    
run strings file. (but I think, you're playing the fool) –  Eddy_Em Feb 19 '13 at 14:40

1 Answer 1

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) 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.