How to Make Locate Output Look Like ls -la

command linelocatels

The locate command output is a little bland:

$ time locate etc/profile
/etc/profile
/etc/profile.d
/etc/profile.d/appmenu-qt5.sh
/etc/profile.d/apps-bin-path.sh
/etc/profile.d/bash_completion.sh
/etc/profile.d/cedilla-portuguese.sh
/etc/profile.d/jdk.csh
/etc/profile.d/jdk.sh
/etc/profile.d/vte-2.91.sh

real    0m0.696s
user    0m0.671s
sys     0m0.024s

How can I give more information to it like ll or ls -la does? Perhaps include headings too?

Best Answer

Using xargs and ls:

$ locate -0 etc/profile | xargs -0 ls -ld
-rw-r--r-- 1 root root  575 Oct 23  2015 /etc/profile
drwxr-xr-x 2 root root 4096 Apr 20 10:10 /etc/profile.d
-rw-r--r-- 1 root root   40 Nov 30  2015 /etc/profile.d/appmenu-qt5.sh
-rw-r--r-- 1 root root  663 May 18  2016 /etc/profile.d/bash_completion.sh
-rw-r--r-- 1 root root 1003 Dec 29  2015 /etc/profile.d/cedilla-portuguese.sh
-rwxr-xr-x 1 root root   31 Oct 18  2017 /etc/profile.d/go.sh
-rwxr-xr-x 1 root root  301 Feb 20  2013 /etc/profile.d/jdk.csh
-rwxr-xr-x 1 root root  299 Feb 20  2013 /etc/profile.d/jdk.sh
-rw-r--r-- 1 root root  999 Aug 23  2017 /etc/profile.d/libvirt-uri.sh
-rw-r--r-- 1 root root 1941 Mar 16  2016 /etc/profile.d/vte-2.91.sh
-rw-r--r-- 1 root root 1557 Apr 15  2016 /etc/profile.d/Z97-byobu.sh