一.使用tar命令对文件进行打包压缩与解压缩:
1.使用gzip方式对文件进行压缩,并指定压缩名为 tar_gzip.tar.gz
[root@localhost ~]# tar czf tar_gxip.tar.gz data.txt
[root@localhost ~]# ls
模板 下载 anaconda-ks.cfg cut_data,txt file1.txt index.html input.txt result.txt tar_gxip.tar.gz
2.使用bzip2方式对文件夹进行压缩,并指定压缩名为 tar_bzip2.tar.bz2
[root@localhost ~]# tar cjf tar_bzip2.tar.gz2 data.txt
[root@localhost ~]# ls
模板 下载 anaconda-ks.cfg cut_data,txt file1.txt index.html input.txt result.txt tar_bzip2.tar.gz2 video_1755372
视频 音乐 app.txt data.txt file2 index.html.1 num.txt sorted_args.txt tar_gxip.tar.gz
3.使用xz方式对文件进行压缩,并指定压缩名为 tar_xz.tar.xz
[root@localhost ~]# tar cjf tar_xz.tar.xz data.txt
[root@localhost ~]# ls
公共 文档 aaa.txt baidu.html end file3.txt initial-setup-ks.cfg redirect.txt sorted_num.txt test2
模板 下载 anaconda-ks.cfg cut_data,txt file1.txt index.html input.txt result.txt tar_bzip2.tar.gz2 uniq_data.txt
视频 音乐 app.txt data.txt file2 index.html.1 num.txt sorted_args.txt tar_gxip.tar.gz video_1755372
图片 桌面 args.txt dcs file2.txt info_txt pipe_data.txt sorted_merge.txt tar_xz.tar.xz
4.新建文件file1.txt,file2.txt,file3.txt
(1)对文件file1.txt和file2.txt,进行压缩(使用gzip方式),排除file3.txt(即不对file3进行压缩)
并指定压缩名为tar_file.tar.gz
[root@localhost ~]# touch filef{1..3}.txt
[root@localhost ~]# ls
模板 下载 anaconda-ks.cfg cut_data,txt file1.txt filef1.txt index.html.1 num.txt sorted_args.txt tar_gxip.tar.gz video_1755372
视频 音乐 app.txt data.txt file2 filef2.txt info_txt pipe_data.txt sorted_merge.txt tar_xz.tar.xz
图片 桌面 args.txt dcs file2.txt filef3.txt initial-setup-ks.cfg redirect.txt sorted_num.txt test2
[root@localhost ~]# tar czf tar_file.tar.txt file[^3].txt
(2)新建文件file4.txt,将file4.txt添加到tar_file.tar.gz中
[root@localhost ~]# touch file4.txt
[root@localhost ~]# tar czf tar_file.tar.gz file4.txt
(3)查看压缩包tar_file.tar.gz有哪些文件及目录(不解压,只查看)
[root@localhost ~]# tar tf tar_file.tar.gz
file4.txt
(4)解压tar_gzip.tar.gz到指定目录tar_test(没有这个目录就创建)
[root@localhost ~]# mkdir tar_test
[root@localhost ~]# tar xzf tar_gxip.tar.gz -C tar_test
[root@localhost ~]# ls -l tar_test
总用量 0
-rw-r--r--. 1 root root 0 4月 5 19:31 data.txt
(5)解压tar_xz.tar.xz
[root@bogon ~]# tar xjf tar_xz.tar.xz -C tar_test
[root@bogon ~]# ls -l tar_test
总用量 0
-rw-r--r--. 1 root root 0 4月 5 19:31 data.txt
二.在Linux上的/root目录创建一个Linux.txt,在windows上创建windows.txt
1.通过sftp的 get和put命令,将windows上的windows.txt推送到linux上
2.通过sftp的 get和put命令,将linux上的linux.txt推送到windows上
(1) 使用rz上传文件windows.txt到linux上
(2)使用sz下载文件linux.txt到windows上
三.创建普通变量local_data=1并访问
[root@bogon ~]# local_datd=1
[root@bogon ~]# echo $local_datd
1
1. 创建环境变量ROOT_DATA=root, 只有root用户可以访问到
[root@bogon ~]# export ROOT_DATA=root
[root@bogon ~]# echo $ROOT_DATA
root
![](https://img-blog.csdnimg.cn/21012ebc5c6246b1bbb1abb7367aa06e.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAd3p6MjAwMjEwMjc=,size_20,color_FFFFFF,t_70,g_se,x_16)
2.创建环境变量USER_DATA=user, 只有普通用户可以访问到
[xiaowang@bogon ~]$ export USER_DATA=user
[xiaowang@bogon ~]$ echo UDER_DATA
UDER_DATA
3.创建环境变量DATA=all, root用户和普通用户都可以访问到
[root@bogon ~]# vim /etc/bashrc
[root@bogon ~]# soure .bashrc
bash: soure: 未找到命令...
[root@bogon ~]# source .bashrc
[root@bogon ~]# echo $DATA
all
[xiaowang@bogon ~]$ source .bashrc
[xiaowang@bogon ~]$ echo $DATA
all
四.创建3个文件test1.txt, test2.txt, test3.txt
[root@bogon ~]# touch test{1..3}.txt
1.使用find查找test1.txt,test2.txt, test3.txt
[root@bogon ~]# find test{1..3}.txt
test1.txt
test2.txt
test3.txt
2.使用别名: 将上边命令命名为myfind
[root@bogon ~]# alias myfind='find'
[root@bogon ~]# myfind test{1..3}.txt
test1.txt
test2.txt
test3.txt
3.取消别名
[root@bogon ~]# unalias myfind
[root@bogon ~]# myfind
bash: myfind: 未找到命令...
五.查看最近使用的10条历史命令
[root@bogon ~]# history 10
47 soure .bashrc
48 source .bashrc
49 echo $DATA
50 touch test{1..3}.txt
51 find test{1..3}.txt
52 alias myfind='find'
53 myfind test{1..3}.txt
54 unalias myfind
55 myfind
56 history 10
六.在一行上执行两个命令,打印123和从root切换到普通用户
[root@bogon ~]# echo '123'>xiaowang
[root@bogon ~]# echo "123";su xiaowang
123
[xiaowang@bogon root]$
7.通配符使用
创建3个文件 file1, file2, file3
1.* 去匹配3个文件
[root@bogon ~]# ls -l file*
-rw-r--r--. 1 root root 0 4月 5 22:40 file1
-rw-r--r--. 1 root root 0 3月 26 10:56 file2
-rw-r--r--. 1 root root 0 4月 5 22:40 file3
2.? 匹配3个文件
[root@bogon ~]# ls -l file?
-rw-r--r--. 1 root root 0 4月 5 22:40 file1
-rw-r--r--. 1 root root 0 3月 26 10:56 file2
-rw-r--r--. 1 root root 0 4月 5 22:40 file3
3.[]匹配file1和file3
[root@bogon ~]# ls -l file[1,3]
-rw-r--r--. 1 root root 0 4月 5 22:40 file1
-rw-r--r--. 1 root root 0 4月 5 22:40 file3
4.[^]匹配file2
[root@bogon ~]# ls -l file[^1,3]
-rw-r--r--. 1 root root 0 3月 26 10:56 file2
5.[!]匹配file2
[root@bogon ~]# ls -l file[!1,3]
-rw-r--r--. 1 root root 0 3月 26 10:56 file2
6.{}匹配file1和file3
[root@bogon ~]# ls -l file[1,3]
-rw-r--r--. 1 root root 0 4月 5 22:40 file1
-rw-r--r--. 1 root root 0 4月 5 22:40 file3
八.引号的使用举例: 无引号,单引号,双引号,反引号,$()
[root@bogon ~]# echo pwd
pwd
[root@bogon ~]# echo 'pwd'
pwd
[root@bogon ~]# echo "pwd"
pwd
[root@bogon ~]# echo `pwd`
/root
[root@bogon ~]# echo $(pwd)
/root
九.linux中用户的类型
超级用户,系统用户,普通用户
linux中用户组的类型
基本组,附加组
linux中存储用户信息的文件是哪个?且其中的字段是什么意思
/etc/passwd
每行由 7 个字段组成,字段之间用 “:”分隔 格式--账号名称 : 密码 :UID:GID: 个人资料 : 主目录 :Shell
字段说明:
账号名称:用户登录 Linux 系统时使用的名称。
密码:以前是以加密格式保存密码的位置 , 现在密码保存在 /etc/shadow 文件中 , 此处只是密码占位符 “x” 或“*” 。若为 “x” ,说明密码经过了 shadow 的保护
UID :用户的标识,是一个数值,用它来区分不同的用户
GID :用户所在基本组的标识,是一个数值,用它来区分不同的组,相同的组具有相同的 GID 。
个人资料:可以记录用户的完整姓名、地址、办公室电话、家庭电话等个人信息。
主目录:类似 Windows 的个人目录,通常是 /home/username ,这里 username 是用户名,用户执行
“cd ~ ” 命令时当前目录会切换到个人主目录。
Shell :定义用户登录后激活的 Shell ,默认是 Bash Shell
linux中存储组信息的文件是哪个?且其中的字段是什么意思?
/etc/group,例:root:x:0:组成员
root
组的名字
x
组的加密口令
0
是系统区分不同组的 ID ,在 /etc/passwd 域中的 GID 字段是用这个数来指定用户的基本组
组成员
是用 “ , ” 分开的用户名,列出的是附加组的成员。
————————————————
版权声明:本文为CSDN博主「Gur.」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_64051859/article/details/123940660
十.创建下列用户、组和组成员资格:
1.创建名为 sysmgrs 的组
[root@bogon ~]# groupadd -r sysmgrs
2.创建用户 natasha 同时指定sysmgrs作为natasha的附加组
[root@bogon ~]# useradd natasha -G sysmgrs
[root@bogon ~]# tail -1 /etc/passwd
natasha:x:1002:1002::/home/natasha:/bin/bash
3.创建用户 harry 同时指定 sysmgrs作为harry的附加组
[root@bogon ~]# useradd harry -G sysmgrs
[root@bogon ~]# tail -1 /etc/passwd
harry:x:1001:1001::/home/harry:/bin/bash
4.创建用户 sarah 指定shell类型为/sbin/false(无权访问系统上的交互式 shell) 且不是 sysmgrs 的成员
[root@bogon ~]# useradd sarsh -s/sbin/false
[root@bogon ~]# tail -1 /etc/passwd
sarsh:x:1003:1003::/home/sarsh:/sbin/false
5.设置natasha 、 harry 和 sarah 的密码都是 123
[root@bogon ~]# passwd natasha
更改用户 natasha 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@bogon ~]# passwd harry
更改用户 harry 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@bogon ~]# passwd sarsh
更改用户 sarsh 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
6.创建用户lockuser, 并指定家目录为/home/lock, 然后锁定该用户
[root@bogon ~]# useradd lockuser -d /home/lock
[root@bogon ~]# passwd -l lockuser
锁定用户 lockuser 的密码 。
passwd: 操作成功
7.创建用户limituser, gid为1555,userid为1666, 让其密码在10天后过期
[root@bogon ~]# groupadd -g1555 aaa
[root@bogon ~]# useradd limituser -g1555 -u1666 -f10
[root@bogon ~]# tail -1 /etc/group
aaa:x:1555:
[root@bogon ~]# tail -1 /etc/passwd
limituser:x:1666:1555::/home/limituser:/bin/bash
[root@bogon ~]# tail -1 /etc/shadow
limituser:!!:19087:0:99999:7:10::
8.解锁lockuser, 并设定下次登录时必须修改密码
![](https://img-blog.csdnimg.cn/246d2249aae4427aa8bb1139a02142ae.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAR3VyLg==,size_20,color_FFFFFF,t_70,g_se,x_16)
9.让natasha具备修改 harry密码的权限(sudo)
visudo
Host_Alias RHCSA=lwz
User_Alias USER11=natasha
Cmnd_Alias CHPASS=/usr/bin/passwd harry
USER RCHSA=(root) CHPASS
![](https://img-blog.csdnimg.cn/1af090632c1b48ceb764e80be329a351.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAR3VyLg==,size_20,color_FFFFFF,t_70,g_se,x_16)
10.创建用户testuser并设置密码,修改用户名为normaluser
![](https://img-blog.csdnimg.cn/f55e45d431ea433f9c870c582cc1e0dd.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAR3VyLg==,size_20,color_FFFFFF,t_70,g_se,x_16)
11.删除lockuser