7.6总结与练习

1、当前用户永久生效的命令别名
(1)写一个命令命为hello,实现的功能为每输入一次hello命令,就有hello,everyone写入文
件/file.txt中。

[root@server ~]# vim /etc/profile
[root@server ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias xzegrep='xzegrep --color=auto'
alias xzfgrep='xzfgrep --color=auto'
alias xzgrep='xzgrep --color=auto'
alias zegrep='zegrep --color=auto'
alias zfgrep='zfgrep --color=auto'
alias zgrep='zgrep --color=auto'
[root@server ~]# source /etc/profile
[root@server ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias hello='echo hello,everyone >> /file.txt'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias xzegrep='xzegrep --color=auto'
alias xzfgrep='xzfgrep --color=auto'
alias xzgrep='xzgrep --color=auto'
alias zegrep='zegrep --color=auto'
alias zfgrep='zfgrep --color=auto'
alias zgrep='zgrep --color=auto'
[root@server ~]# cat /file.txt 
hello,everyone
hello,everyone

(2)写一个命令别名为shuaxin,实现的功能为每输入一次该命令,file.txt文件的所有时间就更新为当前
时间。

[root@server ~]# vim + /etc/profile
[root@server ~]# source /file.txt 
[root@server ~]# stat /file.txt 
  File: /file.txt
  Size: 45        	Blocks: 8          IO Block: 4096   regular file
Device: 10303h/66307d	Inode: 1363084     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-25 21:06:53.057612526 -0400
Modify: 2022-10-25 21:04:33.368476727 -0400
Change: 2022-10-25 21:04:33.368476727 -0400
 Birth: 2022-10-24 10:55:38.870695269 -0400
[root@server ~]# hh
[root@server ~]# shuaxin 
[root@server ~]# stat /file.txt 
  File: /file.txt
  Size: 45        	Blocks: 8          IO Block: 4096   regular file
Device: 10303h/66307d	Inode: 1363084     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-25 21:07:31.178195378 -0400
Modify: 2022-10-25 21:07:31.178195378 -0400
Change: 2022-10-25 21:07:31.178195378 -0400
 Birth: 2022-10-24 10:55:38.870695269 -0400

s
2、所有用户生效的命令别名
写一个所有用户都生效的命令别名为hh,每一个用户输入这个命令之后可以在该用户家目录下创建一个file1
文件。

[root@server ~]# vim /etc/profile
[root@server ~]# source /etc/profile
Session lifetime based on X11 requested, but X11 initialization failed.
[root@server ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias hello='echo hello,everyone >> /file.txt'
alias hh='touch $HOME/file1'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias xzegrep='xzegrep --color=auto'
alias xzfgrep='xzfgrep --color=auto'
alias xzgrep='xzgrep --color=auto'
alias zegrep='zegrep --color=auto'
alias zfgrep='zfgrep --color=auto'
alias zgrep='zgrep --color=auto'
[root@server ~]# ll /root
total 12
-rw-r--r--. 1 root root    0 Oct 24 10:40 abc
-rw-------. 1 root root 1220 Oct 15 16:02 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 Oct 15 16:28 Desktop
drwxr-xr-x. 2 root root    6 Oct 15 16:28 Documents
drwxr-xr-x. 2 root root    6 Oct 15 16:28 Downloads
-rw-r--r--. 1 root root    2 Oct 24 10:21 hello.everyone
-rw-r--r--. 1 root root 1492 Oct 15 16:07 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 Oct 15 16:28 Music
drwxr-xr-x. 2 root root    6 Oct 15 16:28 Pictures
drwxr-xr-x. 2 root root    6 Oct 15 16:28 Public
drwxr-xr-x. 2 root root    6 Oct 15 16:28 Templates
drwxr-xr-x. 2 root root    6 Oct 15 16:28 Videos
[root@server ~]# hh
[root@server ~]# ll /root
total 12
-rw-r--r--. 1 root root    0 Oct 24 10:40 abc
-rw-------. 1 root root 1220 Oct 15 16:02 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 Oct 15 16:28 Desktop
drwxr-xr-x. 2 root root    6 Oct 15 16:28 Documents
drwxr-xr-x. 2 root root    6 Oct 15 16:28 Downloads
-rw-r--r--. 1 root root    0 Oct 25 20:55 file1
-rw-r--r--. 1 root root    2 Oct 24 10:21 hello.everyone
-rw-r--r--. 1 root root 1492 Oct 15 16:07 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 Oct 15 16:28 Music
drwxr-xr-x. 2 root root    6 Oct 15 16:28 Pictures
drwxr-xr-x. 2 root root    6 Oct 15 16:28 Public
drwxr-xr-x. 2 root root    6 Oct 15 16:28 Templates
drwxr-xr-x. 2 root root    6 Oct 15 16:28 Videos
[root@server ~]# 
[su@server ~]$ pwd
/home/su
[su@server ~]$ ll
total 0
[su@server ~]$ hh
[su@server ~]$ ll
total 0
-rw-rw-r--. 1 su su 0 Oct 25 20:56 file1

3、命令历史:查看命令历史,并且调用第十行命令

[root@server ~]# history
ping 114.114.114.114
PING 114.114.114.114 (114.114.114.114) 56(84) bytes of data.
64 bytes from 114.114.114.114: icmp_seq=1 ttl=92 time=61.2 ms
64 bytes from 114.114.114.114: icmp_seq=2 ttl=68 time=32.9 ms
64 bytes from 114.114.114.114: icmp_seq=3 ttl=75 time=39.2 ms
^X64 bytes from 114.114.114.114: icmp_seq=4 ttl=83 time=44.5 ms
^C
--- 114.114.114.114 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3006ms
rtt min/avg/max/mdev = 32.918/44.450/61.209/10.507 ms
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值