how to list files in Unix without the modified date

Greg picture Greg · Mar 25, 2013 · Viewed 8.6k times · Source

I'm trying to create a zip file that will run on multiple servers to compare the contents of the servers. For many reasons, the easiest and best piece of information for me to compare is a text file of the directory listings... but I need that without the modified date as they make the comparisons show differences that don't matter in this case.

So if I run command ls -la to create text output for comparing, I get would get something like this:

drwxr-xr-x.  6 root   root       4096 Mar 20 14:59 .
dr-xr-xr-x. 22 root   root       4096 Feb 18 03:20 ..
drwxr-xr-x.  9  web   ad         4096 Oct 30 14:35 apache-tomcat-6.0.18
drwxr-xr-x.  9  web   ad         4096 Mar 24 03:00 apache-tomcat-6.0.36
lrwxrwxrwx.  1 root   root          5 Oct 30 14:06 java -> java6
lrwxrwxrwx.  1 root   root         16 Oct 30 14:05 java6 -> jdk/jdk1.6.0_37/
lrwxrwxrwx.  1 root   root         16 Mar 20 14:59 java7 -> jdk/jdk1.7.0_17/
drwxr-xr-x.  4 root   root       4096 Mar 20 15:02 jdk
lrwxrwxrwx.  1 root   root         21 Nov  6 15:09 tomcat -> apache-tomcat-6.0.36/

What I would like is to use is ls -la | cut -c 1-31 but that only takes one list (the characters 1-31) and I really want the data after the date. I'm fairly new with Unix and was curious if anyone knows how to produce a list that would look something like this:

drwxr-xr-x.  6 root   root       4096 .
dr-xr-xr-x. 22 root   root       4096 ..
drwxr-xr-x.  9  web   ad         4096 apache-tomcat-6.0.18
drwxr-xr-x.  9  web   ad         4096 apache-tomcat-6.0.36
lrwxrwxrwx.  1 root   root          5 java -> java6
lrwxrwxrwx.  1 root   root         16 java6 -> jdk/jdk1.6.0_37/
lrwxrwxrwx.  1 root   root         16 java7 -> jdk/jdk1.7.0_17/
drwxr-xr-x.  4 root   root       4096 jdk
lrwxrwxrwx.  1 root   root         21 tomcat -> apache-tomcat-6.0.36/

Thanks

Answer

111 picture 111 · Jan 6, 2017

Posting an alternate solution because the accepted one will fail on filename with spaces.

On Linux and other systems that support it (not Mac OS) use --time-style with null formatting

[root@preg junk]# ls -lah
total 12K
drwxr-xr-x 2 root root 4.0K Jan  6 16:12 .
drwxr-xr-x 4 root root 4.0K Jan  6 15:38 ..
-rw-r--r-- 1 root root    0 Jan  6 12:42 '$#%bad'
-rw-r--r-- 1 root root    2 Jan  6 16:12 'moar bad;'
-rw-r--r-- 1 root root    0 Jan  6 12:40 'quote"file'
-rw-r--r-- 1 root root    0 Jan  6 12:41 'single'\''quote'\''file'

[root@preg junk]# ls -lah  --time-style='+'  .
total 12K
drwxr-xr-x 2 root root 4.0K  .
drwxr-xr-x 4 root root 4.0K  ..
-rw-r--r-- 1 root root    0  '$#%bad'
-rw-r--r-- 1 root root    2  'moar bad;'
-rw-r--r-- 1 root root    0  'quote"file'
-rw-r--r-- 1 root root    0  'single'\''quote'\''file'
[root@preg junk]#