Wes Miller
Wes Miller

Reputation: 2241

How to get the date on a directory entry using "ls" and not on the whole directory contents?

I seem to want the opposite of everyone else - How may i use (in bash scripts) an ls -al /some/path/to/where/ever/. to get just the entry for ".", not for everything in "."? What I'm after is the dir's date, so. in other words, what's the date on the /some/path/to/where/ever/. directory?

Doesn't have to be "ls" that is just what seemed natural.

Upvotes: 2

Views: 4121

Answers (3)

David W.
David W.

Reputation: 107040

Instead of using ls, you can use stat to capture the date. This way, the date isn't in a shifting format, and you don't have to filter it out from the rest of the output:

$ stat -f "%Sm" $directory_name
Feb 10 14:19:47 2014

$ stat -f "%Dm" $directory_name
1392059987     # Number of seconds since the "Epoch" (Usually Jan 1, 1970).

The stat command varies from system to system, so read your manpage.

Upvotes: 0

anubhava
anubhava

Reputation: 785156

You can do stat command:

stat -c "%y %n" .

OR for EPOCH value:

stat -c "%Y %n" .

Upvotes: 5

chepner
chepner

Reputation: 531175

You want to use the -d option to get the entry for the directory itself, not the contents of the directory.

ls -ld /some/path/to/where/ever

In this case, the -a option would be unnecessary, since you are not listing the contents of the given argument.

Upvotes: 3

Related Questions