Customize ls Output to Not Show the Date
This can be handy if you want to see all files and their size but not the date because you want to diff the output of 2 lists of files.
This came up recently when I wanted to diff the output of a list of files on my main computer and my Chromebook running Linux. I wanted to make sure that I copied over the same exact number of files and the files were all the same size. The files were copied where the timestamp of the files were not the same so it reported a diff on every file.
The --time-style
flag lets us customize or even remove the date / time.
Here’s an example directory / file tree that we’ll use:
$ tree
.
├── 1
└── a
├── 2
└── b
├── 3
└── c
└── 4
3 directories, 4 files
You can run ls -la
to list all files in the current directory, such as:
$ ls -la
total 12
drwxr-xr-x 3 nick nick 4096 Oct 26 10:05 .
drwxr-xr-x 105 nick nick 4096 Oct 26 10:05 ..
-rw-r--r-- 1 nick nick 0 Oct 26 10:05 1
drwxr-xr-x 3 nick nick 4096 Oct 26 10:05 a
You can also do ls -laR
to recursively list all files and directories:
$ ls -laR
.:
total 12
drwxr-xr-x 3 nick nick 4096 Oct 26 10:05 .
drwxr-xr-x 105 nick nick 4096 Oct 26 10:05 ..
-rw-r--r-- 1 nick nick 0 Oct 26 10:05 1
drwxr-xr-x 3 nick nick 4096 Oct 26 10:05 a
./a:
total 12
drwxr-xr-x 3 nick nick 4096 Oct 26 10:05 .
drwxr-xr-x 3 nick nick 4096 Oct 26 10:05 ..
-rw-r--r-- 1 nick nick 0 Oct 26 10:05 2
drwxr-xr-x 3 nick nick 4096 Oct 26 10:05 b
./a/b:
total 12
drwxr-xr-x 3 nick nick 4096 Oct 26 10:05 .
drwxr-xr-x 3 nick nick 4096 Oct 26 10:05 ..
-rw-r--r-- 1 nick nick 0 Oct 26 10:05 3
drwxr-xr-x 2 nick nick 4096 Oct 26 10:05 c
./a/b/c:
total 8
drwxr-xr-x 2 nick nick 4096 Oct 26 10:05 .
drwxr-xr-x 3 nick nick 4096 Oct 26 10:05 ..
-rw-r--r-- 1 nick nick 0 Oct 26 10:05 4
You can set the time to be an empty string with ls -laR --time-style=+""
:
$ ls -laR --time-style=+""
.:
total 12
drwxr-xr-x 3 nick nick 4096 .
drwxr-xr-x 105 nick nick 4096 ..
-rw-r--r-- 1 nick nick 0 1
drwxr-xr-x 3 nick nick 4096 a
./a:
total 12
drwxr-xr-x 3 nick nick 4096 .
drwxr-xr-x 3 nick nick 4096 ..
-rw-r--r-- 1 nick nick 0 2
drwxr-xr-x 3 nick nick 4096 b
./a/b:
total 12
drwxr-xr-x 3 nick nick 4096 .
drwxr-xr-x 3 nick nick 4096 ..
-rw-r--r-- 1 nick nick 0 3
drwxr-xr-x 2 nick nick 4096 c
./a/b/c:
total 8
drwxr-xr-x 2 nick nick 4096 .
drwxr-xr-x 3 nick nick 4096 ..
-rw-r--r-- 1 nick nick 0 4
If you look at the above output and the one right above that you’ll see that the only difference is the date / time is not included. This isn’t something I’ll use too often but it’s nice to know it exists.
The video below demos running ls
in a few different ways.
# Demo Video
Timestamps
- 0:32 – Recursively listing files and directories with the date
- 0:45 – Removing the date and time from the output
What will you use this for? Let me know below.