命令解释器shell

发布于:2022-10-29 ⋅ 阅读:(910) ⋅ 点赞:(0)

目录

一、思维导图

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

1、写一个命令命为hello,实现的功能为每输入一次hello命令,就有hello,everyone写入文件/file.txt中。

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

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

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

四、命令历史

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


一、思维导图

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

1、写一个命令命为hello,实现的功能为每输入一次hello命令,就有hello,everyone写入文件/file.txt中。

[root@localhost ~]# vim .bashrc

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias hello="echo hello,everyone > /file.txt"

[root@localhost ~]# source .bashrc
[root@localhost ~]# hello
[root@localhost ~]# cat /file.txt
hello,everyone

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

[root@localhost ~]# vim .bashrc

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias hello="echo hello,everyone > /file.txt"
alias shuaxin='touch /file.txt'

[root@localhost ~]# source .bashrc
[root@localhost ~]# ll /file.txt
-rw-r--r--. 1 root root 15 Oct 29 01:19 /file.txt
[root@localhost ~]# shuaxin
[root@localhost ~]# ll /file.txt
-rw-r--r--. 1 root root 15 Oct 29 01:28 /file.txt

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

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

[root@localhost ~]# vim /etc/profile

# /etc/profile

alias hh='touch ~/file1'  //在/etc/profile中加入此行命令,保存退出

[root@localhost ~]# source /etc/profile
[root@localhost ~]# hh
[root@localhost ~]# ll
total 16
-rw-------. 1 root root 1468 Oct 22 21:05 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 Oct 22 21:10 Desktop
drwxr-xr-x. 2 root root    6 Oct 22 21:10 Documents
drwxr-xr-x. 2 root root    6 Oct 22 21:10 Downloads
-rw-r--r--. 1 root root    0 Oct 26 15:36 file1
-rw-r--r--. 1 root root 1821 Oct 22 21:09 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 Oct 22 21:10 Music
-rw-r--r--. 1 root root 7475 Oct 23 15:25 myfile.zip
drwxr-xr-x. 2 root root    6 Oct 22 21:10 Pictures
drwxr-xr-x. 2 root root    6 Oct 22 21:10 Public
drwxr-xr-x. 2 root root    6 Oct 22 21:10 Templates
drwxr-xr-x. 2 root root   28 Oct 23 15:48 test
drwxr-xr-x. 2 root root    6 Oct 22 21:10 Videos

四、命令历史

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

[root@localhost ~]# history
    1  cat /etc/redhat-release
    2  mkdir /test
    3  cd /test
    4  touch passwd group bashrc profile sshd_config
    5  ll
    6  ln -s /etc/motd motd.soft
    7  ln /etc/motd motd.hard
    8  ll
    9  uname -r /motd.soft
   10  cat /test/motd.soft

[root@localhost ~]# !10
cat /test/motd.soft
4.18.0-348.el8.x86_64
Red Hat Enterprise Linux release 8.5 (Ootpa)
localhost.localdomain
/bin/bash