1、当前用户永久生效的命令别名
(1)写一个命令命为hello,实现的功能为每输入一次hello命令,就有hello,everyone写入文件/file.txt中。
[root@server ~]# vim ./.bashrc
在.bashrc文件中:
检查测试是否可用:
[root@server ~]# source ./.bashrc [root@server ~]# hello [root@server ~]# cat /file.txt hello,everyone [root@server ~]# hello [root@server ~]# cat /file.txt -n 1 hello,everyone 2 hello,everyone
(2)写一个命令别名为shuaxin,实现的功能为每输入一次该命令,file.txt文件的所有时间就更新为当前时间。
[root@server ~]# vim ./.bashrc
在.bashrc文件中写入:
检查测试是否可用:
[root@server ~]# stat /file.txt File: /file.txt Size: 30 Blocks: 8 IO Block: 4096 regular file Device: fd00h/64768d Inode: 693411 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:etc_runtime_t:s0 Access: 2022-10-26 21:46:50.034026978 +0800 Modify: 2022-10-26 21:46:42.396026995 +0800 Change: 2022-10-26 21:46:42.396026995 +0800 Birth: 2022-10-26 21:46:31.245027021 +0800 [root@server ~]# source ./.bashrc [root@server ~]# shuaxin [root@server ~]# stat /file.txt File: /file.txt Size: 30 Blocks: 8 IO Block: 4096 regular file Device: fd00h/64768d Inode: 693411 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:etc_runtime_t:s0 Access: 2022-10-26 21:50:13.565026517 +0800 Modify: 2022-10-26 21:50:13.565026517 +0800 Change: 2022-10-26 21:50:13.565026517 +0800 Birth: 2022-10-26 21:46:31.245027021 +0800
2、所有用户生效的命令别名
写一个所有用户都生效的命令别名为hh,每一个用户输入这个命令之后可以在该用户家目录下创建一个file1文件。
[root@server ~]# vim /etc/bashrc
在/etc/bashrc文件中写入:
检查测试是否可用:
[root@server ~]# source /etc/bashrc [root@server ~]# hh [root@server ~]# stat ~/file1 File: /root/file1 Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd00h/64768d Inode: 51120361 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2022-10-26 22:29:28.587021422 +0800 Modify: 2022-10-26 22:29:28.587021422 +0800 Change: 2022-10-26 22:29:28.587021422 +0800 Birth: 2022-10-26 22:29:28.587021422 +0800
在其他用户界面创建:
[root@server ~]# su - rhcsa [rhcsa@server ~]$ hh [rhcsa@server ~]$ ll ~/file1 -rw-rw-r--. 1 rhcsa rhcsa 0 Oct 26 22:33 /home/rhcsa/file1 [rhcsa@server ~]$ stat ~/file1 File: /home/rhcsa/file1 Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd02h/64770d Inode: 452 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 1000/ rhcsa) Gid: ( 1000/ rhcsa) Context: unconfined_u:object_r:user_home_t:s0 Access: 2022-10-26 22:33:01.625020939 +0800 Modify: 2022-10-26 22:33:01.625020939 +0800 Change: 2022-10-26 22:33:01.625020939 +0800 Birth: 2022-10-26 22:33:01.625020939 +0800
3、命令历史:查看命令历史,并且调用第十行命令
[root@server ~]# history
查看历史命令并调用第十行:
总结:
喜欢的话点赞加关注哦,后续精彩教程小编会持续为大家更。ヾ(≧▽≦*)o