Glam Prestige Journal

Bright entertainment trends with youth appeal.

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.

6

1 Answer

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) 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy