第三关练习-权限
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第三关练习-权限相关的知识,希望对你有一定的参考价值。
1.1 取出网卡配置文件的ip
[[email protected] ~]# awk '/IPADDR/' /etc/sysconfig/network-scripts/ifcfg-eth0
IPADDR=10.0.0.200
[[email protected] ~]# awk -F= '/IPADDR/{print $2}' /etc/sysconfig/network-scripts/ifcfg-eth0
10.0.0.200
1.2 取出网卡中的DNS
[[email protected] ~]# awk -F"[=]" '/DNS[0-9]+/{print $2}' /etc/sysconfig/network-scripts/ifcfg-eth0
223.6.6.6
223.5.5.5
1.3 显示年-月-日_周几
date +%F_%w
[[email protected] ~]# date +%F_%w
2018-08-06_1
[[email protected] ~]# date -d '-1year'
Sun Jul 23 16:44:04 CST 2017
[[email protected] ~]# date -d '-1day'
Sun Jul 22 16:44:12 CST 2018
1.4 设置时间
[[email protected] ~]# date -s "20180521 12:12:12"
Mon May 21 12:12:12 CST 2018
[[email protected] ~]# date
Mon May 21 12:13:23 CST 2018
1.5 自动校对时间
[[email protected] ~]# ntpdate ntp1.aliyun.com
6 Aug 09:01:17 ntpdate[1849]: step time server 120.25.115.20 offset 6641251.972418 sec
1.6 打包压缩 /etc/目录 压缩到/tmp,每天创建的压缩包名字要不同
[[email protected] ~]# #tar zcf /tmp/etc.tar.gz /etc/
[[email protected] ~]# #tar zcf /tmp/etc-2018-06-06.tar.gz /etc/
[[email protected] ~]# date +%F
2018-08-06
[[email protected] ~]# tar zcf /tmp/etc-$(date +%F).tar.gz /etc/
tar: Removing leading `/' from member names
[[email protected] ~]# ll /tmp/etc-2018-08-06.tar.gz
-rw-r--r-- 1 root root 9734087 Aug 6 09:19 /tmp/etc-2018-08-06.tar.gz
[[email protected] ~]# tar tf /tmp/etc-2018-08-06.tar.gz
1.7 查找当前目录下所有文件,并把文件中的www.etiantian.org字符串替换成www.oldboyedu.com。
方法1
find /oldboy -type f |xargs sed 's#www.etiantian.org#www.oldboyedu.com#g'
方法2
sed 's#www.etiantian.org#www.oldboyedu.com#g' `find /oldboy -type f `
sed 's#www.etiantian.org#www.oldboyedu.com#g' $(find /oldboy -type f )
方法3
find /oldboy -type f -exec sed 's#www.etiantian.org#www.oldboyedu.com#g' {} ;
1.8 请问在一个命令上加什么参数可以实现下面命令的内容在同一行输出。
echo "oldboy";echo "oldboy"
[[email protected] ~]# echo 'oldboy'
oldboy
[[email protected] ~]# echo -n 'oldboy'
oldboy[[email protected] ~]#
[[email protected] ~]# echo 'oldboy old lidao'
oldboy old lidao
[[email protected] ~]# echo oldboy old lidao"
[[email protected] ~]# echo "oldboy old lidao"
oldboy old lidao
[[email protected] ~]# echo -e "oldboy old lidao"
oldboy
old
lidao
[[email protected] ~]# echo -e "oldboy old lidao"
oldboy
old
lidao
-n不显示每行结尾的回车
-e 让echo命令支持 转义字符
1.9 当从root用户切到普通用户oldboy时,执行ifconfig会提示。command not found
模拟环境
export PATH=
PATH 路径 环境变量 存放的是 命令路径
如何修改PATH
1.临时
[[email protected] ~]# export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:~/bin
[[email protected] ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
2.永久
[[email protected] ~]# tail -1 /etc/profile
#export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:~/bin
[[email protected] ~]# source /etc/profile
3.检查
发出当前系统使用的 PATH
1.10 请描述下列路径的内容是做什么的?
/var/log/messages 系统默认日志
/var/log/secure 用户登录日志
/etc/fstab 开机自动挂载
/etc/hosts 解析主机名(域名)
/etc/rc.local 开机自启动
/etc/profile 别名 环境变量
/var/spool/cron/root 定时任务的配置文件
1.11 修改主机名
1)临时
2)永久
/etc/sysconfig/network
3) 解析
[[email protected] ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.200 oldboyedu50-lnb
[[email protected] ~]# ping `hostname`
PING oldboyedu50-lnb (10.0.0.200) 56(84) bytes of data.
64 bytes from oldboyedu50-lnb (10.0.0.200): icmp_seq=1 ttl=64 time=0.021 ms
64 bytes from oldboyedu50-lnb (10.0.0.200): icmp_seq=2 ttl=64 time=0.021 ms
1.12 如何快速查到ifconfig的全路径,请给出命令。
[[email protected] ~]# find / -type f -name "ifconfig"
/sbin/ifconfig
[[email protected] ~]# which ifconfig
/sbin/ifconfig
[[email protected] ~]# which rm
alias rm='echo rm bny'
/bin/echo
[[email protected] ~]# which rm
/bin/rm
[[email protected] ~]# whereis grep awk
grep: /bin/grep /usr/share/man/man1p/grep.1p.gz /usr/share/man/man1/grep.1.gz
awk: /bin/awk /usr/bin/awk /usr/libexec/awk /usr/share/awk /usr/share/man/man1p/awk.1p.gz /usr/share/man/man1/awk.1.gz
1.13 【用户管理】请给出查看当前哪些用户在线的linux命令。
[[email protected] ~]# w
10:41:59 up 2:07, 2 users, load average: 0.04, 0.02, 0.00
USER TTY FROM [email protected] IDLE JCPU PCPU WHAT
root pts/0 10.0.0.1 23Jul18 0.00s 0.28s 0.00s w
root pts/1 10.0.0.1 09:56 29:20 0.00s 0.00s -bash
[[email protected] ~]# w |awk 'NR==1{print $(NF-6)}'
1.14 请给出正确的关机和重起服务器的命令。
1.重启
reboot
shutdown -r 10
shutdown -r 0/now 立即重启
shutdown -c 取消当前的重启或关机
init 6
2.关机
halt
shutdown -h 10
shutdown -h 0/now 立即关机
poweroff
init 0
1.15 请写出下面linux命令行快捷键的功能?
Ctrl + a 把光标移动到行首
Ctrl + e 把光标移动到行尾
Ctrl + c 取消 cancel
Ctrl + d 退出当前用户
Ctrl + l 清屏
Ctrl + u 把光标所在位置到行首的内容删除(剪切)
Ctrl + k 把光标所在位置到行尾的内容删除(剪切)
ctrl + y 粘贴
ctrl+s 锁屏
ctrl+q/c 解锁
ctrl + r 找出最近一次使用过的 包含xxxx的命令 替你执行
1.16 Linux权限
1.文件或目录rwx含义
2.permission denied 权限拒绝
3.通过控制权限保护网站安全
4.特殊与隐藏权限
1.17 linux如何知道我对某个文件或目录有什么权限?
[[email protected] ~]# su - oldboy
[[email protected] ~]$ ll /etc/hosts
-rw-r--r-- 1 root root 186 Aug 6 10:24 /etc/hosts
1.看看是你谁?
whoami oldboy
2.你与这个文件什么关系 : 主人 家人 陌生人
[[email protected] ~]$ id oldboy
uid=500(oldboy) gid=500(oldboy) groups=500(oldboy)
#oldboy用户 文件是 陌生人关系
3.确认权限 陌生人权限 看最后三位
r 4
w 2
x 1
- 0
[[email protected] ~]# echo {r,-}{w,-}{x,-}
rwx rw- r-x r-- -wx -w- --x ---
权限转换
rw-r--r--
420400400
6 4 4
755 rwxr-xr-x
640 rw-r-----
744 rwxr--r--
600 rw-------
1.18 修改权限 change mode chmod
1.直接通过数字形式修改权限
[[email protected] /oldboy]# chmod 666 test.txt
[[email protected] /oldboy]# ll test.txt
-rw-rw-rw- 1 root root 23 Jul 20 01:13 test.txt
[[email protected] /oldboy]# chmod 777 test.txt
[[email protected] /oldboy]# ll test.txt
-rwxrwxrwx 1 root root 23 Jul 20 01:13 test.txt
2.通过字母 形式修改
rw- rw- rw-
主人 家人 陌生人
所有者 所属用户组 其他人
user group other
u g o
[[email protected] /oldboy]# chmod u=r test.txt
[[email protected] /oldboy]# ll test.txt
-r--rwxrwx 1 root root 23 Jul 20 01:13 test.txt
1.19 给文件快速增加执行权限
[[email protected] /oldboy]# chmod ugo+x test.txt
[[email protected] /oldboy]# ll test.txt
-rwxr-xr-x 1 root root 23 Jul 20 01:13 test.txt
[[email protected] /oldboy]# chmod a-x test.txt
[[email protected] /oldboy]# ll test.txt
-rw-r--r-- 1 root root 23 Jul 20 01:13 test.txt
[[email protected] /oldboy]# chmod +x test.txt
[[email protected] /oldboy]# ll test.txt
-rwxr-xr-x 1 root root 23 Jul 20 01:13 test.txt
chmod ugo+x
chmod a+x
chmod +x
1.20 chown change owner 修改文件的所有者
[[email protected] /oldboy]# chown oldboy.oldboy test.txt
[[email protected] /oldboy]# ll test.txt
-rwxr-xr-x 1 oldboy oldboy 23 Jul 20 01:13 test.txt
[[email protected] /oldboy]#
[[email protected] /oldboy]#
[[email protected] /oldboy]# chown root test.txt
[[email protected] /oldboy]# ll test.txt
-rwxr-xr-x 1 root oldboy 23 Jul 20 01:13 test.txt
[[email protected] /oldboy]# chown .root test.txt
[[email protected] /oldboy]# ll test.txt
-rwxr-xr-x 1 root root 23 Jul 20 01:13 test.txt
以上是关于第三关练习-权限的主要内容,如果未能解决你的问题,请参考以下文章