Linux command
date 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Show
date
Custom
date ["+%Y-%m-%d %H:%M:%S"]
Show
date -u
Set
sudo date -s ["2024-01-15 10:30:00"]
Show
date -d [@1234567890]
说明
date displays or sets the system date and time. It supports extensive output formatting through format specifiers, time zone conversions, relative date calculations, and Unix timestamp conversions. The command is essential for timestamping, logging, scheduling, and time-based operations. Beyond simple display, date excels at date arithmetic: you can specify relative dates like "tomorrow", "next monday", "2 days ago", or "+3 hours". It can parse dates from strings, convert Unix timestamps to human-readable format, and format output for any purpose from ISO 8601 standards to custom formats. The tool is one of the most commonly used Unix utilities, present since the earliest Unix versions. It's frequently used in shell scripts for generating timestamped filenames, calculating time differences, or performing date-based conditional logic. Format specifiers allow precise control over output, from simple "YYYY-MM-DD" to complex locale-specific formats. The tool respects timezone settings and can display UTC or any specific timezone.
参数
- -d, --date=_string_
- Display specified date/time
- -s, --set=_string_
- Set system date/time (requires root)
- -u, --utc
- Print/set UTC time
- -r, --reference=_file_
- Display file's modification time
- -I_timespec_
- ISO 8601 format
- -R, --rfc-email
- RFC 5322 format
FAQ
What is the date command used for?
date displays or sets the system date and time. It supports extensive output formatting through format specifiers, time zone conversions, relative date calculations, and Unix timestamp conversions. The command is essential for timestamping, logging, scheduling, and time-based operations. Beyond simple display, date excels at date arithmetic: you can specify relative dates like "tomorrow", "next monday", "2 days ago", or "+3 hours". It can parse dates from strings, convert Unix timestamps to human-readable format, and format output for any purpose from ISO 8601 standards to custom formats. The tool is one of the most commonly used Unix utilities, present since the earliest Unix versions. It's frequently used in shell scripts for generating timestamped filenames, calculating time differences, or performing date-based conditional logic. Format specifiers allow precise control over output, from simple "YYYY-MM-DD" to complex locale-specific formats. The tool respects timezone settings and can display UTC or any specific timezone.
How do I run a basic date example?
Run `date` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -d, --date=_string_ do in date?
Display specified date/time