alias 快捷命令操作 [root@MR ~]# cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin [root@MR ~]# alias passwd='cat /etc/passwd' [root@MR ~]# passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#(如果你先重启电脑还能使用的话,请往下看) [root@MR ~]# ls -a [root@MR ~]# vim .bashrc (按字母“i”进入编辑模式) # .bashrc
# User specific aliases and functions
alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' alias network='cd /etc/sysconfig/network-scripts' alias passwd='cat /etc/passwd'#(将此行命令添加进去) # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc #(如果你想任何用户都可以使用得话,请添加之此文本文件/etc/bashrc) fi (狂按‘esc键’输入":wq")
[root@MR ~]# history 1 ls 2 history 3 echo `$a` 4 cd /etc/sysconfig/network-scripts/ ......以下省略.........
常用选项
-c 清除历史命令
1 2 3
[root@MR ~]# history -c [root@MR ~]# history 1 history
-d 一般后接参数,删除第几条命名
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[root@MR ~]# history 1 history 2 cd 3 pwd 4 ls 5 mv 6 history [root@MR ~]# history -d 4 [root@MR ~]# history 1 history 2 cd 3 pwd 4 mv 5 history 6 history -d 4 7 history
-w 保存文件到当前用户下的/.bash_history 中
1 2 3 4 5 6 7 8 9 10
[root@MR ~]# history -w [root@MR ~]# cat .bash_history history cd pwd mv history history -d 4 history history -w
!n 再次执行历史命令中的第n条历史命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
[root@MR ~]# history 1 history 2 cd 3 pwd 4 mv 5 history 6 history -d 4 7 history 8 history -w 9 cat bash_history 10 cat .bash_history 11 history [root@MR ~]# !3 pwd /root
!-n 再次执行历史命令中倒数第n条命令
1 2 3 4 5 6 7 8
[root@MR ~]# history .......以上省略........ 15 stat a 16 cd 17 ls 18 history [root@MR ~]# !-3 cd
[root@MR ~]# history ..........以上省略.......... 28 stat a 29 cd 30 ls 31 stat a 32 ls 33 cd 34 pwd 35 historiy 36 history [root@MR ~]# !stat stat a 文件:"a" 大小:22 块:0 IO 块:4096 目录 设备:fd00h/64768d Inode:694 硬链接:4 权限:(0755/drwxr-xr-x) Uid:( 0/ root) Gid:( 0/ root) 环境:unconfined_u:object_r:admin_home_t:s0 最近访问:2019-03-17 15:19:50.679860493 +0800 最近更改:2019-03-17 15:19:43.697860882 +0800 最近改动:2019-03-17 15:19:43.697860882 +0800 创建时间:-
[root@MR /]# cd /etc/sys sysconfig/ sysctl.d/ system-release sysctl.conf systemd/ system-release-cpe [root@MR /]# cd /etc/sysconfig/
bash命令别名
1 2 3 4 5 6 7 8 9 10
alias 快捷命令操作 [root@MR ~]# cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin [root@MR ~]# alias passwd='cat /etc/passwd' [root@MR ~]# passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#(如果你先重启电脑还能使用的话,请往下看) [root@MR ~]# ls -a [root@MR ~]# vim .bashrc (按字母“i”进入编辑模式) # .bashrc
# User specific aliases and functions
alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' alias network='cd /etc/sysconfig/network-scripts' alias passwd='cat /etc/passwd'#(将此行命令添加进去) # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc #(如果你想任何用户都可以使用得话,请添加之此文本文件/etc/bashrc) fi (狂按‘esc键’输入":wq")
[root@MR ~]# ls 1 2 3 A anaconda-ks.cfg b [root@MR ~]# cp 1 2 3 A [root@MR ~]# cd A [root@MR A]# ls 1 2 3
[root@MR ~]# ls -l 总用量 4 drwxr-xr-x. 2 root root 6 3月 23 18:12 A -rw-------. 1 root root 810 3月 6 16:33 anaconda-ks.cfg [root@MR ~]# cp -arp A b [root@MR ~]# ls -l 总用量 4 drwxr-xr-x. 2 root root 6 3月 23 18:12 A -rw-------. 1 root root 810 3月 6 16:33 anaconda-ks.cfg drwxr-xr-x. 2 root root 6 3月 23 18:12 b
mv:移动文件(重命名)
1 2 3 4 5 6 7 8
[root@MR ~]# ls 1 2 3 A anaconda-ks.cfg b [root@MR ~]# mv A B [root@MR ~]# ls 1 2 3 anaconda-ks.cfg b B [root@MR ~]# mv b B [root@MR ~]# ls B 1 2 3 b
cat:顺序查看文本内容
拼接文件内容并输出至标准输出(屏幕)
-n:显示行号
1 2 3 4 5 6 7 8 9
[root@MR ~]# cat -n anaconda-ks.cfg 1 #version=RHEL7 2 # System authorization information 3 auth --enableshadow --passalgo=sha512 4 5 # Use CDROM installation media 6 cdrom 7 # Run the Setup Agent on first boot ............以下省略.............
tac:逆序查看文件内容
连接文件并倒序打印内容至标准输出
1 2 3 4 5 6 7 8 9
[root@MR ~]# tac anaconda-ks.cfg
%end
@core %packages
clearpart --none --initlabel # Partition clearing information
more:全屏查看文本文件内容
只能从前往后看,百分比查看,看完自动退出
1 2 3 4 5 6 7 8 9 10
[root@MR ~]# more anaconda-ks.cfg #version=RHEL7 # System authorization information auth --enableshadow --passalgo=sha512
# Use CDROM installation media cdrom # Run the Setup Agent on first boot
--More--(34%)
less:全屏查看文本文件内容
可从前往后看亦可从后往前看,看完不会自动退出
(往上是b,往下是空格,退出是q)
head:从前往后查看一定行数
默认下显示前十行,我们也可以输入-n 【输入一个数字】来查看你想要看到的前多少行
1 2 3 4 5 6 7
[root@MR ~]# head CentOS-Base.repo # CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the ......................以下省略7条........................ [root@MR ~]# head -n 1 CentOS-Base.repo # CentOS-Base.repo
[root@zhoulijie opt]# ls 123456789 185dcdvdv 1cshcd acvbfv bgfdbdsgv [root@zhoulijie opt]# rm -rf 1* [root@zhoulijie opt]# ls acvbfv bgfdbdsgv
?:是匹配任意单个字符
1 2 3 4
[root@zhoulijie opt]# ls acvbfv al bgfdbdsgv [root@zhoulijie opt]# ls a? al
[]:是匹配指定范围内的单个字符
1 2 3 4 5 6 7 8
[root@zhoulijie wen]# ls 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m [root@zhoulijie wen]# ls [1-9] 1 2 3 4 5 6 7 8 9 [root@zhoulijie wen]# ls [1,a] 1 a [root@zhoulijie wen]# ls [a-h] a b c d e f g h
[^]:是匹配指定范围之外的任意单个字符
1 2 3 4
[root@zhoulijie wen]# ls [^a-m] 1 2 3 4 5 6 7 8 9 [root@zhoulijie wen]# ls [^1-9] a b c d e f g h i j k l m
常见的归档与压缩文档格式
.gz
.bz2
.xz
.zip
.z
归档工具–tar
常见的选项:
-c:创建归档文件
-f file.tar:指定要操作的归档文件
-x:还原归档文件
-v:显示归档过程
-p:归档时保留权限信息。只有管理员才有此权限用此选项
-C:指定还原归档或解压时的目录
-tf:不展开归档,直接查看归档了哪些文件
常用的组合项:
-zcf abc.tar.gz:归档并调用gzip进行压缩
1 2 3 4 5
[root@MR ~]# ls 1 2 3 anaconda-ks.cfg B [root@MR ~]# tar -zcf abc.tar.gz 1 2 3 [root@MR ~]# ls 1 2 3 abc.tar.gz anaconda-ks.cfg B
-jcf abc.tar.bz2:归档并调用bzip2进行压缩
1 2 3
[root@MR ~]# tar -jcf abc.tar.bz2 1 2 3 [root@MR ~]# ls 1 2 3 abc.tar.bz2 abc.tar.gz anaconda-ks.cfg B
-Jcf abc.tar.xz:归档并调用xz进行压缩
1 2 3
[root@MR ~]# tar -Jcf abc.tar.xz 1 2 3 [root@MR ~]# ls 1 2 3 abc.tar.bz2 abc.tar.gz abc.tar.xz anaconda-ks.cfg B
-xf abc.tar.gz:解压
-C 是指定解压后的文件放哪里
1 2 3 4
[root@MR ~]# mkdir q [root@MR ~]# tar -xf abc.tar.bz2 -C q [root@MR ~]# ls q 1 2 3