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.www58058.com/95442