dates and timestamps
Print dates in any format, turn epoch seconds into dates and back, use other time zones.
Steps
-
date +%Ftoday as 2026-11-23
-
date '+%Y-%m-%d %H:%M:%S'date and time
-
date +%sseconds since 1970 (epoch)
-
date -d @1700000000an epoch time as a date (GNU; macOS: date -r 1700000000)
-
date -d 'yesterday' +%Fyesterday, next monday, 3 days ago… (GNU)
-
TZ=UTC datethe time in another zone
Commands used
date
Each has a page in lore: lore date opens it.
Related recipes
- read a file line by lineGo through a file's lines in a script, also split into fields, without losing spaces or backslashes.
- add a folder to the pathLet the shell find programs in a folder, for good, and reload the settings without logging out.
- add to the end of a fileAdd lines to a file without replacing it, also to a file only root can write.
- add up numbers in a fileSum a column of numbers, from a file or a command's output.