linux第二周

总结

tr “a-z” “A-Z”
adfhuheuhaEUHAUHEUAWOE
ADFHUHEUHAEUHAUHEUAWOE
tr “a-z” “A-Z”<anaconda-ks.cfg
tr “a-z” “A-Z”<anaconda-ks.cfg>F1
#VERSION=DEVEL
# SYSTEM AUTHORIZATION INFORMATION
AUTH –ENABLESHADOW –PASSALGO=SHA512
# USE CDROM INSTALLATION MEDIA
CDROM
tr “abcdef” “1234”
abcdefjdi
123444j4i
tr -t “abcdef” “1234”
abcdefg
1234efg
[root@CENTOS7 ~]#tr -d “abc”
aeiskvckkcfb
eiskvkkf
[root@CENTOS7 ~]#tr -d -c “abc” 需要Ctrl+d才能执行命令
123456abcuiewyiuweyrho
abc
tr -s “abc”
aaaabbbbccccabcabcabc
abcabcabcabc
#rz
[root@CENTOS7 ~]#ls
anaconda-ks.cfg  Documents  ff     initial-setup-ks.cfg  Public     新建文本文档.txt
Desktop          f          file1  Music                 Templates
dir2             fc         fo     Pictures              Videos
[root@CENTOS7 ~]#cat 新建文本文档.txt
a
b
c[root@CENTOS7 ~]#touch f1
[root@CENTOS7 ~]#nano f1
[root@CENTOS7 ~]#cat f1
a
b
c
[root@CENTOS7 ~]#sz f1
hexdump -C f1
00000000  61 0a 62 0a 63 0a 0a                              |a.b.c..|
00000007
[root@CENTOS7 ~]#hexdump -C 新建文本文档.txt
00000000  61 0d 0a 62 0d 0a 63                              |a..b..c|
00000007
tr -d “\15” <123.txt >f2    \r=8进制的\15=回车
[root@CENTOS7 ~]#hexdump -C f2
00000000  61 0a 62 0a 63                                    |a.b.c|
00000005
tr “\n” “\t” <f1 >f4
[root@CENTOS7 ~]#cat f4
abc
tr “\n” “\v” <f
1
 2
  3
tr -d “\n” <f
123[root@CENTOS7 ~]#
tr -s ” “<f
1 2 3
df >f
tr -s ” ” “:”<f
Filesystem:1K-blocks:Used:Available:Use%:Mounted:on
/dev/sda2:52403200:3282184:49121016:7%:/
devtmpfs:535296:0:535296:0%:/dev
tmpfs:550036:0:550036:0%:/dev/shm
tmpfs:550036:7896:542140:2%:/run
tmpfs:550036:0:550036:0%:/sys/fs/cgroup
/dev/sda3:31441920:33056:31408864:1%:/data
/dev/sda1:1038336:161620:876716:16%:/boot
tmpfs:110008:20:109988:1%:/run/user/0
/dev/sr0:8490330:8490330:0:100%:/run/media/root/CentOS:7:x86_64
tmpfs:110008:0:110008:0%:/run/user/1000
cat >f
asf
adf
^C
[root@CENTOS7 ~]#cat f
asf
adf
[root@CENTOS7 ~]#cat >f <<123
> asdf
> swerwer
> safdegew
> sadfdasf
> 123
[root@CENTOS7 ~]#cat f
asdf
swerwer
safdegew
sadfdasf
[root@CENTOS7 ~]#tr [:lower:] [:upper:] <<123
> dsfhjdhhjdfsjk
> alfdosiaf
> sdlfisdoif
> wehfoh
> 123
DSFHJDHHJDFSJK
ALFDOSIAF
SDLFISDOIF
WEHFOH
mail -s “hello” wang <<123
> jdfsijdfsh
> woeufhwauhfoaw
> fowehofhoweaefh
> 123
[root@CENTOS7 ~]#su – wang
Last login: Mon Apr  2 20:45:21 CST 2018 on pts/0
[wang@CENTOS7 ~]$mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
“/var/spool/mail/wang”: 2 messages 1 new
    1 root                  Mon Apr  2 20:45  19/647   “hello”
>N  2 root                  Mon Apr  2 20:48  20/627   “hello”
& 2
Message  2:
From root@CENTOS7.localdomain  Mon Apr  2 20:48:12 2018
Return-Path: <root@CENTOS7.localdomain>
X-Original-To: wang
Delivered-To: wang@CENTOS7.localdomain
Date: Mon, 02 Apr 2018 20:48:12 +0800
To: wang@CENTOS7.localdomain
Subject: hello
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: root@CENTOS7.localdomain (root)
Status: R
jdfsijdfsh
woeufhwauhfoaw
fowehofhoweaefh
&
hostname | tr “a-z” “A-Z”
CENTOS7.LOCALDOMAIN
hostname | tr “a-z” “A-Z” | tr -d “.”
CENTOS7LOCALDOMAIN
cat f1 | mail -s “hallo” wang  或者  mail -s “hallo” wang <f1
ls /boot /rereo | tr “a-z” “A-Z”
ls: cannot access /rereo: No such file or directory
/BOOT:
CONFIG-3.10.0-693.EL7.X86_64
EFI
GRUB
GRUB2
INITRAMFS-0-RESCUE-D9B2C489CDF948F8B487E98005C15E1C.IMG
INITRAMFS-3.10.0-693.EL7.X86_64.IMG
INITRD-PLYMOUTH.IMG
SYMVERS-3.10.0-693.EL7.X86_64.GZ
SYSTEM.MAP-3.10.0-693.EL7.X86_64
VMLINUZ-0-RESCUE-D9B2C489CDF948F8B487E98005C15E1C
VMLINUZ-3.10.0-693.EL7.X86_64
[root@CENTOS7 ~]#ls /boot /rereo 2>&1| tr “a-z” “A-Z”
LS: CANNOT ACCESS /REREO: NO SUCH FILE OR DIRECTORY
/BOOT:
CONFIG-3.10.0-693.EL7.X86_64
EFI
GRUB
GRUB2
INITRAMFS-0-RESCUE-D9B2C489CDF948F8B487E98005C15E1C.IMG
INITRAMFS-3.10.0-693.EL7.X86_64.IMG
INITRD-PLYMOUTH.IMG
SYMVERS-3.10.0-693.EL7.X86_64.GZ
SYSTEM.MAP-3.10.0-693.EL7.X86_64
VMLINUZ-0-RESCUE-D9B2C489CDF948F8B487E98005C15E1C
VMLINUZ-3.10.0-693.EL7.X86_64
[root@CENTOS7 ~]#ls /boot /rereO |& tr “a-z” “A-Z”
LS: CANNOT ACCESS /REREO: NO SUCH FILE OR DIRECTORY
/BOOT:
CONFIG-3.10.0-693.EL7.X86_64
EFI
GRUB
GRUB2
INITRAMFS-0-RESCUE-D9B2C489CDF948F8B487E98005C15E1C.IMG
INITRAMFS-3.10.0-693.EL7.X86_64.IMG
INITRD-PLYMOUTH.IMG
SYMVERS-3.10.0-693.EL7.X86_64.GZ
SYSTEM.MAP-3.10.0-693.EL7.X86_64
VMLINUZ-0-RESCUE-D9B2C489CDF948F8B487E98005C15E1C
VMLINUZ-3.10.0-693.EL7.X86_64
df | tr -s ” ” “.”
Filesystem.1K-blocks.Used.Available.Use%.Mounted.on
/dev/sda2.50264772.5081888.42622884.11%./
tmpfs.502056.76.501980.1%./dev/shm
/dev/sda1.999320.34944.911948.4%./boot
/dev/sda3.30106576.44992.28525584.1%./data
/dev/sr0.3878870.3878870.0.100%./media/CentOS_6.9_Final
echo {1..100} | tr ‘ ‘ + | bc
5050
[wang@centos ~]$echo {1..100} | tr ” ” + | bc
5050
[wang@centos ~]$echo {1..100} | tr ‘ ‘ “+” | bc
5050
[wang@centos ~]$echo {1..100} | tr ‘ ‘ “+” | bc
seq -s + 1 100 | bc
5050
echo “test print” | lpr – P print_name  将内容传给打印机
tar -cvf – /home | tar -xvf –   将/home目录打包在解包后面的-代表文件名不变
ls | tee f
Desktop
Documents
Downloads
f
f1.log
ls
motd
Music
Pictures
Public
Templates
Videos
[wang@CENTOS7 ~]$cat f
Desktop
Documents
Downloads
f
f1.log
ls
motd
Music
Pictures
Public
Templates
Videos
who | tee -a f
root     :0           2018-04-02 21:49 (:0)
wang     pts/0        2018-04-02 21:50 (192.168.30.1)
[wang@CENTOS7 ~]$cat f
Desktop
Documents
Downloads
f
f1.log
ls
motd
Music
Pictures
Public
Templates
Videos
root     :0           2018-04-02 21:49 (:0)
wang     pts/0        2018-04-02 21:50 (192.168.30.1)
ls | tee -a f | tr -d “\n”
DesktopDocumentsDownloadsff1.loglsmotdMusicPicturesPublicTemplatesVideos
cat /etc/issue | tr [:lower:] [:upper:] > /tmp/issue.out
[wang@CENTOS7 ~]$cat /tmp/issue.out
\S
KERNEL \R ON AN \M
[wang@CENTOS7 ~]$cat /etc/issue
\S
Kernel \r on an \m
who | tr “a-z” “A-Z” > /tmp/who.out
[wang@CENTOS7 ~]$who
root     :0           2018-04-02 21:49 (:0)
wang     pts/0        2018-04-02 21:50 (192.168.30.1)
[wang@CENTOS7 ~]$cat /tmp/who.out
ROOT     :0           2018-04-02 21:49 (:0)
WANG     PTS/0        2018-04-02 21:50 (192.168.30.1)
cat /etc/centos-release   centos 7 显示centos版本
CentOS Linux release 7.4.1708 (Core)
lsb_release -a  查看centos6的centos版本号
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.
0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.
0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.9 (Final)
Release: 6.9
Codename: Final
rpm -ivh /run/media/root/CentOS\ 7\ x86_64/Packages/
ls | tr “\n” ” “
anaconda-ks.cfg da Desktop Documents Downloads fi install.log install.log.syslog motd Music Pictures Public Templates Videos
cat -A 123.txt
a^M$
b^M$
c[wang@CENTOS7 ~]$
课后作业
cat -A f1
a$
b$
c[wang@CENTOS7 ~]$^C
cat f | tr -d -c ” 1-9″
 1  2  3  4
[wang@CENTOS7 ~]$echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/wang/.local/bin:/home/wang/bin
[wang@CENTOS7 ~]$echo $PATH | tr “:” “\n”
/usr/local/bin
/usr/bin
/usr/local/sbin
/usr/sbin
/home/wang/.local/bin
/home/wang/bin
#cat f | tr “0-9” “a-j”
cat /etc/centos-release |tr -dc “[:alpha:]”
CentOSLinuxreleaseCore
openssl rand -base64 8 生成随机字符8位?位数不对?
openssl rand -base64 8 | tr -dc “A-Za-z0-9”
touch `openssl rand -base64 8 | tr -dc “a-z0-9″`创建随机文件
Authentication:认证  Authorization:授权  Accouting|Audition:审计
用户登录系统时,系统会给用户一个令牌(token,identity)
用户想获得新的令牌必须重新登录
user1  /bin/cat context上下文 (运行此程序的用户身份,用户组身份)     /data/log
user2  /bin/cat     /data/log
user能不能使用这个文件是有user本身决定的
用户的主要组(primary group)  用户的附加组(supplementary group)  当一个user有多个group时user的权限是累加的
一个user必须有一个primary group且只有一个primary group
pwunconv  显示口令 pwconv 隐藏口令
[root@CENTOS7 ~]#cat /etc/passwd
nano /etc/passwd  修改账户信息
新建一个用户是系统从 /etc/skel 中将配置文件自动复制到用户的家目录
cp -r /etc/skel/.[^.]* /data/wang  复制配置文件到指定家目录
chsh -s /bin/csh wang
Changing shell for wang.
Shell changed.
fields 列 域  record 行
更改加密算法  authconfig   –passalgo=sha256 –update
更改加密算法是修改的cat /etc/login.defs中的文件
passwd -e wang   立即让口令过期
Expiring password for user wang.
passwd: Success
[root@CENTOS7 ~]#cat /etc/shadow
wang:$6$h//NLnKbS9hhBfPr$r5ER6UNXVR9QlLorxZKT6jI5xX5Z4CwThVs3uLBfOtG7AOjI8xvVxm1ssfKwtYCDmKYipULOvw25f.3iyLy6l1:0:0:99999:7:::
chage -d o wang 立即让口令过期
chage -l wang
Last password change : Apr 03, 2018
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires :  7
chage wang
Changing the aging information for wang
Enter the new value, or press ENTER for the default
Minimum Password Age [0]: 0
Maximum Password Age [99999]:
Last Password Change (YYYY-MM-DD) [2018-04-03]:
Password Expiration Warning [7]:
Password Inactive [-1]:
Account Expiration Date (YYYY-MM-DD) [-1]:
cat /etc/login.defs
nano /etc/login.defs 修改密码有效期
cat /var/spool/mail/wang  mail文件存放在/var/spool/mail中
cat /etc/default/useradd  系统默认新建账号模板
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
useradd -N zhang 创建账号使用users为主主
cat /etc/group 查看组信息 当登录后再将user加入组中需要从新登录才能生效
groups wang 查看wang账号都加入了什么组
问题wang:x:500:
screen:x:84:
[wang@centos root]$id wang
uid=500(wang) gid=0(root) groups=0(root),10(wheel)
gpasswd mage   修改mage组密码
Changing the password for group mage
New Password:
Re-enter new password:
They don’t match; try again
New Password:
Re-enter new password:
newgrp mage    更换组主
vipw  修改用户信息   pwck用于账户修改完成检查错误
vigr  修改组信息  grpck用于组修改完成检查错误
useradd -u 66666 xixi  指定uid
[root@CENTOS7 ~]#getent passwd xixi
xixi:x:66666:1002::/home/xixi:/bin/bash
useradd -ou 66666 xixi创建相同ID的账户
useradd -g wang f1 指定组主
id f1
uid=1001(f1) gid=1000(wang) groups=1000(wang)
chfn wang=useradd -c wang  修改用户信息
useradd -d /data/f1home f1 指定家目录
useradd -s /sbin/nologin -r f1 指定shell类型并且是服务账户,不创建家目录和邮件
useradd -s /sbin/nologin -r -m f2  强行创建家目录
-M不创建家目录但是创建邮件
-G加入已有的辅助组
ls /var/spool/mail 创建账号是存放邮件的地方
f1  mage  rpc  wang  xixi
useradd -G “f1,f2” f3  创建f3时直接加入辅助组f2,f1
[root@CENTOS7 home]#id f3
uid=1001(f3) gid=1001(f3) groups=1001(f3),986(f1),985(f2)
rpm -qp –scripts /run/media/root/CentOS\ 7\ x86_64/Packages/httpd-2.4.6-67.el7.centos.x86_64.rpm
查看光盘中的应用文件
user -D -s /bin/csh 修改/etc/default/useradd中的配置文件
useradd -D         useradd –D -s SHELL       useradd –D –b BASE_DIR       useradd –D –g GROUP
echo magedu | passwd –stdin f1 用于多个用户同一个密码的情况下集体设置密码
scp userkist.txt 192.168.30.128:/dara远程复制,将centos7中的userlist.txt 文件传输到centos6的data中
newusers /data/userlist.tst  一次创建多个账号
创建一个文件f1,在文件中写入
用户名1:密码1
用户名2:密码2
用户名3:密码3等等
cat f1 | chpasswd 一次性修改多个用户的密码,密码可以不同
usermod [OPTION] login  -u UID: 新UID  -g GID: 新主组  -G GROUP1[,GROUP2,…[,GROUPN]]]:新附加组,原来的附加组将会被覆盖; 若保留原有,则要同时使用-a选项
  -s SHELL:新的默认SHELL  -c ‘COMMENT’:新的注释信息  -d HOME: 新家目录不会自动创建;若要创建新家目录并移动原家数据,同时使 用-m选项
  -l login_name: 新的名字;  -L: lock指定用户,在/etc/shadow 密码栏的增加 !   -U: unlock指定用户,将 /etc/shadow 密码栏的 ! 拿掉
 -e YYYY-MM-DD: 指明用户账号过期日期  -f INACTIVE: 设定非活动期限
usermod -G bin wang 将王账号加入bin组
[root@CENTOS7 home]#id wang
uid=1000(wang) gid=1000(wang) groups=1000(wang),1(bin)
usermod -aG root  wang 继续追加进入root
usermod -G “” wang  去除wang账号的附加组
[root@CENTOS7 home]#id wang
uid=1000(wang) gid=1000(wang) groups=1000(wang)
[root@CENTOS7 home]#usermod -G wang wang
usermod -l wang oldwang 修改wang账户名为oldwang
userdel -r wang   删除wang账号及其/home下的文件夹及mail
id -u wang uid号
id -g wang gid号
id -G wang gid和辅助组的号
加n现实名字
su – root -c ‘cat /etc/shadow’
Password:
切换成root并执行’cat /etc/shadow’命令后返回wang账户
groupadd g1
[root@CENTOS7 ~]#gpasswd -a wang g1
groups wang
wang : wang g1
groupmems -l -g g1
wang
gpasswd -d wang g1
Removing user wang from group g1
[root@CENTOS7 ~]#groupmems -l -g g1
[root@CENTOS7 ~]#groupmems -a wang -g g1
[root@CENTOS7 ~]#groupmems -l -g g1
wang
[root@CENTOS7 ~]#groupmems -d wang -g g1
[root@CENTOS7 ~]#groupmems -l -g g1
nwegrp 是一个用户同时拥有2个组时切换主组   命令newgrp 辅组
read r 读权限
write w 写权限
excute x 执行权限
file r 看文件内容
file w 修改文件内容
file x 一般不需要执行权限
使用cat /bin/cat时导致乱码可以reset重置
[root@CENTOS7 data]#touch f1
root@CENTOS7 data]#ll f1
-rw-r–r–. 1 root root 0 Apr  4 19:26 f1
[root@CENTOS7 data]#chown wang f1 修改f1的拥有者
[root@CENTOS7 data]#ll f1
-rw-r–r–. 1 wang root 0 Apr  4 19:26 f1
[root@CENTOS7 data]#chgrp lele f1
[root@CENTOS7 data]#ll f1
-rw-r–r–. 1 wang lele 0 Apr  4 19:26 f1
[root@CENTOS7 data]#gpasswd -a wang g1 将wang加入g1组= groupmems -a wang -g g1
Adding user wang to group g1
[root@CENTOS7 data]#usermod -aG g2 wang
[root@CENTOS7 data]#id wang
uid=1000(wang) gid=1002(lele) groups=1002(lele),1001(g1),1003(g2)
usermod -g wang(组) wang 将wang组定义为wang的主组
[root@CENTOS7 ~]#id wang
uid=1000(wang) gid=1000(wang) groups=1000(wang)
usermod -aG g1,g2 wang
[root@CENTOS7 ~]#id wang
uid=1000(wang) gid=1000(wang) groups=1000(wang),1001(g1),1003(g2)
ll /data
total 0
-rw-r–r–. 1 wang lele 0 Apr  4 19:26 f1
umask默认022
修改umask默认值直接在umask 数字
[wang@CENTOS7 ~]$chgrp mage f1
chgrp: changing group of ‘f1’: Operation not permitted
[wang@CENTOS7 data]$chgrp g1 f1 想改变文件的组只能在wang用户所在的组中改变
[wang@CENTOS7 data]$ll f1
-rw-r–r–. 1 wang g1 0 Apr  4 19:26 f1
[wang@CENTOS7 data]$chgrp bin f1
chgrp: changing group of ‘f1’: Operation not permitted
1.
普通用户不能改变文件的所有者
2.普通用户想要改变文件的组必须是此文件的所有者且只能在用户在的组中选择。主组和附加组在授权时没有区别
对普通用户来说访问文件有3种人文件所有者 文件组中的人 路人
chmod change mode
chmod
方法1:mode 法
chmod who opt per file
who:u g o a(all)
opt:+ – =
per:r w x X
chmod u+x,g-w,o=  file
方法2:数字法
u    g   o
rwx rw- r–
111 110 100
chmod 764 file
r:4
w:2
x:1
— 000 0
–x 001 1
-w- 010 2
-wx 011
r– 100
r-x 101
rw- 110
rwx 111 7
[root@CENTOS7 ~]#groupmems -l -g g2  查看g2组成员
wang  lele
删除文件的权限是由目录决定的
ll -d /data  查看目录
drwxr-xr-x. 2 root root 16 Apr  4 19:26 /data
#chmod -x /bin/ls
[root@CENTOS7 ~]#ls
-bash: /bin/ls: Permission denied
chmod -x /bin/cat 去掉cat的执行权限
[root@CENTOS7 ~]#ll /bin/cat
-rw-r–r–. 1 root root 54080 Nov  6  2016 /bin/cat
cat /data/f1  cat命令无法执行
-bash: /bin/cat: Permission denied
root账号无视读写权限,但是遵循执行权限
对于二进制程序读权限不是必须的
失去读权限file命令无法判断cat的文件类型
d /data
[root@CENTOS7 data]#mkdir dir1
[root@CENTOS7 data]#ll
total 4
drwxr-xr-x. 2 root root 6 Apr  5 09:41 dir1
-rwxr—w-. 1 wang g1   7 Apr  5 09:16 f1
[root@CENTOS7 data]#cd dir1
[root@CENTOS7 dir1]#touch f1
[root@CENTOS7 dir1]#tree /data
/data
├── dir1
│?? └── f1
└── f1
在dir1目录下不能修改它的权限,当去掉dir1的r权限时,可以进入目录,但是不能查看目录内容,若果知道目录内容,可以打开目录下的文件
没有执行权限,不能进入目录,不能查看目录下的文件的内容,不能看到文件的属性
chmod –reference=f2 f1 f3 让f1和f3的权限和f2一样
[root@CENTOS7 data]#ll
total 4
drwxr-xr-x. 2 root root 16 Apr  5 10:27 dir1
-rw-r–r–. 1 wang g1    1 Apr  5 10:45 f1
-rw-r–r–. 1 root root  0 Apr  5 11:01 f2
-rw-r–r–. 1 root root  0 Apr  5 11:02 f3
cotal 八进制
chmod +X只对目录加执行权限,不对文件加执行权限.但是如果文件本身有执行权限,那么就会给文件也加上执行权限
[root@CENTOS7 data]#ll
total 0
d–x–x–x. 2 root root 17 Apr  5 11:35 dir1
[root@CENTOS7 data]#chown wang.g1 dir1  同时修改所有者和组
[root@CENTOS7 data]#ll
total 0
d–x–x–x. 2 wang g1 17 Apr  5 11:35 dir1
cp /bin/cat dir1
chmod 444 dir1
[wang@CENTOS7 data]$dir1/cat /etc/shadow
bash: dir1/cat: Permission denied
[root@CENTOS7 data]#chmod 111 dir1
[wang@CENTOS7 data]$dir1/cat /etc/issue
\S
Kernel \r on an \m
ll
total 0
d–x–x–x. 2 root root 17 Apr  5 11:35 dir1
[root@CENTOS7 data]#chown wang.g1 dir1
[root@CENTOS7 data]#ll
total 0
d–x–x–x. 2 wang g1 17 Apr  5 11:35 dir1
umask本质含义取消对应权限
umask + default(默认权限) =file666/dir777
umask默认值022, 修改默认值umask 数字
对file而言当对位相减之后如果是奇数则加一
root和普通用户的umask不同与文件安全有关,存放相关定义的文件是/etc/bashrc
umask -p
umask 0022
umask -p >> .bashrc
umask -S -p
umask -S u=rwx,g=rx,o=rx
?1、当用户docker对/testdir 目录无执行权限时,意味着无法做哪些操作?只能ls看到文件名
?2、当用户mongodb对/testdir 目录无读权限时,意味着无法做哪些操作?除了ls剩下都可以
?3、当用户redis 对/testdir 目录无写权限时,该目录下的只读文件file1是否可
修改和删除?除了cat都不行
?4、当用户zabbix对/testdir 目录有写和执行权限时,该目录下的只读文件file1
是否可修改和删除?可以删除不可以修改
?5、复制/etc/fstab文件到/var/tmp下,设置文件所有者为tomcat读写权限,所
属组为apps组有读写权限,其他人无权限
groupadd apps
useradd tomcat
cp /etc/fstab /var/tpm/
chown tomcat /var/rmp/fstab
chgrp apps /var/rmp/fstab
chmod 660 /var/rmp/fstab
?6、误删除了用户git的家目录,请重建并恢复该用户家目录及相应的权限属性
1
mkdir /home/git
cp -a /etc/skel/.[^.]* /home/git
或者
cp -r /etc/skel /home/git
2
chown -R git.git /home/git/
3
chmod 700 /home/git
suid:继承二进制程序所有者的权限 只适合二进制程序
sgid:
1)继承二进制程序所有组的权限
2)作用于目录,此目录新建的文件继承目录的所属组
sticky(粘制位):作用于目录,此目录的文件只能被所有者删除
r
w
x
u,g,o
umask
suid sgid,sticky
acl
df | tr -s ” ” |cut -d” ” -f5 |tr -d “%”
df|tr -s ” ” % |cut -d % -f5
取IP
centos6
ifconfig eth0 |head -n2|tail -n1 |tr -s ” ” : |cut -d: -f4
centos7
ifconfig ens33|head -n2 |tail -n1 |tr -s ” ” |cut -d” ”  -f3
centos6
service iptables stop
chkconfig iptables off
centos7
systemctl stop firewalld
systemctl disable firewalld
cut -d: -f1,3 /etc/passwd |sort -t: -k2 -nr
cat /var/log/httpd/access_log |cut -d” ” -f1 |sort  |uniq -c |sort -nr |head
chattr +i 不能删除,改名,更改
?chattr +a 只能追加内容
  chattr +A 锁定读时间   modtime修改时间 ctime 元数据修改时间
?lsattr 显示特定属性
ACL:Access Control List,实现灵活的权限管理
[root@CENTOS7 data]#setfacl -s u:wang:0 f1
[wang@CENTOS7 data]$cat f1
cat: f1: Permission denied
[root@CENTOS7 data]#setfacl -m u:mage:rw f1  修改
[root@CENTOS7 data]#su mage
[mage@CENTOS7 data]$echo 123456 >> f1
[mage@CENTOS7 data]$cat f1
123456
[mage@CENTOS7 data]$getfacl f1
# file: f1
# owner: root
# group: root
user::rw-
user:wang:—
user:mage:rw-
group::r–
mask::rw-
other::r–
[root@CENTOS7 data]#getfacl f1
# file: f1
# owner: root
# group: root
user::rw-
user:wang:—
user:mage:rw-
group::r–
mask::rw-
other::r–
[root@CENTOS7 data]#setfacl -x u:wang f1 删除wang
[root@CENTOS7 data]#getfacl f1
# file: f1
# owner: root
# group: root
user::rw-
user:mage:rw-
group::r–
mask::rw-
other::r–
[root@CENTOS7 data]#setfacl -m mask::r f1  设定mask的权限除了user和other其余的人都不可以超过mask的权限
[root@CENTOS7 data]#getfacl f1
# file: f1
# owner: root
# group: root
user::rw-
user:mage:rw- #effective:r–
group::r–
mask::r–
other::r–
[root@CENTOS7 data]#setfacl -b f1 清空ACL权限
[root@CENTOS7 data]#ll f1
-rw-r–r–. 1 root root 7 Apr  5 16:26 f1
[root@CENTOS7 data]#getfacl f1
# file: f1
# owner: root
# group: root
user::rw-
group::r–
other::r–
setfacl -M cal.txt f1 将cal.txt中的命令批量处理
 cal.txt 中存放的文件格式是
u:wang:rwx
g:g1:w
u:mage:x
setfacl -X acl.txt f1 批量删除
acl.txt 格式为
g:g1
[root@CENTOS7 data]#cat -n f1
     1 a
     2 b
     3 c
     4 d
     5 12
     6
     7 12
     8
     9
    10 12
    11
    12
    13
    14
    15
    16 13
[root@CENTOS7 data]#cat -b f1
     1 a
     2 b
     3 c
     4 d
     5 12
     6 12
     7 12
     8 13
[root@CENTOS7 data]#cat -n f1
     1 a
     2 b
     3 c
     4 d
     5 12
     6
     7 12
     8
     9
    10 12
    11
    12
    13
    14
    15
    16 13
[root@CENTOS7 data]#cat -ns f1
     1 a
     2 b
     3 c
     4 d
     5 12
     6
     7 12
     8
     9 12
    10
    11 13
[root@CENTOS7 data]#cat -A f1
a$
b$
c$
d$
12$
$
12$
$
$
12$
$
$
$
$
$
13$
tac 将竖着的反过来
rev将横着的反过来
cat anaconda-ks.cfg 太多
more anaconda-ks.cfg 可以分页显示
ls -R /etc/ |more 分页查看大量文件
ls -R /etc/ |less 同上,翻到低不退出,支持搜索
head 默认显示前10行
ifconfig | head -n2 显示前2行
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.30.101  netmask 255.255.255.0  broadcast 192.168.30.255
openssl rand -base64 100 |tr -dc “0-9a-z” |head -c12
[root@CENTOS7 ~]#echo abcd | tail -c2
d
[root@CENTOS7 ~]#cat /var/log/messages | tail -n5
Apr  5 17:52:44 CENTOS7 dbus[587]: [system] Successfully activated service ‘org.freedesktop.nm_dispatcher’
Apr  5 17:52:44 CENTOS7 dbus-daemon: dbus[587]: [system] Successfully activated service ‘org.freedesktop.nm_dispatcher’
Apr  5 17:52:44 CENTOS7 systemd: Started Network Manager Script Dispatcher Service.
Apr  5 17:52:44 CENTOS7 nm-dispatcher: req:1 ‘dhcp4-change’ [ens33]: new request (4 scripts)
Apr  5 17:52:44 CENTOS7 nm-dispatcher: req:1 ‘dhcp4-change’ [ens33]: start running ordered scripts…
tail -f f  追中f文件中的变化
tail -F f  追中文件名
[root@CENTOS7 ~]#ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.30.101  netmask 255.255.255.0  broadcast 192.168.30.255
        inet6 fe80::19e7:a41a:a0ac:2f54  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:45:bf:14  txqueuelen 1000  (Ethernet)
        RX packets 20639  bytes 1760788 (1.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 13544  bytes 4139158 (3.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[root@CENTOS7 ~]#ifconfig ens33 | head -n2 | tail -n1
        inet 192.168.30.101  netmask 255.255.255.0  broadcast 192.168.30.255
[root@CENTOS7 ~]#df |tr -s ” ” “%” | cut -d% -f5
Use
7
0
0
2
0
1
16
1
100
0
[root@CENTOS7 ~]#ifconfig | head -n2 |tail -n1|tr -s ” ” |cut -d” ” -f3
192.168.30.101
[root@CENTOS7 ~]#cut -d: -f1,3 –output-delimiter=”==” /etc/passwd
root==0
bin==1
daemon==2
adm==3
lp==4
service httpd start 开启服务器
root@centos ~]#paste f1 f2
1 5
2 6
3 7
4 8
[root@centos ~]#cat f1 f2
1
2
3
4
5
6
7
8[root@centos ~]#
[root@centos ~]#paste -s f1 f2
1 2 3 4
5 6 7 8
[root@centos ~]#paste -s -d”:” f1 f2
1:2:3:4
5:6:7:8
wc=word count
[root@centos ~]#wc f1
4(几行) 4(几个单词) 8 (几个字节)f1
[root@centos ~]#ls | wc
     16      16     131
[root@centos ~]#wc -l /etc/passwd
35 /etc/passwd
[root@centos ~]#wc -w /etc/passwd
55 /etc/passwd
[root@centos ~]#wc -c /etc/passwd
1661 /etc/passwd
[root@centos ~]#ll /etc/passwd
-rw-r–r–. 1 root root 1661 Apr  3 22:11 /etc/passwd
[root@centos ~]#wc -m /etc/passwd
1661 /etc/passwd
[root@centos ~]#wc -L /etc/passwd
79 /etc/passwd
[root@centos ~]#who | wc -l
2
[root@centos ~]#cat /var/log/httpd/access_log |wc -l
44
[root@CENTOS7 ~]#df | tr -s ” ” “%” |cut -d% -f5 |sort -rn | head -n1
100
[root@centos ~]#cut -d ” ” -f1 /var/log/httpd/access_log|sort -u |wc -l
3
[root@centos ~]#seq 1 102 |sort -R | head -n1
28
[root@centos ~]#seq 1 102 |sort -R | head -n1
57
[root@centos ~]#seq 1 102 |sort -R | head -n1
56
[root@centos ~]#seq 1 102 |sort -R | head -n1
60
cut -d “:” -f 1,3 /etc/passwd | sort -t: -k2 -nr
[root@CENTOS7 ~]#cat >f
aa
aa
bb
bb
aa
cc
ccc
ccc
bb
[root@CENTOS7 ~]#uniq f
aa
bb
aa
cc
ccc
bb
[root@CENTOS7 ~]#uniq -c f
      2 aa
      2 bb
      1 aa
      1 cc
      2 ccc
      1 bb
[root@CENTOS7 ~]#uniq -u f
aa
cc
bb
[root@centos ~]#cat /var/log/httpd/access_log |cut -d” ” -f1 |sort|uniq -c |sort -nr |head
     36 172.20.48.1
      5 192.168.30.1
      3 172.20.86.125
[root@centos ~]#cp /etc/fstab fstab
[root@centos ~]#cp /etc/fstab fstab2
[root@centos ~]#nano fatab
[root@centos ~]#ll fstab
-rw-r–r–. 1 root root 899 Apr  5 20:42 fstab
[root@centos ~]#nano fstab
[root@centos ~]#diff fstab fstab2
4c4
< # eated by anaconda on Tue Mar 27 16:59:39 2018
> # Created by anaconda on Tue Mar 27 16:59:39 2018
12c12
< UUaaaaID=9fc26932-7094-4948-b395-24ab05d8ea73 swap                    swap    defaults        0 0
> UUID=9fc26932-7094-4948-b395-24ab05d8ea73 swap                    swap    defaults        0 0
[root@centos ~]#diff -u fstab fstab2 >diff.log
patch -b fstab2 diff.log
patching file fstab2
Reversed (or previously applied) patch detected!  Assume -R? [n] y
[root@centos ~]#ls
anaconda-ks.cfg  diff.log   f1  fstab2       install.log.syslog  Pictures   Videos
da               Documents  f2  fstab2.orig  motd                Public
Desktop          Downloads  fi  install.log  Music               Templates
[root@centos ~]#diff fstab2 fstab2.orig
4c4
< # eated by anaconda on Tue Mar 27 16:59:39 2018
> # Created by anaconda on Tue Mar 27 16:59:39 2018
12c12
[root@CENTOS7 ~]#grep abc
ljfiea;if
abcielaeiwoabc
abcielaeiwoabc
[root@CENTOS7 ~]#grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@CENTOS7 ~]#grep “$USER” /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@CENTOS7 ~]#grep `whoami` /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@CENTOS7 ~]#grep -v root /etc/passwd  不包括root
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@CENTOS7 ~]#grep -i “ROOT” /etc/passwd -i忽略大小写
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@CENTOS7 ~]#grep -n “root” /etc/passwd
1:root:x:0:0:root:/root:/bin/bash
10:operator:x:11:0:operator:/root:/sbin/nologin
[root@CENTOS7 ~]#cat -n /etc/passwd | grep root
     1 root:x:0:0:root:/root:/bin/bash
    10 operator:x:11:0:operator:/root:/sbin/nologin
[root@CENTOS7 ~]#ls |grep ks 当成一个字符串
anaconda-ks.cfg
initial-setup-ks.cfg
[root@CENTOS7 ~]#ls *ks* 通配符匹配文件的
anaconda-ks.cfg  initial-setup-ks.cfg
 –color=auto: 对匹配到的文本着色显示
? -v: 显示不被pattern匹配到的行
? -i: 忽略字符大小写
? -n:显示匹配的行号
? -c: 统计匹配的行数
? -o: 仅显示匹配到的字符串
? -q: 静默模式,不输出任何信息
? -A #: after, 后#行
? -B #: before, 前#行
? -C #:context, 前后各#行
? -e:实现多个选项间的逻辑or关系
grep –e ‘cat ’ -e ‘dog’ file
? -w:匹配整个单词
? -E:使用ERE
? -F:相当于fgrep,不支持正则表达式
[root@CENTOS7 ~]#grep -q “root” /etc/passwd 静默模式  grep “root” /etc/passwd > /dev/null
[root@CENTOS7 ~]#echo $?   0是找到了
0
[root@CENTOS7 ~]#grep -q “sudhfiuehwf” /etc/passwd
[root@CENTOS7 ~]#echo $?  非0没找到
1
[root@CENTOS7 ~]#grep -nA3 “root” /etc/passwd
1:root:x:0:0:root:/root:/bin/bash
2-bin:x:1:1:bin:/bin:/sbin/nologin
3-daemon:x:2:2:daemon:/sbin:/sbin/nologin
4-adm:x:3:4:adm:/var/adm:/sbin/nologin
[root@CENTOS7 ~]#grep -nB3 “root” /etc/passwd
1:root:x:0:0:root:/root:/bin/bash
7-shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
8-halt:x:7:0:halt:/sbin:/sbin/halt
9-mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10:operator:x:11:0:operator:/root:/sbin/nologin
[root@CENTOS7 ~]#grep -nC2 “root” /etc/passwd
1:root:x:0:0:root:/root:/bin/bash
2-bin:x:1:1:bin:/bin:/sbin/nologin
3-daemon:x:2:2:daemon:/sbin:/sbin/nologin
8-halt:x:7:0:halt:/sbin:/sbin/halt
9-mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10:operator:x:11:0:operator:/root:/sbin/nologin
11-games:x:12:100:games:/usr/games:/sbin/nologin
12-ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nmap -v -sP 172.20.108.0/24  扫描网段
[root@CENTOS7 ~]#grep -e “root” -e “bash” /etc/passwd  搜索root或者bash
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
wang:x:1000:1000:wang:/home/wang:/bin/bash
lele:x:1001:1002::/home/lele:/bin/bash
mage:x:1002:1004::/home/mage:/bin/bash
git:x:1003:1005::/home/git:/bin/bash
[root@CENTOS7 ~]#grep “root” /etc/passwd | grep “bash” 字符串中有root和bash
root:x:0:0:root:/root:/bin/bash
echo “x123abc_jiea” 下划线和数字都是单词。-w()
file -f 文件
grep -f 文件
cat >f
root
bash
^C
[root@CENTOS7 ~]#grep -f f /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
wang:x:1000:1000:wang:/home/wang:/bin/bash
lele:x:1001:1002::/home/lele:/bin/bash
mage:x:1002:1004::/home/mage:/bin/bash
git:x:1003:1005::/home/git:/bin/bash
[root@CENTOS7 ~]#echo abbc | grep a..c
abbc
[root@CENTOS7 ~]#echo abgc | grep a..c
abgc
[root@CENTOS7 ~]#echo abgbc | grep a..c
[root@CENTOS7 ~]#echo abcdef | grep “a[^xyz]c”  匹配[]中的任意一个字符
abcdef
[root@CENTOS7 ~]#echo axb | grep “ax*b”  x*表示0到无限个x
axb
[root@CENTOS7 ~]#echo ab | grep “ax*b”
ab
[root@CENTOS7 ~]#echo axxb | grep “ax*b”
axxb
[root@CENTOS7 ~]#ls | grep “.*\.cfg”
anaconda-ks.cfg
initial-setup-ks.cfg
[root@CENTOS7 ~]#ls *.cfg
anaconda-ks.cfg  initial-setup-ks.cfg
[root@CENTOS7 ~]#ls | grep “.*\.cfg”  贪婪模式
anaconda-ks.cfg
initial-setup-ks.cfg
[root@CENTOS7 ~]#ls *.cfg    0次或者1次
anaconda-ks.cfg  initial-setup-ks.cfg
在正得表达式中[.]只是代表.本身的含义
ifconfig ens33 | grep -w inet | grep -o ” [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.”
 192.168.30.101
 255.255.255.0
 192.168.30.255
[wang@CENTOS7 ~]$ifconfig ens33 |grep -o “[0-9.]\{7,\}”
192.168.30.101
255.255.255.0
192.168.30.255
[wang@CENTOS7 ~]$ifconfig ens33 |grep -o “inet [0-9.]\+”
inet 192.168.30.101
[wang@CENTOS7 ~]$df |grep “sda” |grep -o “[0-9]\{,3\}%”| grep -o “[0-9]\+” | sort -nr | head -n1
16
[wang@CENTOS7 ~]$cat /etc/fstab | grep -v “^#” |grep -v “^$”
UUID=0a1bc23e-06e5-4210-9b32-0edbff09ca1a /                       xfs     defaults        0 0
UUID=4d8d9214-eeed-4758-8c34-f05492b9ea73 /boot                   xfs     defaults        0 0
UUID=fb669d84-551f-4a70-a11e-f61deec0fd86 /data                   xfs     defaults        0 0
UUID=906330a5-2af1-4bf4-8b2d-9337eaf92250 swap                    swap    defaults        0 0
[wang@CENTOS7 ~]$cat /etc/fstab | grep “^U.*”
UUID=0a1bc23e-06e5-4210-9b32-0edbff09ca1a /                       xfs     defaults        0 0
UUID=4d8d9214-eeed-4758-8c34-f05492b9ea73 /boot                   xfs     defaults        0 0
UUID=fb669d84-551f-4a70-a11e-f61deec0fd86 /data                   xfs     defaults        0 0
UUID=906330a5-2af1-4bf4-8b2d-9337eaf92250 swap                    swap    defaults        0 0
[wang@CENTOS7 ~]$cat f
abc
ert
lfiheofih
[wang@CENTOS7 ~]$cat f | grep -v “^[[:space:]]*$”
abc
ert
lfiheofih
[wang@CENTOS7 ~]$echo wangwangwang | grep “\(wang\)\{3,\}”
wangwangwang
[root@centos ~]#echo wangwangwangmagemagemageeuhewhfowangwangwangmagemagemage | grep “\(wang\)\+.*\(mage\)\+\1.*\2”
[root@centos ~]#echo wangwangwangmagemagemageeuhewhfowangwangwangmagemagemage | grep “\(wang\)\+.*\(mage\)\+.*\1.*\2”
wangwangwangmagemagemageeuhewhfowangwangwangmagemagemage
cat /etc/passwd | grep -w “^\(.*\):.*\1$”
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
[root@centos ~]#cat /etc/passwd | grep -w “^\(.*\):.*/\1$”
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
[root@centos ~]#cat /etc/passwd | grep “^\(a\|b\).*”
bin:x:1:1:bin:/bin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
[root@centos ~]#cat /etc/centos-release | grep -o ” [0-9]”
 6
nano /etc/redhat-release  修改版本号
cat /etc/passwd | grep -wo “[0-9]\{2,3\}”
[wang@CENTOS7 ~]$cat /etc/passwd | grep -w “^\(wang\|mage\|root\)”
root:x:0:0:root:/root:/bin/bash
wang:x:1000:1000:wang:/home/wang:/bin/bash
mage:x:1002:1004::/home/mage:/bin/bash
[wang@CENTOS7 ~]$cat /etc/passwd | grep “^\(wang\|mage\|root\)\>”
root:x:0:0:root:/root:/bin/bash
wang:x:1000:1000:wang:/home/wang:/bin/bash
mage:x:1002:1004::/home/mage:/bin/bash
[wang@CENTOS7 ~]$basename /etc/rc.d/init.d/functions
functions
[wang@CENTOS7 ~]$dirname /etc/rc.d/init.d/functions
/etc/rc.d/init.d
[wang@CENTOS7 ~]$
[root@CENTOS7 ~]#echo /etc/rc.d/init.d/functions | grep -o “[^/]*$”
functions
root@CENTOS7 ~]#echo /etc/rc.d/init.d/ | grep -o “[^/]*/\?$”
init.d/
[root@CENTOS7 ~]#echo /etc/rc.d/init.d | grep -o “[^/]*/\?$”
init.d
vim +10 /etc/passwd  跳到第10行
vim +/^ftp /etc/passwd 以ftp开头的行
vim -b /bin/ls   打开2进制文件
vim -d f1 f2     比较两个文件的不同
vim -m f1         只读
i光标前输入I行首输入a光标后输入A行尾输入
o光标下一行O光标上一行
:进入扩展模式wq保存退出q退出q!强制退出w file另存为,如果文件存在想强行修改w! file , r file 将文件读入当前
^[[1;31mred^[[0m  红色的red^[,是用Ctrl+v+[
10+h左j下k上l右       向哪儿方向移动多少次
w下一个单词词首e下一个单词词尾b前一个单词词首
H文件这一页的第一行行首L最后一行行首M本页行中
0行首$行尾^非空行首G文件最后gg文件开始的地方
空行或者.空格分割算一个句子,{}
空行算一个段落
x剪切p复制 xp对调 X从光标处往前删
~转换大小写最多一行J删除光标后的回车符
r替换一个字符。R切入替换模式
dd剪切一行,d$光标之后的d0光标之前的
yy复制一行 同上
c删除并进入insert模式
0gu$ 0gU$切换大小写
%s/^\(UUID\)/ #\1/
%s/^UUID/#&/
vim /var/www/html/hell.sh
service httpd start
curl http://192.168.30.128/hell.sh | bash

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/95442

(0)
上一篇 2018-04-08 17:58
下一篇 2018-04-08 18:10

相关推荐