user2442230
user2442230

Reputation: 43

getting a file's access time in linux

Hello currently in linux I run stat with a file and it yields this:

File: `/var/www/html/assetlib/web/uploads/5d32500c44e62277d198a89d3ed8f69729d83e62.png'  
Size: 18241         Blocks: 40         IO Block: 4096   regular file                       
Device: ca01h/51713d    Inode: 131903      Links: 1
Access: (0666/-rw-rw-rw-)  Uid: (   48/  apache)   Gid: (   48/  apache)           
Access: 2013-06-04 05:33:08.909346476 +0000           
Modify: 2013-06-04 05:33:08.909346476 +0000                                             
Change: 2013-06-04 05:33:08.909346476 +0000\

how can I get the access time, I just want to be able to have 2013-06-04 05:33:08 I tried using awk but was unsuccessful, I am a noob at linux! Any help is greatly appreciated. Thanks!

Upvotes: 1

Views: 418

Answers (5)

draxxxeus
draxxxeus

Reputation: 1523

Try this

stat file | awk "NR==6"

Upvotes: 1

Sebastiaan M
Sebastiaan M

Reputation: 5885

Or using grep and cut:

stat backup.txt | grep Access | grep -v Uid | cut -b 9-37

Upvotes: 0

log0
log0

Reputation: 10917

--printf='%x' gives the last access time human readable (man stat). Then using cut to get rid of what comes after the .

$ stat --printf='%x' myfile | cut -d. -f 1
2013-06-02 16:00:15

Upvotes: 1

jlliagre
jlliagre

Reputation: 30813

Here is one way using awk:

stat myfile | awk '$1=="Access:" && NF==4 { gsub("\\..*$","",$3); print $2," ",$3 }'

Upvotes: 0

Nitin4873
Nitin4873

Reputation: 17552

 Kaizen ~/so_test $ stat -c "%x" zsleep_cntr.sh
 2013-06-06 09:51:08.981417300 +0530

does this help ?

Upvotes: 1

Related Questions