次日重点
bash-4.1$ :修改配置文件 .bashrc 删除.bashrc ,添加就行了
[root@centos /home/basher]#ls -a
. .bash_logout .bashrc .mozilla
.. .bash_profile .gnome2
[root@centos /home/basher]# rm /home/basher/.bashrc
rm: remove regular file `/home/basher/.bashrc'? y
[root@centos /home/basher]#su - basher
[basher@centos ~]$bash
bash-4.1$
echo $SHELLhtml
一、centos6——centos7 相连
ssh @root 172.18.118.243 22
screen -S HELP
screen -ls
screen -x HELP
二、
linux 密码不记得,怎么办node
第三天重点:
文件名规则:除了斜杠和nul linux
[root@centos7 ~]#rpm -qa |grep man 查看包是否安装
man 中文包安装:
mount /dev/cdrom /media 挂载,并安装
systemctl start autofs
systemctl enable autofs
man passwd :进入第五章节 mna -a passwd q ctrl +d
[root@centos7 zh_CN]#pwd
/usr/share/man/zh_CNgit
[root@centos7 zh_CN]#man -aw lsvim
/usr/share/man/man1/ls.1.gz
/usr/share/man/zh_CN/man1/ls.1.gz
/usr/share/man/man1p/ls.1p.gzcentos
[root@centos7 zh_CN]#bash
centos 7: /etc/man_db.confapp
man变量配置文件:MANDATORY_MANPATH /usr/share/man/zh_CN ssh
*****—-------> echo$PAT H: 环境变量
export '$PATH:/app'
. /etc/profile ide
centos 6: /etc/man.conf
-普通文件
d目录文件
[root@centos7 ~]#ll -ld /etc/
drwxr-xr-x. 139 root root 8192 May 19 08:57 /etc/
b块设备文件
c字符设备文件
[root@centos7 ~]#ll /dev/tty
crw-rw-rw-. 1 root tty 5, 0 May 19 08:47 /dev/tty
[root@centos7 ~]#ll /dev/pts/0
crw--w----. 1 sun tty 136, 0 May 19 08:50 /dev/pts/0
l软连接文件
[root@centos7 ~]#ll /usr/sbin/clock
lrwxrwxrwx. 1 root root 7 May 16 13:10 /usr/sbin/clock -> hwclock
p管道文件
s套接字文件
[root@centos7 ~]#ll /run/*.sock
srw-rw-rw-. 1 root root 0 May 19 08:47 /run/gssproxy.sock
srw-rw-rw-. 1 root root 0 May 19 08:47 /run/rpcbind.sock
建立nc -Ul mage.sock 通讯
加入nc -U mage.sock
ctrl +d 退出
pwd -p :若是是软链接将显示原始目录
[root@centos7 etc]#cd /etc/init.d
[root@centos7 init.d]#pwd -P
/etc/rc.d/init.d
[root@centos7 init.d]#ll /etc/init.d
lrwxrwxrwx. 1 root root 11 May 16 13:09 /etc/init.d -> rc.d/init.d
相对路径子目录:
[root@centos7 ~]#cd /etc/sysconfig
[root@centos7 sysconfig]#cd /etc/sysconfig/network-scripts/^C
[root@centos7 sysconfig]#cd network-scripts/
[root@centos7 network-scripts]#
路径的切换:上级目录
[root@centos7 sysconfig]#cd /etc/sysconfig/network-scripts/mage/
[root@centos7 mage]#pwd
/etc/sysconfig/network-scripts/mage
[root@centos7 mage]#cd ../../
**——————>bash /app/txt.sh
****》root/ txt.sh 执行命令
[root@centos7 back]#dirname /app/back
/app
[root@centos7 back]#basename /app/back
back
文件名通配符
*:匹配零或多个任意字符
?:匹配任意一个单一字符
0-9:表示任何数字
a-Z:表示全部字母,包括大小写
[^linux]:表示不包含l和i和n和u和x [:digit:]:表示任意数字 [:lower:]:表示小写字母 [:upper:]:表示大写字母 [:alpha:]:表示大小写字母 [:alnum:]:表示任意字母或数字 [:blank:]:表示空格(水平制表符)及TAB [:space:]:表示空格(水平制表符)、回车(垂直制表符)及TAB [:punct:]:表示符号 [:print:]:表示可打印字符
-rw-------. 1 root root 1489 May 15 13:25 anaconda-ks.cfg
-/d/l/s/b/c/p 表示文件的类型 rw- --- --- 表示owner,group,other的权限 . 表示该文件有selinux的context标签,可用-Z 详细查看 1 表示硬连接数 root 表示该文件的owner root 表示该文件的group 1495 表示该文件的大小,默认bytes -h以人类可读性显示,则显示具体的单位 May 15 11:23 默认显示为mtime,可以使用u或--time=atime来显示atime s 可以使用--time=ctime来显示ctime anaconda-ks.cfg 文件名
做业:
一、[root@centos7 app]#ls /app/k[:digit:][:lower:]
[root@centos7 app]#ls /app/[0-9][0-9][0-9]
二、[root@centos7 app]#ls -d /proc/[0-9][0-9][0-9]
三、[root@centos7 app]#ls /app/[[:punct:][:digit:]]
/app/8973 /app/987 /app/a+3 /app/a &71qa1 /app/k21a
[root@centos7 app]#ls /app/[[:punct:][0-9]
/app/8973 /app/987 /app/a+3 /app/a &71qa1 /app/k21a
四、[root@centos7 app]#ls m[[:digit:]]x
m2x
五、[root@centos7 app]#ls [A-Z][0-9][0-9]
ls [A-Z][[:digit:]][[:digit:]]
A23
六、[root@centos7 app]#ls [[:lower:]][0-9].conf
qa13.conf
[root@centos7 app]#ls [[:lower:]][[:digit:]].conf
qa13.conf
七、[root@centos7 ~]#ls [^.]
a anaconda-ks.cfg initial-setup-ks.cfg txt.sh
八、alias baketc='cp -av /etc/ /app/backupdate +%F
'
九、[root@centos /app]#cp -av /root/* /app/testdir/rootdir
十、[root@centos /app]#mkdir -pv /testdir/dir8/{x/{a,b,c},y/{a,b,c}}
[root@centos /app]#mkdir -pv /app/testdir{11,12/dir14,13/dir15} 目录
十一、[root@centos /app]#mkdir -pv /app/testdir/dir/{9/x/a,10/y/b}
mkdir: created directory /app/testdir/dir'<br/>mkdir: created directory
/app/testdir/dir/9'
mkdir: created directory /app/testdir/dir/9/x'<br/>mkdir: created directory
/app/testdir/dir/9/x/a'
mkdir: created directory /app/testdir/dir/10'<br/>mkdir: created directory
/app/testdir/dir/10/y'
mkdir: created directory `/app/testdir/dir/10/y/b'
十二、[root@centos /app]#mkdir -pv /app/testdir/dir/{11,12/dir14,13/dir15}
练习:
一、显示/var目录下全部以l开头,以一个小写字母结尾,且中间出现至少一位数字的文件或目录
ls /var/l[0-9][[:lower:]]d
二、显示/etc目录下以任意一位数字开头,且以非数字结尾的文件或目录
ls /etc/[0-9][^0-9]
三、显示/etc/目录下以非字母开头,后面跟了一个字母及其它任意长度任意字符的文件或目录
ls /etc/[^a-Z][a-Z]
四、显示/etc/目录下全部以rc开头,并后面是0-6之间的数字,其它为任意字符的文件或目录
ls -d /etc/rc[0-6]
五、显示/etc目录下,全部以.d结尾的文件或目录
ls -d /etc/.d
六、显示/etc目录下,全部.conf结尾,且以m,n,r,p开头的文件或目录
ls -d /etc/[mnrp].conf
七、只显示/root下的隐藏文件和目录
ls -d .
八、只显示/etc下的非隐藏目录
ls -d /etc/*/
cp -av /etc/ /app/testdir/backup`date +%F`
实验:
文件更名及备份
root@centos7 app]#ls
f10.conf.bak f2.conf.bak f4.conf.bak f6.conf.bak f8.conf.bak
f1.conf.bak f3.conf.bak f5.conf.bak f7.conf.bak f9.conf.bak
[root@centos7 app]#rename conf.bak conf *.bak
[root@centos7 app]#ls
f10.conf f2.conf f4.conf f6.conf f8.conf
f1.conf f3.conf f5.conf f7.conf f9.conf
[root@centos7 app]#touch f{1..10}.conf
[root@centos7 app]#ls
1 f10.conf f2.conf f4.conf f6.conf f8.conf
backup2018-05-19 f1.conf f3.conf f5.conf f7.conf f9.conf
[root@centos7 app]#rename conf conf.bak f* 批量备份文件
2
ls -Z selinux
[root@centos ~]#getenforce ^C
[root@centos ~]#vim /etc/selinux/config^C
[root@centos ~]#
3
[root@centos ~]#stty -echoctl ————>bashrc 去掉ctrl +c 字符
4
[root@centos ~]#stat anaconda-ks.cfg
File: `anaconda-ks.cfg'
Size: 1489 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 1051842 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-05-19 15:56:07.426235498 +0800 读
Modify: 2018-05-15 13:25:14.120999614 +0800 修改
Change: 2018-05-15 13:25:20.471999612 +0800 元数据时间
4 touch a
stat 刷新时间 ctime touch -a 刷新 a,c 时间
a time touch -c 刷新 a,m 时间
mtime
ASCII>> utf -8 127位
中国GB2312
16位
2^16=65536
man 7 ascii 查看 ASCII 表
6
bc 计算使用
obase=2;ibase=10
9
1001
7
[root@centos ~]#echo -e "a\n" 换行
a
[root@centos ~]#echo -e "\007"
7 、? 表示2个字符以上
八、提示符怎么修改原始~/.bashrc
九、[1-36-9] :表示一位数字
十、[root@centos ~]#ls [[:blank:]]
a b
[root@centos ~]#ls [[:space:]]*
a b
十一、
[root@centos ~]#echo -e "aaad d" |tr -d [[:blank:]]
aaadd
[root@centos ~]#echo -e "aaad d\n" |tr -d [[:blank:]]
aaadd
[root@centos ~]#echo -e "aaad d\n" |tr -d [[:space:]]
aaadd[root@centos ~]#
[root@centos ~]#ls [[:punct:]] 表示包含符号
CP 命令
软链接
[root@centos /app]#mkdir dir2
[root@centos /app]#cp /etc/passwd .
[root@centos /app]#ls
dir2 passwd
[root@centos /app]#ln -s passwd mima
[root@centos /app]#ll
total 8
drwxr-xr-x. 2 root root 4096 May 19 22:21 dir2
lrwxrwxrwx. 1 root root 6 May 19 22:22 mima -> passwd
-rw-r--r--. 1 root root 1609 May 19 22:21 passwd
[root@centos /app]#cp -d mima dir2/
[root@centos /app]#cd dir2
[root@centos /app/dir2]#ls
mima
[root@centos /app/dir2]#ll
total 0
lrwxrwxrwx. 1 root root 6 May 19 22:23 mima -> passwd 闪烁
[root@centos /app/dir2]#touch passwd
[root@centos /app/dir2]#ll
total 0
lrwxrwxrwx. 1 root root 6 May 19 22:23 mima -> passwd 找到路径
-rw-r--r--. 1 root root 0 May 19 22:23 passwd
[root@centos /app/dir2]#
[root@centos /app]#cp -av * /newappdir2' ->
/newapp/dir2'dir2/mima' ->
/newapp/dir2/mima'dir2/passwd' ->
/newapp/dir2/passwd'mima' ->
/newapp/mima'passwd' ->
/newapp/passwd'
[root@centos /etc]#du -sh 字节 h
41M
生成一个 bigfile 清空文件
[root@centos /app/source]#dd if=/dev/zero of=bigfile bs=1M count=20
[root@centos /app/source]#du -sh
21M
mkdir source target
cp -a source/ target/
[root@centos /app/source]#du -sh
[root@centos /app/target]# > /app/target/bigfile 清空
[root@centos /app/target]#rm -rf 删除
cp -f
[sun@centos7 app]$chmod 000 1111
[sun@centos7 app]$ll
total 8
----------. 1 sun sun 2234 May 16 14:23 1111
-rw-r--r--. 1 sun sun 2234 May 16 14:13 passwd
[sun@centos7 app]$cat 1111
cat: 1111: Permission denied
[sun@centos7 app]$ll -dl /app
drwxrwxrwx. 2 root root 32 May 16 14:23 /app
[sun@centos7 app]$cp -f /etc/passwd 1111
[sun@centos7 app]$cat 1111
[sun@centos7 app]$ll 1111
-rw-r--r--. 1 sun sun 2234 May 16 14:24 1111
[sun@centos7 app]$ll /etc/passwd
-rw-r--r--. 1 root root 2234 May 16 13:22 /etc/passwd
[sun@centos7 app]$
mv 移动并更名
[root@centos7 app]#ls
1111 a backup2018-05-16 dir2
[root@centos7 app]#mv a dir2/
[root@centos7 app]#ll
total 4
-rw-r--r--. 1 sun sun 2234 May 16 14:24 1111
drwx------. 2 root root 6 May 16 14:34 backup2018-05-16
drwxr-xr-x. 2 root root 15 May 16 14:40 dir2
[root@centos7 app]#mv dir2/a ./passwd
[root@centos7 app]#ls
1111 backup2018-05-16 dir2 passwd
[root@centos7 app]#
删除根下面全部的目录:
[root@centos ~]#cd /
[root@centos /]# rm-rf *^C
[root@centos /]#cd
[root@centos ~]#rm -rf /
快照:关机快照 内存占用空间
硬连接 inode 编号 indoe bitmap block bitmap
[root@centos /app]#ls -i source/fstab
131074 source/fstab
[root@centos /app]#ls -i target/1fstab
131074 target/1fstab
[root@centos /app]#
[root@centos /app]#ln passwd haha 最后一个分区
[root@centos /app]#ls -i
11 haha 11 passwd 131073 source 393217 target
ln /etc/passwd /bin/haha
df /etc /dev/sd2
df /bin
软连接 :是路径 指针
[root@centos /app]#mkdir source target
[root@centos /app]#ls
source target
[root@centos /app]#cp /etc/passwd source/
[root@centos /app]#cd target/
[root@centos /app/target]#ln -s ../source/passwd mima
[root@centos /app/target]#ll mima
lrwxrwxrwx. 1 root root 16 May 16 14:29 mima -> ../source/passwd
[root@centos /app/target]#
[root@centos ~]#ll -ld /etc/init.d
lrwxrwxrwx. 1 root root 11 May 15 13:14 /etc/init.d -> rc.d/init.d
[root@centos ~]#ll -ld /var/mail
lrwxrwxrwx. 1 root root 10 May 15 13:14 /var/mail -> spool/mail
软链接
[root@centos /app]#ll /tmp/a/b/c/d/exe
lrwxrwxrwx. 1 root root 30 May 16 15:23 /tmp/a/b/c/d/exe -> ../../../../../app/1/2/3/4/txt
怎么查看软连接真实 路径
[root@centos /var/www]#mkdir /var/www/magetest
[root@centos /var/www]#cd /var/www/magetest
[root@centos /var/www/magetest]#vim hello.html
[root@centos /var/www/magetest]#ln -s /var/www/magetest/hello.html /var/www/magetest/index.html
[root@centos /var/www/mage]#rm -rf index.html
[root@centos /var/www/mage]#ln -s hello.html index.html
[root@centos /var/www/mage]#ll
total 4
-rw-r--r--. 1 root root 9 May 16 15:27 hello.html
lrwxrwxrwx. 1 root root 10 May 16 15:43 index.html -> hello.html
file- f 产看文件列表
[root@centos /app]#vim liebiao.txt
/etc/grub/
/etc/passwd
/app/txt
[root@centos /app]#file -f liebiao.txt
/etc/grub/: cannot open `/etc/grub/' (No such file or directory)
/etc/passwd: ASCII text
/app/txt: ASCII text
查看软链接类型:
[root@centos /app]#file -L /etc/system-release/etc/system-release: ASCII text