目录
1:创建环境变量root_data, 只有root用户可以访问到
2:创建环境变量normal_user_data, 只有普通用户可以访问到
二:创建3个文件test1.txt, test2.txt, test3.txt
1:使用find查找test1.txt,test2.txt, test3.txt
六:引号的使用举例: 无引号,单引号,双引号,反引号,$()
2:linux中存储用户信息的文件是哪个?且其中的字段是什么意思
3:linux中存储组信息的文件是哪个?且其中的字段是什么意思?
一:创建普通变量local_data=1并访问
[root@rhcsa ~]# data=1
[root@rhcsa ~]# echo $data
1
1:创建环境变量root_data, 只有root用户可以访问到
[root@rhcsa ~]# vim .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
# 定义一个只有root用户能访问的变量
data=root
export data
......
# 一定要输入下面的命令
[root@rhcsa ~]# source .bash_profile
2:创建环境变量normal_user_data, 只有普通用户可以访问到
#切换到普通用户的家目录中定义
[root@rhcsa ~]# cd /home/slw/
[root@rhcsa slw]# vim .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
~
data=slw
explore data
~
[root@rhcsa slw]# source .bash_profile
3:创建环境变量root用户和普通用户都可以访问到
[root@rhcsa ~]# vim /etc/profile
# 在此处定义变量可所有用户访问
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
......
if [ -f /etc/bashrc ] ; then
-- INSERT --
二:创建3个文件test1.txt, test2.txt, test3.txt
[root@rhcsa ~]# touch test{1..3}.txt
[root@rhcsa ~]# ll
total 84
-rw-r--r--. 1 root root 0 Nov 21 15:28 test1.txt
-rw-r--r--. 1 root root 0 Nov 21 15:28 test2.txt
-rw-r--r--. 1 root root 0 Nov 21 15:28 test3.txt
1:使用find查找test1.txt,test2.txt, test3.txt
[root@rhcsa ~]# find test?.txt
test1.txt
test2.txt
test3.txt
2:使用别名: 将上边命令命名为myfind
[root@rhcsa ~]# alias myfind="find test?.txt"
[root@rhcsa ~]# myfind
test1.txt
test2.txt
test3.txt
3:取消别名
[root@rhcsa ~]# unalias myfind
[root@rhcsa ~]# myfind
bash: myfind: command not found...
三:查看最近使用的10条历史命令
-c 清空内存中命令历史
-d # 删除指定的历史命令,比如 history -d 100 ,就是删除第100个命令历史
# : 显示最近的#条历史,例如:history 20 ,表示显示最近的20条命令历史
-a: 追加本次会话新执行的命令历史列表至历史文件
-n: 将历史文件中未读过的行加载到内存中的历史列表,方便多个终端同步内存中的命令历史。
-r: 读取历史文件中的所有历史命令到内存中的历史列表,即使内存中的列表中已经存在这条历史。
-w: 保存内存中历史列表到指定的历史文件,history -w ./test 把历史写入到当前目录的test文件中
-p: 官方解释没看懂,我觉得此命令相当于echo的作用,但是使用history -p string输出的信息不被记录到历史中,
就是“不被记录的echo,隐形echo,你可以尝试使用history -p $变量名,这样会不会觉得很像echo?
但是如果你使用history -p string1 string2,会发现它并不像echo打印到一行,会打印成多行。
-s: 伪造命令历史,比如history -s rm -rf /opt,这样写并不会执行删除opt目录的操作,只是把这条没有执行的"命令"加入到了历史中
[root@rhcsa ~]# history 10
四:在一行上打印123和以及从root切换到普通用户
五:通配符使用
创建3个文件 file1, file2, file3
[root@rhcsa ~]# touch file{1..3}
[root@rhcsa ~]# ll
total 84
-rw-r--r--. 1 root root 0 Nov 21 15:37 file1
-rw-r--r--. 1 root root 0 Nov 21 15:37 file2
-rw-r--r--. 1 root root 0 Nov 21 15:37 file3
1.* 去匹配3个文件
匹配多个字符
[root@rhcsa ~]# ll file*
-rw-r--r--. 1 root root 0 Nov 21 15:37 file1
-rw-r--r--. 1 root root 126 Nov 20 21:17 file1.txt
-rw-r--r--. 1 root root 0 Nov 21 15:37 file2
-rw-r--r--. 1 root root 0 Nov 20 21:02 file2.txt
-rw-r--r--. 1 root root 0 Nov 21 15:37 file3
-rw-r--r--. 1 root root 0 Nov 20 21:02 file3.txt
-rw-r--r--. 1 root root 0 Nov 20 21:21 file4.txt
2.? 匹配3个文件
只匹配一个字符
[root@rhcsa ~]# ll file?
-rw-r--r--. 1 root root 0 Nov 21 15:37 file1
-rw-r--r--. 1 root root 0 Nov 21 15:37 file2
-rw-r--r--. 1 root root 0 Nov 21 15:37 file3
3.[]匹配file1和file3
[root@rhcsa ~]# ll file[1,3]
-rw-r--r--. 1 root root 0 Nov 21 15:37 file1
-rw-r--r--. 1 root root 0 Nov 21 15:37 file3
4.[^]匹配file2
[root@rhcsa ~]# ll file[^1..3]
-rw-r--r--. 1 root root 0 Nov 21 15:37 file2
5.[!]匹配file2
[root@rhcsa ~]# ll file[!1..3]
-rw-r--r--. 1 root root 0 Nov 21 15:37 file2
6.{}匹配file1和file3
[root@rhcsa ~]# ll file{1,3}
-rw-r--r--. 1 root root 0 Nov 21 15:37 file1
-rw-r--r--. 1 root root 0 Nov 21 15:37 file3
六:引号的使用举例: 无引号,单引号,双引号,反引号,$()
[root@rhcsa ~]# echo data
data
[root@rhcsa ~]# echo $data
[root@rhcsa ~]# data2="data"
[root@rhcsa ~]# echo $data2
data
[root@rhcsa ~]# data2="$data"
[root@rhcsa ~]# echo $data2
[root@rhcsa ~]# data2='$data'
[root@rhcsa ~]# echo $data2
$data
七:linux中用户的类型
1:linux中用户组的类型
超级用户(root,UID=0)
就是说UID为0的用户都是超级用户,只要把/etc/passwd相应的用户的UID改为0,该用户就变成超级用户了
普通用户 (uid 500-60000)
也就是我们平时所使用的用户
伪(系统)用户(UID 1-499)
伪用户与系统和程序服务相关,因为并不是真实的使用者,所以叫伪用户,如bin、daemon、shutdown、halt等,任何Linux系统都默认有这些伪用户;mail、ftp、sshd等,与Linux系统的进程相关;
————————————————
版权声明:本文为CSDN博主「我要你的自然74」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_40691208/article/details/80866332
2:linux中存储用户信息的文件是哪个?且其中的字段是什么意思
/etc/passwd
用户名:口令:用户标识号:组标识号:注释性描述:主目录:登录Shell
对每个字段的解读如下:.用户名
代表用户账号字段,一般为不超过8个字符的字符串,由大小写字母以及数组组成,不能含有冒号,最好不要含有点字符(.),不要以加号(+)或(-)开头。口令
虽然口令都是加密的,但是由于/etc/passwd这个文件对所有人可见,为了安全起见,很多Linux发现版都采用了shadow技术,即将真正的口令存放在shadow文件中,这里的口令一般用“x”或“*”进行代替。用户标识号
一般情况下,用户的标识号是与用户名一一对应的,若是几个用户都是一样的用户标识号,那么在系统看来是同一个用户,但它们可以拥有不同的口令、主目录以及登录shell。组标识号
记录着用户所属的主用户组的id,对应着/etc/group中的一条记录。注释性描述
记录着一些用户的个人描述,如姓名、电话等等。这个字段并没有什么实际的用途。在不同的Linux 系统中,这个字段的格式并没有统一。在许多Linux系统中,这个字段存放的是一段任意的注释性描述文字,用做finger命令的输出。主目录
用户登录到系统之后所处的目录,用户的主目录名称就是该用户的登录名,自己对主目录有完整的读、写、操作权限,其他用户视情况设置权限。登录shell
用户登录到系统后,会启动一个进程负责将用户的操作传递到系统内核,这个进程就是系统登录后的命令解释器或程序,我们称之为shell,主要起到人机之间的联通作用。
Shell是用户与Linux之间的一个接口(详见我的另一篇shell博文),Linux中的shell有很多种如,sh(Bounce Shell)、csh(C Shell)、ksh(Korn Shell)、bash(Bounce Again Shell)等等。
————————————————
版权声明:本文为CSDN博主「传奇冰行」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lbb88888888/article/details/102764199
3:linux中存储组信息的文件是哪个?且其中的字段是什么意思?
/etc/group
组名:口令:组标识号:组内用户列表
"组名"是用户组的名称,由字母或数字构成。与/etc/passwd中的登录名一样,组名不应重复。
"口令"字段存放的是用户组加密后的口令字。一般Linux 系统的用户组都没有口令,即这个字段一般为空,或者是*。
"组标识号"与用户标识号类似,也是一个整数,被系统内部用来标识组。
"组内用户列表"是属于这个组的所有用户的列表/b],不同用户之间用逗号(,)分隔。这个用户组可能是用户的主组,也可能是附加组
————————————————
版权声明:本文为CSDN博主「传奇冰行」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lbb88888888/article/details/102764199