命令解释器-shell
一、当前用户永久生效的命令别名
(1)写一个命令命为hello,实现的功能为每输入一次hello命令,就有hello,everyone写入文件/file.txt中
[root@server /]
[root@server /]
[root@server /]
hello,everyone
[root@server /]
文件内容输入:alias hello='echo hello,echo everyone >> /file.txt'
保存并退出文件:`ESC + wq`
[root@server /]
[root@server /]
[root@server /]
[root@server /]
(2)写一个命令别名为shuaxin,实现的功能为每输入一次该命令,file.txt文件的所有时间就更新为当前时间
[root@server /]
[root@server /]
File: file.txt
Size: 54 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 1546109 Links: 1
Access: (0646/-rw-r--rw-) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:etc_runtime_t:s0
Access: 2022-10-26 19:41:03.515650898 +0800
Modify: 2022-10-26 19:40:57.060651021 +0800
Change: 2022-10-26 19:40:57.060651021 +0800
Birth: 2022-10-26 19:26:44.414667289 +0800
[root@server /]
[root@server /]
File: file.txt
Size: 54 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 1546109 Links: 1
Access: (0646/-rw-r--rw-) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:etc_runtime_t:s0
Access: 2022-10-26 19:43:15.444648381 +0800
Modify: 2022-10-26 19:43:15.444648381 +0800
Change: 2022-10-26 19:43:15.444648381 +0800
Birth: 2022-10-26 19:26:44.414667289 +0800
[root@server /]
文件内容输入:alias shuaxin='touch /file.txt'
保存并退出文件:`ESC + wq`
[root@server /]
二、所有用户生效的命令别名
(1)写一个所有用户都生效的命令别名为hh,每一个用户输入这个命令之后可以在该用户家目录下创建一个file1文件
[root@server /]
文件内容输入:alias hh='touch $HOME/file1'
保存并退出文件:`ESC + wq`
[root@server /]
[root@server /]
[root@server ~]
-rw-r--r--. 1 root root 0 Oct 26 20:58 /root/file1
[root@server ~]
[xue@server ~]$ hh
[xue@server ~]$ ll /home/xue/file1
-rw-rw-r--. 1 xue xue 0 Oct 26 20:59 /home/xue/file1
三、命令历史:
(1)查看命令历史,并且调用第十行命令
[root@server ~]
1 clear
2 hostname server.local
3 cat /etc/hostname
4 hostname server.local
5 cat /etc/hostname
6 hostnamectl set-hostname server.local
7 cat /etc/hostname
8 clear
9 ifconfig
10 ip address
......
[root@server ~]
cat /etc/hostname
server.local
四、总结
![在这里插入图片描述](https://img-blog.csdnimg.cn/a650c85fa4ca43beac8f3517eb91b4d9.png#pic_center)