资讯详情

How to Get Day of Week in Bash (With Examples)

📅 2026/11/6 3:48:42 | 华诺云谱 👁 阅读
How to Get Day of Week in Bash (With Examples)
You can use the following methods to get the current day of the week in Bash:Method 1: Get Day of Week as Number (e.g. 1Monday, 7 Sunday)date %uMethod 2: Get Day of Week as Full Name (e.g. “Sunday”)date %AMethod 3: Get Day of Week as Abbreviated Name (e.g. “Sun”)date %aThe following examples show how to use each method in practice.Example 1: Get Day of Week as Number in BashThis article is currently being written on a Sunday.We can use the following syntax to get the current day of the week as a number between 1 and 7 in Bash:date %uThe following screenshot shows how to use this syntax in practice:This returns7, which is the number that corresponds to Sunday as the day of the week.If you want to extract the day of the week as a number for a specific date, you can use the following syntax instead:date -d 2024-10-15 %uThe following screenshot shows how to use this syntax in practice:This returns2, which represents the day of the week (Tuesday) for the date2024-10-15that we specified.Example 2: Get Day of Week as Full Name in BashWe can use the following syntax to get the day of the week as a full name in Bash:date %AThe following screenshot shows how to use this syntax in practice:This returnsSunday, which is the day of the week represented as the full name.Example 3: Get Day of Week as Abbreviated Name in BashWe can use the following syntax to get the day of the week as an abbreviated name in Bash:date %aThe following screenshot shows how to use this syntax in practice:This returnsSun, which is the day of the week represented as the abbreviated name.Related TutorialsThe following tutorials explain how to perform other common tasks in Bash:Bash: How to Get Month NameBash: How to Compare DatesBash: How to Extract Date from String
📝

华诺云谱内容团队

资深建站顾问 · 行业研究员

10年+企业数字化服务经验,专注智能建站、SEO优化与品牌营销,持续输出建站技巧、行业洞察与营销干货,已帮助5000+企业实现数字化增长。

你可能需要的服务

订阅华诺云谱资讯周报

每周一封,精选建站技巧、SEO与营销干货,直达邮箱。已有 8,000+ 企业主订阅,助你少走弯路。

↑