RHCSAday5-命令解释器-shell

命令解释器-shell

一、当前用户永久生效的命令别名

(1)写一个命令命为hello,实现的功能为每输入一次hello命令,就有hello,everyone写入文件/file.txt中
#当前终端生效
[root@server /]# alias hello='echo hello,echo everyone >> /file.txt'
[root@server /]# hello
[root@server /]# cat /file.txt 
hello,everyone
#当前用户生效
[root@server /]# vim /root/.bashrc 
文件内容输入:alias hello='echo hello,echo everyone >> /file.txt'
保存并退出文件:`ESC + wq` 
[root@server /]# source /root/.bashrc 
[root@server /]# hello
[root@server /]# bash
[root@server /]# hello
(2)写一个命令别名为shuaxin,实现的功能为每输入一次该命令,file.txt文件的所有时间就更新为当前时间
#当前终端
[root@server /]# alias shuaxin='touch /file.txt'
[root@server /]# stat file.txt 
  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 /]# shuaxin
[root@server /]# stat file.txt 
  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 /]# vim /root/.bashrc 
文件内容输入:alias shuaxin='touch /file.txt'
保存并退出文件:`ESC + wq` 
[root@server /]# source /root/.bashrc

二、所有用户生效的命令别名

(1)写一个所有用户都生效的命令别名为hh,每一个用户输入这个命令之后可以在该用户家目录下创建一个file1文件
[root@server /]# vim /etc/bashrc
文件内容输入:alias hh='touch $HOME/file1'
保存并退出文件:`ESC + wq` 
[root@server /]# source /etc/bashrc
[root@server /]# hh
[root@server ~]# ll /root/file1 
-rw-r--r--. 1 root root 0 Oct 26 20:58 /root/file1
[root@server ~]# su - xue
[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 ~]# history 
    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 ~]# !5
cat /etc/hostname 
server.local

四、总结

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值