首页 > 代码库 > 5-Linux基础-3

5-Linux基础-3

Linux 基础-3

上节课复习

useradd username -u uid -g gid -c comment -d homedir -s shell
usermod username -u uid -g gid -c comment -d home
dir -s shell
usermod :

-a 追加
-g<群组>:修改用户所属的群组;
-G<群组>;修改用户所属的附加群组

文件属性

- 普通文件
d 目录文件
l 连接文件
b 块设备
p 管道文件
s socket文件

对目录的权限:

r:可以查看目录下内容
w:可以创建文件和删除文件和修改文件名
x:可cd进文件夹

正文处理命令及tar命令

文件合并:

cat a1.txt a2.txt>>a.txt
touch {a..c}{1..3}.txt

tar

-A或--catenate:新增文件到以存在的备份文件;  
-B:设置区块大小;   
-c或--create:建立新的备份文件;  
-C <目录>:这个选项用在解压缩,若要在特定目录解压缩,可以使用这个选项。  
-d:记录文件的差别;  
-x或--extract或--get:从备份文件中还原文件;  
-t或--list:列出备份文件的内容;  
-z或--gzip或--ungzip:通过gzip指令处理备份文件;   
-Z或--compress或--uncompress:通过compress指令处理备份文件;   
-f<备份文件>或--file=<备份文件>:指定备份文件;  
-v或--verbose:显示指令执行过程;  
-r:添加文件到已经压缩的文件;  
-u:添加改变了和现有的文件到已经存在的压缩文件;  
-j:支持bzip2解压文件;   
-v:显示操作过程;  
-l:文件系统边界设置;  
-k:保留原有文件不覆盖;  
-m:保留文件不被覆盖;  
-w:确认压缩文件的正确性;  
-p或--same-permissions:用原来的文件权限还原文件;  
-P或--absolute-names:文件名使用绝对名称,不移除文件名称前的“/”号;   
-N <日期格式> 或 --newer=<日期时间>:只将较指定日期更新的文件保存到备份文件里;   
--exclude=<范本样式>:排除符合范本样式的文件。

-c -v -tf -x -f -C 

tar vcf all.tar *       //归档不压缩,z是压缩,xz文件压缩率更高
gzip all.tar     //生成 all.tar.gz
gunzip all.tar.gz       //解压缩

先归档再压缩:tar vxzf all.tar.gz * 
解压缩 tar vxf all.tar.gz  //不需要z,万能格式解压缩

bzip2
bzip2 test.tar  //生成 test.tar.bz2
bunzip2 test.tar.bz2   //解压缩

vi

命令行模式: :
编辑模式:  a i o 
扩展模式: shift+:

命令行模式:

G/shift+g :跳到文件末尾
gg: 跳到文件开头
$:行尾
^:行首
0:行首
yy:复制当前行
p:粘贴
nyy:复制当前行下的n行到寄存器
yy:复制当前行 10p:粘贴当前行下的10行
dd:删除当前行,其实是剪切到寄存器
u:撤销
ctrl+r:恢复
num+G:跳到第n行
L:当前屏幕最后一列
/ :查找 n往下跳

扩展模式:

:wq
:q
:wq!
:q!
:sed -i 
:s/需要修改还的内容/替换的内容/   修改当前行当前行
:%s/需要修改还的内容/替换的内容/   修改全文,每行只修改第一个
:%s/需要修改还的内容/替换的内容/g   修改全文(%)所有内容(g)

系统的初始化和服务

单用户模式:root身份 开机按 e,linux16 后面加上init /bin/sh +ctrl+s    翻车了
http://blog.csdn.net/myth_hg/article/details/44727647

mount -o remount,rw /

单用户模式破解root密码:

1)在启动grub菜单,选择编辑选项启动,(开机按 e)
2)找到Linux 16的那一行,将ro改为rw init=/sysroot/bin/sh
3) 现在按下Control+x,使用单用户模式启动
5)现在,可以使用下面的命令访问系统
chroot /sysroot
6)重置密码
passwd root
7)更新系统信息
touch /.autorelabel
8)退出chroot
exit
9)重启系统 

救援模式破解root密码

救援模式破解root密码

 

<style>html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video { margin: 0; padding: 0; border: 0 } body { font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 14px; line-height: 1.6; color: #333; background-color: #fff; padding: 20px; max-width: 960px; margin: 0 auto } body>*:first-child { margin-top: 0 !important } body>*:last-child { margin-bottom: 0 !important } p,blockquote,ul,ol,dl,table,pre { margin: 15px 0 } h1,h2,h3,h4,h5,h6 { margin: 20px 0 10px; padding: 0; font-weight: bold } h1 tt,h1 code,h2 tt,h2 code,h3 tt,h3 code,h4 tt,h4 code,h5 tt,h5 code,h6 tt,h6 code { font-size: inherit } h1 { font-size: 28px; color: #000 } h2 { font-size: 24px; border-bottom: 1px solid #ccc; color: #000 } h3 { font-size: 18px } h4 { font-size: 16px } h5 { font-size: 14px } h6 { color: #777; font-size: 14px } body>h2:first-child,body>h1:first-child,body>h1:first-child+h2,body>h3:first-child,body>h4:first-child,body>h5:first-child,body>h6:first-child { margin-top: 0; padding-top: 0 } a:first-child h1,a:first-child h2,a:first-child h3,a:first-child h4,a:first-child h5,a:first-child h6 { margin-top: 0; padding-top: 0 } h1+p,h2+p,h3+p,h4+p,h5+p,h6+p { margin-top: 10px } a { color: #4183C4; text-decoration: none } a:hover { text-decoration: underline } ul,ol { padding-left: 30px } ul li>:first-child,ol li>:first-child,ul li ul:first-of-type,ol li ol:first-of-type,ul li ol:first-of-type,ol li ul:first-of-type { margin-top: 0px } ul ul,ul ol,ol ol,ol ul { margin-bottom: 0 } dl { padding: 0 } dl dt { font-size: 14px; font-weight: bold; font-style: italic; padding: 0; margin: 15px 0 5px } dl dt:first-child { padding: 0 } dl dt>:first-child { margin-top: 0px } dl dt>:last-child { margin-bottom: 0px } dl dd { margin: 0 0 15px; padding: 0 15px } dl dd>:first-child { margin-top: 0px } dl dd>:last-child { margin-bottom: 0px } pre,code,tt { font-size: 12px; font-family: Consolas, "Liberation Mono", Courier, monospace } code,tt { margin: 0 0px; padding: 0px 0px; white-space: nowrap; border: 1px solid #eaeaea; background-color: #f8f8f8 } pre>code { margin: 0; padding: 0; white-space: pre; border: none; background: transparent } pre { background-color: #f8f8f8; border: 1px solid #ccc; font-size: 13px; line-height: 19px; overflow: auto; padding: 6px 10px } pre code,pre tt { background-color: transparent; border: none } kbd { background-color: #DDDDDD; background-image: linear-gradient(#F1F1F1, #DDDDDD); background-repeat: repeat-x; border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD; border-style: solid; border-width: 1px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; line-height: 10px; padding: 1px 4px } blockquote { border-left: 4px solid #DDD; padding: 0 15px; color: #777 } blockquote>:first-child { margin-top: 0px } blockquote>:last-child { margin-bottom: 0px } hr { clear: both; margin: 15px 0; height: 0px; overflow: hidden; border: none; background: transparent; border-bottom: 4px solid #ddd; padding: 0 } table th { font-weight: bold } table th,table td { border: 1px solid #ccc; padding: 6px 13px } table tr { border-top: 1px solid #ccc; background-color: #fff } table tr:nth-child(2n) { background-color: #f8f8f8 } img { max-width: 100% }</style>

5-Linux基础-3