Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to list files in Unix without the modified date

Tags:

unix

ls

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

like image 731
Greg Avatar asked Mar 25 '13 19:03

Greg


People also ask

How do I find the original file created date in Unix?

The easiest way to get the file creation date is with the stat command. As we can see, the creation date is shown in the “Birth” field.

How do you sort files by date modified in Unix?

How to list Unix files in date order? In order to ls by date or list Unix files in last modifed date order use the -t flag which is for 'time last modified'. or to ls by date in reverse date order use the -t flag as before but this time with the -r flag which is for 'reverse'.


2 Answers

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]# 
like image 62
111 Avatar answered Sep 22 '22 19:09

111


I think the best solution to your problem is to use awk.

ls -la | awk '{print $1, $2, $3, $4, $5, $9}'

So you obtain an output like this:

drwxr-xr-x. 6 root root 4096 .
dr-xr-xr-x. 22 root root 4096 ..
drwx------+ 5 user staff 170 Desktop
drwx------+ 16 user staff 544 Documents
drwx------+ 6 user staff 204 Downloads
like image 31
Fabrizio Duroni Avatar answered Sep 21 '22 19:09

Fabrizio Duroni