当前位置: 首页 > ops >正文

Linux基本指令,对路径的认识

引言

        简单介绍一些Linux的基本指令,快速上手Linux操作系统。

一、ls指令

语法:ls [选项] [目录或文件]

功能::对于目录,该命令列出该目录下的所有子目录与文件。

               对于文件件,将列出文件名以及其他信息

常用选项:

  • -a 列出目录下的所以文件,包含以 . 开头的隐含文件
  • -l 列出文件的详细信息
  • -d 将目录像文件一样显示,而不是显示其下的文件。ls -d [指定目录]
  • 等等等等,后面遇到了再详细介绍。
[root@hcss-ecs-f571 ~]# ls
learn01
[root@hcss-ecs-f571 ~]# ls -a
.  ..  .bash_history  .bash_logout  .bash_profile  .bashrc  .cache  .cshrc  .history  learn01  .pki  .ssh  .tcshrc
[root@hcss-ecs-f571 ~]# ls -l
total 4
drwxr-xr-x 2 root root 4096 Jul 29 22:12 learn01
[root@hcss-ecs-f571 ~]# ls -a -l
total 48
dr-xr-x---.  6 root root 4096 Jul 29 22:12 .
dr-xr-xr-x. 19 root root 4096 May 25 23:07 ..
-rw-r--r--   1 root root  475 Jul 29 22:12 .bash_history
-rw-r--r--.  1 root root   18 Dec 29  2013 .bash_logout
-rw-r--r--.  1 root root  176 Dec 29  2013 .bash_profile
-rw-r--r--.  1 root root  176 Dec 29  2013 .bashrc
drwx------   3 root root 4096 Jul 26  2024 .cache
-rw-r--r--.  1 root root  100 Dec 29  2013 .cshrc
-rw-------   1 root root    0 Jul 26  2024 .history
drwxr-xr-x   2 root root 4096 Jul 29 22:12 learn01
drwxr-----   3 root root 4096 Jul 26  2024 .pki
drwx------   2 root root 4096 May 25 23:07 .ssh
-rw-r--r--.  1 root root  129 Dec 29  2013 .tcshrc

二、pwd命令

语法:pwd

功能:显示用户当前所在的目录

常用选项:无

[root@hcss-ecs-f571 ~]# pwd
/root

 Linux理论知识:路径的认识

• Linux系统中,磁盘上的文件和目录被组成一棵目录树,每个节点都是目录或文件
• 其中普通文件⼀定是目录树的叶子节点
• 目录可能是叶子(空目录),也可能是路上节点
• 理解路径存在的意义:树状组织方式,保证快速定位查找到指定的文件,而定位文件就需要具有唯⼀性的方案来进行定位文件。其中任何⼀个节点,都只有⼀个父节点,所以,从根目录开始,定位指定文件,路径具有唯⼀性
• 绝对路径:⼀般从/开始,不依赖其他⽬录的定位文件的方式
• 相对路径:相对于当前用户所处⽬录,定位⽂件的路径方式
• 绝对路径⼀般不会随着用户的路径变化而丧失唯一性,一般在特定服务的配置文件中经常  被使用
• 相对路径因为它的便捷性,⼀般在命令行中使用较多

三、cd指令

语法:cd 目录名

功能:改变工作目录。将当前工作目录改变到指定的目录下

常用选项:

  • cd ..  返回上级目录
  • cd ~ 快速进入自己的家目录
  • cd / 进入/目录
  • cd - 退回到上一次的目录中
  • cd 跟目录      
[root@hcss-ecs-f571 learn01]# cd ~
[root@hcss-ecs-f571 ~]# pwd
/root
[root@hcss-ecs-f571 ~]# cd /
[root@hcss-ecs-f571 /]# pwd
/
[root@hcss-ecs-f571 /]# cd /root/learn01
[root@hcss-ecs-f571 learn01]# pwd
/root/learn01
[root@hcss-ecs-f571 learn01]# cd -
/
[root@hcss-ecs-f571 /]# pwd
/
[root@hcss-ecs-f571 /]# cd ~
[root@hcss-ecs-f571 ~]# pwd
/root
[root@hcss-ecs-f571 ~]# 

四、touch指令

语法:touch [选项]..[文件]

功能:touch命令参数可更改文档或目录的日期时间,包括存取时间和更改时间,或者新建⼀个不存在的文件。

常用选项:

  • -a:change only the access time
  • -c:change only the modification time
[root@hcss-ecs-f571 ~]# ls
learn01
[root@hcss-ecs-f571 ~]# cd learn01
[root@hcss-ecs-f571 learn01]# touch my.txt
[root@hcss-ecs-f571 learn01]# ls
my.txt
[root@hcss-ecs-f571 learn01]# ll
total 0
-rw-r--r-- 1 root root 0 Jul 29 23:28 my.txt
[root@hcss-ecs-f571 learn01]# 

五、mkdir指令

语法:mkdir [选项] dirname

功能:在当前目录下创建一个名为“dirname”的目录

常用选项:-p/--parents: 可以是一个路径名称。此时若路径中的某些目录尚不存在,加上此选项后,系统将自动建好那些尚不存在的目录,即一次可以建立多个目录

[root@hcss-ecs-f571 learn01]# ll
total 8
drwxr-xr-x 2 root root 4096 Jul 29 23:40 dir1
drwxr-xr-x 3 root root 4096 Jul 29 23:41 dir2
-rw-r--r-- 1 root root    0 Jul 29 23:28 my.txt
[root@hcss-ecs-f571 learn01]# mkdir dir3
[root@hcss-ecs-f571 learn01]# ll
total 12
drwxr-xr-x 2 root root 4096 Jul 29 23:40 dir1
drwxr-xr-x 3 root root 4096 Jul 29 23:41 dir2
drwxr-xr-x 2 root root 4096 Jul 29 23:42 dir3
-rw-r--r-- 1 root root    0 Jul 29 23:28 my.txt
[root@hcss-ecs-f571 learn01]# mkdir -p dir4/dir5/dir6
[root@hcss-ecs-f571 learn01]# ll
total 16
drwxr-xr-x 2 root root 4096 Jul 29 23:40 dir1
drwxr-xr-x 3 root root 4096 Jul 29 23:41 dir2
drwxr-xr-x 2 root root 4096 Jul 29 23:42 dir3
drwxr-xr-x 3 root root 4096 Jul 29 23:42 dir4
-rw-r--r-- 1 root root    0 Jul 29 23:28 my.txt
[root@hcss-ecs-f571 learn01]# tree dir4
dir4
└── dir5└── dir62 directories, 0 files
[root@hcss-ecs-f571 learn01]# 

六、rmdir指令

语法:rmdir [-p] [dirname]

适用对象:具有当前目录操作权限的所有使用者

功能:删除空目录

drwxr-xr-x 6 root root 4096 Jul 29 23:42 learn01
[root@hcss-ecs-f571 ~]# tree learn01
learn01
├── dir1
├── dir2
│   └── dir3
│       └── dir4
│           └── dir5
├── dir3
├── dir4
│   └── dir5
│       └── dir6
└── my.txt
[root@hcss-ecs-f571 learn01]# ll
total 16
drwxr-xr-x 2 root root 4096 Jul 29 23:40 dir1
drwxr-xr-x 3 root root 4096 Jul 29 23:41 dir2
drwxr-xr-x 2 root root 4096 Jul 29 23:42 dir3
drwxr-xr-x 3 root root 4096 Jul 29 23:42 dir4
-rw-r--r-- 1 root root    0 Jul 29 23:28 my.txt
[root@hcss-ecs-f571 learn01]# rmdir dir1
# 直接删除目录dir1
[root@hcss-ecs-f571 learn01]# ll
total 12
drwxr-xr-x 3 root root 4096 Jul 29 23:41 dir2
drwxr-xr-x 2 root root 4096 Jul 29 23:42 dir3
drwxr-xr-x 3 root root 4096 Jul 29 23:42 dir4
-rw-r--r-- 1 root root    0 Jul 29 23:28 my.txt
[root@hcss-ecs-f571 learn01]# rmidr dir2
-bash: rmidr: command not found
[root@hcss-ecs-f571 learn01]# ll
total 12
drwxr-xr-x 3 root root 4096 Jul 29 23:41 dir2
drwxr-xr-x 2 root root 4096 Jul 29 23:42 dir3
drwxr-xr-x 3 root root 4096 Jul 29 23:42 dir4
-rw-r--r-- 1 root root    0 Jul 29 23:28 my.txt
# 指定路径中有不为空的路径,便⽆法删除
[root@hcss-ecs-f571 learn01]# rmdir -p dir2/dir3/dir4
rmdir: failed to remove ‘dir2/dir3/dir4’: Directory not empty
[root@hcss-ecs-f571 learn01]# rmdir -p dir2/dir3/dir4/dir5
[root@hcss-ecs-f571 learn01]# ll
total 8
drwxr-xr-x 2 root root 4096 Jul 29 23:42 dir3
drwxr-xr-x 3 root root 4096 Jul 29 23:42 dir4
-rw-r--r-- 1 root root    0 Jul 29 23:28 my.txt

七、rm指令

语法: rm [-f-i-r-v] [dirName/dir]

适用对象:所有使用者

功能:删除文件或目录

常用选项:

  • -f 即使文件属性为只读(即写保护),亦直接删除
  • -i 删除前逐一询问确认
  • -r 删除目录及其下所有文件
[root@hcss-ecs-f571 learn01]# pwd
/root/learn01
[root@hcss-ecs-f571 learn01]# tree
.
├── dir3
├── dir4
│   └── dir5
│       └── dir6
├── my.txt
└── test.txt4 directories, 2 files
[root@hcss-ecs-f571 learn01]# rm dir3
rm: cannot remove ‘dir3’: Is a directory
[root@hcss-ecs-f571 learn01]# rm -f dir3
rm: cannot remove ‘dir3’: Is a directory
[root@hcss-ecs-f571 learn01]# rm -r dir3
rm: remove directory ‘dir3’? y[root@hcss-ecs-f571 learn01]# rm -r -i dir4
rm: descend into directory ‘dir4’? y
rm: descend into directory ‘dir4/dir5’? y
rm: remove directory ‘dir4/dir5/dir6’? y
rm: remove directory ‘dir4/dir5’? y
rm: remove directory ‘dir4’? y
[root@hcss-ecs-f571 learn01]# tree
.
├── my.txt
└── test.txt0 directories, 2 files
[root@hcss-ecs-f571 learn01]# rm my.txt
rm: remove regular empty file ‘my.txt’? y
[root@hcss-ecs-f571 learn01]# tree
.
└── test.txt0 directories, 1 file

八、man指令

Linux的命令有很多参数,我们不可能全记住,可以通过查看联机手册获取帮助

语法:man [选项] 命令

常用选项

  • -k 根据关键字搜索联机帮助
  • num 只在第num章节查找
  • -a 将所有章节都显示出来

man手册分为9章(不同系统可能会有差别)

  • 1是普通的命令 
  • 2是系统调用,如open,write之类的(通过这个,至少可以很方便的查到调用这个函数,需要加什么头文件)
  • 3是库函数,如printf,fread4是特殊文件,也就是/dev下的各种设备文件
  • 4略
  • 5是指文件的格式,比如passwd,就会说明这个文件中各个字段的含义
  • 6是给游戏留的,由各个游戏⾃⼰定义
  • 7是附件还有⼀些变量,比如像environ这种全局变量在这里就有说明
  • 8是系统管理用的命令,这些命令只能由root使用,如ifconfig
  • 9略

按q退出手册

九、cp指令

语法:cp [选项] 源文件或目录 目标文件或目录

功能:复制文件或目录

解释:

  • cp指令用于复制文件或目录
  • 如同时指定两个以上的文件或目录,且最后的目的地地是⼀个已经存在的⽬录,则它会把前面指定的所有文件或目录复制到此目录中

常用选项:

  • -f或--force强行复制文件或目录,不论目的文件或目录是否已经存在
  • -i或--interactive 覆盖文件之前先询问用户
  • -r递归处理,将指定目录下的文件与子目录⼀并处理。若源文件或目录的形态,不属于目录或符号链接,则⼀律视为普通文件处理
# cp普通文件
[root@hcss-ecs-f571 learn01]# echo "你好,世界">test.txt
[root@hcss-ecs-f571 learn01]# cat test.txt
你好,世界
[root@hcss-ecs-f571 learn01]# cp test.txt test2.txt
[root@hcss-ecs-f571 learn01]# ll
total 8
-rw-r--r-- 1 root root 16 Jul 30 15:29 test2.txt
-rw-r--r-- 1 root root 16 Jul 30 15:28 test.txt
[root@hcss-ecs-f571 learn01]# cat test2.txt
你好,世界# 将多个文件拷贝到指定路径下
[root@hcss-ecs-f571 learn01]# mkdir dir1
[root@hcss-ecs-f571 learn01]# cp *.txt dir1
[root@hcss-ecs-f571 learn01]# tree
.
├── dir1
│   ├── test2.txt
│   └── test.txt
├── test2.txt
└── test.txt1 directory, 4 files
[root@hcss-ecs-f571 learn01]# 
# cp目标文件存在,直接覆盖
[root@hcss-ecs-f571 learn01]# echo "hello word" > test.txt
[root@hcss-ecs-f571 learn01]# cat test.txt
hello word
[root@hcss-ecs-f571 learn01]# cp test.txt test2.txt
cp: overwrite ‘test2.txt’? y
[root@hcss-ecs-f571 learn01]# cat test2.txt
hello word
[root@hcss-ecs-f571 learn01]# 
# 递归强制拷贝整个目录
[root@hcss-ecs-f571 learn01]# cp -rf dir1 dir2
[root@hcss-ecs-f571 learn01]# tree
.
├── dir1
│   ├── test2.txt
│   └── test.txt
├── dir2
│   ├── test2.txt
│   └── test.txt
├── test2.txt
└── test.txt2 directories, 6 files
[root@hcss-ecs-f571 learn01]# 

十、mv指令

        mv命令是move的缩写,可以⽤来移动文件或者将文件改名(move(rename)files,经常⽤来备份文件或者目录(相当于剪切功能)

语法: mv [ 选项 ] 源文件或目录 目标文件或目录

功能:

  • 视mv命令中第⼆个参数类型的不同(是目标文件还是目标目录),mv命令将文件重命名或将其移至⼀个新的目录中。

常用选项:

  • -f:force强制的意思,如果目标文件已经存在,不会询问而直接覆盖 
  • -i:若目标文件(destination)已经存在时,就会询问是否覆盖!
# 更改名称
[root@hcss-ecs-f571 learn01]# tree
.
├── dir1
│   ├── test2.txt
│   └── test.txt
├── dir2
│   ├── test2.txt
│   └── test.txt
├── dir3
├── test2.txt
└── test.txt3 directories, 6 files
[root@hcss-ecs-f571 learn01]# mv test.txt test1.txt
[root@hcss-ecs-f571 learn01]# tree
.
├── dir1
│   ├── test2.txt
│   └── test.txt
├── dir2
│   ├── test2.txt
│   └── test.txt
├── dir3
├── test1.txt
└── test2.txt3 directories, 6 files# 如果当前路径存在同名⽂件,改名即覆盖
[root@hcss-ecs-f571 learn01]# touch test3.txt
[root@hcss-ecs-f571 learn01]# mv test3.txt test2.txt
mv: overwrite ‘test2.txt’? y
[root@hcss-ecs-f571 learn01]# tree
.
├── dir1
│   ├── test2.txt
│   └── test.txt
├── dir2
│   ├── test2.txt
│   └── test.txt
├── dir3
├── test1.txt
└── test2.txt3 directories, 6 files
[root@hcss-ecs-f571 learn01]# # mv整个目录
[root@hcss-ecs-f571 learn01]# tree
.
├── dir1
│   ├── test2.txt
│   └── test.txt
├── dir2
│   ├── test2.txt
│   └── test.txt
├── dir3
├── test1.txt
└── test2.txt3 directories, 6 files
[root@hcss-ecs-f571 learn01]# mv dir3 dir1
[root@hcss-ecs-f571 learn01]# tree
.
├── dir1
│   ├── dir3
│   ├── test2.txt
│   └── test.txt
├── dir2
│   ├── test2.txt
│   └── test.txt
├── test1.txt
└── test2.txt3 directories, 6 files
[root@hcss-ecs-f571 learn01]# [root@hcss-ecs-f571 learn01]# mv dir1 ..
[root@hcss-ecs-f571 learn01]# cd ..
[root@hcss-ecs-f571 ~]# tree
.
├── dir1
│   ├── dir3
│   ├── test2.txt
│   └── test.txt
└── learn01├── dir2│   ├── test2.txt│   └── test.txt├── test1.txt└── test2.txt4 directories, 6 files

十一、cat指令

语法:cat [选项] [文件]

功能:查看目标文件的内容

常用选项:

  • -b对非空输出行编号
  • -n对输出的所有行编号
  • -s不输出多行空行
# 命令⾏构建多⾏⽂本
[root@hcss-ecs-f571 ~]#  cnt=0; while [ $cnt -le 20 ]; do echo "hello word";let cnt++; done > temp.txt
[root@hcss-ecs-f571 ~]# cat temp.txt
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word# cat 输出携带行号
[root@hcss-ecs-f571 ~]# cat -b temp.txt1	hello word2	hello word3	hello word4	hello word5	hello word6	hello word7	hello word8	hello word9	hello word10	hello word11	hello word12	hello word13	hello word14	hello word15	hello word16	hello word17	hello word18	hello word19	hello word20	hello word21	hello word# 修改temp.txt,使其携带多行空行
[root@hcss-ecs-f571 ~]# vim temp.txt# -b 对⾮空输出⾏编号
[root@hcss-ecs-f571 ~]# cat -b temp.txt1	hello word2	hello word3	hello word4	hello word5	hello word6	hello word7	hello word8	hello word9	hello word10	hello word11	hello word12	hello word13	hello word14	hello word15	hello word16	hello word17	hello word18	hello word19	hello word20	hello word21	hello word
# -n 对输出的所有⾏编号
[root@hcss-ecs-f571 ~]# cat -n temp.txt1	hello word2	hello word3	hello word4	hello word5	hello word6	hello word7	hello word8	hello word9	hello word10	hello word11	hello word12	hello word13	hello word14	hello word15	hello word16	hello word17	hello word18	hello word19	20	21	22	23	hello word24	hello word25	26	27	hello word
# -s 不输出多⾏空⾏,多⾏空⾏压缩成为⼀⾏
[root@hcss-ecs-f571 ~]# cat -s temp.txt
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello wordhello word
hello wordhello word
[root@hcss-ecs-f571 ~]#

十二、more指令

语法:more [选项]

功能:more命令,功能类似cat

常用选项:

  • -n指定输出行数
  • q退出more
# 命令行输出2000行"hello word"
[root@hcss-ecs-f571 ~]#  cnt=0; while [ $cnt -le 2000 ]; do echo "hello word";let cnt++; done > temp.txt
# -n 指定输出的行数
[root@hcss-ecs-f571 ~]# more -10 temp.txt
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
hello word
--More--(0%)

十三、less指令

语法:less [参数] 文件

功能:less与more类似,但使用less可以随意浏览文件,而more仅能向前移动,却不能向后移动,而且less在查看之前不会加载整个文件。

  • less⼯具也是对文件或其它输出进行分页显示的⼯具,应该说是linux正统查看文件内容的工具, 功能极其强⼤
  •  less的用法比起more更加的有弹性,在more的时候,我们并没有办法向前面翻,只能往后面看
  • 若使⽤了less,就可以使用[pageup][pagedown]等按键的功能来往前往后翻看文件,更 容易用来查看⼀个文件的内容
  •  除此之外,在less里头可以拥有更多的搜索功能,不止可以向下搜,也可以向上搜。

选项: 

  • -i 忽略搜索时的大小写
  • -N 显示每行的行号
  •  /字符串:向下搜索“字符串”的功能
  •  ?字符串:向上搜索“字符串”的功能
  •  n:重复前一个搜索(与/或?有关)
  •  N:反向重复前⼀个搜索(与/或?有关)
  •  q:quit
[root@hcss-ecs-f571 ~]# less -N temp.txt 1 hello 02 hello 13 hello 24 hello 35 hello 46 hello 57 hello 68 hello 79 hello 810 hello 911 hello 1012 hello 1113 hello 1214 hello 1315 hello 1416 hello 1517 hello 1618 hello 1719 hello 1820 hello 1921 hello 2022 hello 2123 hello 2224 hello 2325 hello 2426 hello 2527 hello 2628 hello 2729 hello 2830 hello 2931 hello 3032 hello 31
...

十四、head指令和tail指令

        head与tail就像它的名字⼀样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head用来显示档案的开头至标准输出中,而tail就是看档案的结尾。

1.head指令

语法:head [参数] [文件]

功能:head用来显示档案的开头至标准输出中,默认head命令打印其相应⽂件的开头10行。

选项:

  •  -n<行数>显示的行数
[root@hcss-ecs-f571 ~]# head temp.txt
hello 0
hello 1
hello 2
hello 3
hello 4
hello 5
hello 6
hello 7
hello 8
hello 9[root@hcss-ecs-f571 ~]# head -5 temp.txt
hello 0
hello 1
hello 2
hello 3
hello 4
[root@hcss-ecs-f571 ~]# 

2.tail指令

        tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail-f filename会把filename里最尾部的内容显示在屏幕上,并且不断刷新,使你看到最新的文件内容。

语法:tail 必要参数 [文件]

功能:用于显示指定文件末尾内容,不指定文件时,作为输入信息进行处理。常用查看日志文件。

选项: 

  • -f 循环读取
  • -n<行数> 显示行数
[root@hcss-ecs-f571 ~]# tail temp.txt
hello 1991
hello 1992
hello 1993
hello 1994
hello 1995
hello 1996
hello 1997
hello 1998
hello 1999
hello 2000
[root@hcss-ecs-f571 ~]# 
[root@hcss-ecs-f571 ~]# tail -4 temp.txt
hello 1997
hello 1998
hello 1999
hello 2000
[root@hcss-ecs-f571 ~]# 

用管道对数据进行操作:显示文件[250, 300]

[root@hcss-ecs-f571 ~]# head -250 temp.txt | tail -50
hello 200
hello 201
hello 202
hello 203
hello 204
hello 205
hello 206
hello 207
hello 208
hello 209
hello 210
hello 211
hello 212
hello 213
hello 214
hello 215
hello 216
hello 217
hello 218
hello 219
hello 220
hello 221
hello 222
hello 223
hello 224
hello 225
hello 226
hello 227
hello 228
hello 229
hello 230
hello 231
hello 232
hello 233
hello 234
hello 235
hello 236
hello 237
hello 238
hello 239
hello 240
hello 241
hello 242
hello 243
hello 244
hello 245
hello 246
hello 247
hello 248
hello 249

十五、data指令

1.在显示方面:可以设定欲显示的格式,格式设定为⼀个加号后接数个标记,其中常用的标记列表如下:

  • %H:小时(00..23)
  •  %M:分钟(00..59)
  •  %S:秒(00..61)
  •  %X:相当于%H:%M:%S
  •  %d:日(01..31)
  •  %m:月份(01..12)
  •  %Y:完整年份(0000..9999)
  •  %F:相当于%Y-%m-%d

2.在设定时间方面:

  • date-s//设置当前时间,只有root权限才能设置,其他只能查看。
  •  date-s20080523//设置成20080523,这样会把具体时间设置成空00:00:00
  •  date-s01:01:01//设置具体时间,不会对日期做更改
  •  date-s“01:01:012008-05-23″//这样可以设置全部时间
  •  date-s“01:01:0120080523″//这样可以设置全部时间
  •  date-s“2008-05-2301:01:01″//这样可以设置全部时间
  •  date-s“2008052301:01:01″//这样可以设置全部时间

3. 时间戳

  • 时间->时间戳:date+%s
  •  时间戳->时间:date-d@1508749502
  •  Unix时间戳(英⽂为Unixepoch,Unixtime,POSIXtime或Unixtimestamp)是从1970年1⽉1 ⽇(UTC/GMT的午夜)开始所经过的秒数,不考虑闰秒
[root@hcss-ecs-f571 ~]# date
Wed Jul 30 17:53:13 CST 2025
[root@hcss-ecs-f571 ~]# date %Y
date: invalid date ‘%Y’
[root@hcss-ecs-f571 ~]# date +%Y
2025
[root@hcss-ecs-f571 ~]# date %Y
date: invalid date ‘%Y’
[root@hcss-ecs-f571 ~]# y
-bash: y: command not found
[root@hcss-ecs-f571 ~]# date +%Y/%m/%d-%H:%M:%S
2025/07/30-17:54:41
[root@hcss-ecs-f571 ~]# date +%Y/%m/%d-%H:%M:%S -d @0
1970/01/01-08:00:00
[root@hcss-ecs-f571 ~]# 

十六、cal指令

        cal命令可以用来显示公历(阳历)日历。

公历是现在国际通用的历法,又称格列历,通称阳历。

“阳 历”又名“太阳历”,系以地球绕行太阳一周为一年,为西方各国所通用,故又名“西历”。

命令格式:cal 参数 [年份]

功能:用于查看日历等时间信息,如只有一个参数,则表示年份(1-9999),如有两个参数,则表示月份和年份

常用选项:

  • -3显示系统前⼀个月,当前月,下一个月的月历
  • -j 显示在当年中的第几天(⼀年日期按天算,从1月1号算起,默认显示当前月在⼀年中的天数)
  • -y 显示当前年份的日历
[root@hcss-ecs-f571 ~]# cal -y2025                               January               February                 March       
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa1  2  3  4                      1                      15  6  7  8  9 10 11    2  3  4  5  6  7  8    2  3  4  5  6  7  8
12 13 14 15 16 17 18    9 10 11 12 13 14 15    9 10 11 12 13 14 15
19 20 21 22 23 24 25   16 17 18 19 20 21 22   16 17 18 19 20 21 22
26 27 28 29 30 31      23 24 25 26 27 28      23 24 25 26 27 28 2930 31April                   May                   June        
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa1  2  3  4  5                1  2  3    1  2  3  4  5  6  76  7  8  9 10 11 12    4  5  6  7  8  9 10    8  9 10 11 12 13 14
13 14 15 16 17 18 19   11 12 13 14 15 16 17   15 16 17 18 19 20 21
20 21 22 23 24 25 26   18 19 20 21 22 23 24   22 23 24 25 26 27 28
27 28 29 30            25 26 27 28 29 30 31   29 30July                  August                September     
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa1  2  3  4  5                   1  2       1  2  3  4  5  66  7  8  9 10 11 12    3  4  5  6  7  8  9    7  8  9 10 11 12 13
13 14 15 16 17 18 19   10 11 12 13 14 15 16   14 15 16 17 18 19 20
20 21 22 23 24 25 26   17 18 19 20 21 22 23   21 22 23 24 25 26 27
27 28 29 30 31         24 25 26 27 28 29 30   28 29 3031October               November               December      
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa1  2  3  4                      1       1  2  3  4  5  65  6  7  8  9 10 11    2  3  4  5  6  7  8    7  8  9 10 11 12 13
12 13 14 15 16 17 18    9 10 11 12 13 14 15   14 15 16 17 18 19 20
19 20 21 22 23 24 25   16 17 18 19 20 21 22   21 22 23 24 25 26 27
26 27 28 29 30 31      23 24 25 26 27 28 29   28 29 30 3130[root@hcss-ecs-f571 ~]# cal -jJuly 2025         
Sun Mon Tue Wed Thu Fri Sat182 183 184 185 186
187 188 189 190 191 192 193
194 195 196 197 198 199 200
201 202 203 204 205 206 207
208 209 210 211 212[root@hcss-ecs-f571 ~]# 

http://www.xdnf.cn/news/16601.html

相关文章:

  • 无人机磁力计模块运行与技术要点!
  • iOS 签名证书与上架流程详解,无 Mac 环境下的上架流程
  • 传输层协议UDP与TCP
  • 云计算:一场关于“数字水电煤”的革命与未来
  • 通用定时器Timer的基本模式
  • 元码智能“大眼睛”机器人首发,智启生活新纪元!
  • 数据库初阶笔记
  • 招工招聘小程序系统开发——打造一站式招聘服务平台
  • 【MySQL】MySQL索引—B树/B+树
  • 【NLP舆情分析】基于python微博舆情分析可视化系统(flask+pandas+echarts) 视频教程 - 微博内容IP地图可视化分析实现
  • 测试工作中一些有用的链接
  • string类的模拟实现
  • 标准七层网络协议和TCP/IP四层协议的区别
  • TP-Link Archer C50路由器曝安全漏洞,硬编码DES密钥可解密敏感配置
  • JavaScript语法、关键字和变量
  • 外网访问文档编辑器Docsify(Windows版本),内网穿透技术应用简便方法
  • AD里面出现元器件PCB封装不能编辑的情况
  • 湖北大学暑期实训优秀作品:面向美丽中国的数据化可视平台
  • Ubuntu LNMP
  • 《安富莱嵌入式周报》第356期:H7-TOOL的250M示波器模组批量生产中,自主开发QDD执行器,开源14bit任意波形发生器(2025-07-28)
  • 【Linux】重生之从零开始学习运维之Mysql事务
  • Kubernetes自动扩容方案
  • 【C语言进阶】题目练习
  • 《 java 随想录》| LeetCode链表高频考题
  • Linux文件归档和备份
  • 云原生MySQL Operator开发实战(五):扩展与生态系统集成
  • 基于Matlab图像处理的静态雨滴去除与质量评估系统
  • windows下Docker安装路径、存储路径修改
  • Docker初学者需要了解的几个知识点(三):Docker引擎与Docker Desktop
  • 实时行情接口使用教程