Cnode
cp 複製命令linux
cp -p 會保留源文件的全部者,時間戳正則表達式
cp -a 保留文件全部屬性,用於備份shell
root下的cp 命令是別名,cp -i 在覆蓋前會提示是否覆蓋vim
cp命令若是上次執行選項爲--backup=numbered ,下次執行cp -b會執行上次執行過的--backup=numbered選項windows
[root@centos8 network-scripts]# stat ifcfg-ens160 File: ifcfg-ens160 Size: 312 Blocks: 8 IO Block: 4096 regular file Device: 802h/2050d Inode: 69938036 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: system_u:object_r:net_conf_t:s0 Access: 2020-03-29 15:36:14.068397951 +0800 Modify: 2020-03-16 19:00:30.231503208 +0800 Change: 2020-03-16 19:00:30.231503208 +0800 Birth: - [root@centos8 network-scripts]# stat /data/ifcfg-ens160 File: /data/ifcfg-ens160 Size: 312 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 131 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:etc_runtime_t:s0 Access: 2020-03-29 15:36:14.068397951 +0800 Modify: 2020-03-16 19:00:30.231503208 +0800 Change: 2020-03-29 17:49:49.010994553 +0800 Birth: - [root@centos8 network-scripts]# cp -a ifcfg-ens160 /data/ifcfg-ens161 [root@centos8 network-scripts]# stat /data/ifcfg-ens161 File: /data/ifcfg-ens161 Size: 312 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 132 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: system_u:object_r:net_conf_t:s0 Access: 2020-03-29 15:36:14.068397951 +0800 Modify: 2020-03-16 19:00:30.231503208 +0800 Change: 2020-03-29 17:51:51.304570093 +0800 Birth: -
[root@centos8 data]# cp --backup=numbered /etc/sysconfig/network-scripts/ifcfg-ens160 /data/ifcfg-ens160
cp: overwrite '/data/ifcfg-ens160'? y
[root@centos8 data]# ls
2 ifcfg-ens160 ifcfg-ens160.~1~ ifcfg-ens161
[root@centos8 data]# cp -b /etc/sysconfig/network-scripts/ifcfg-ens160 /data/ifcfg-ens160
cp: overwrite '/data/ifcfg-ens160'? y
[root@centos8 data]# ls
2 ifcfg-ens160 ifcfg-ens160.~1~ ifcfg-ens160.~2~ ifcfg-ens161
chown 更改文件全部者和所屬組centos
[root@centos8 data]# chown rzx ifcfg-ens160 [root@centos8 data]# ll total 20 -rw-r--r--. 1 root root 312 Mar 29 18:01 2 -rw-r--r--. 1 rzx root 312 Mar 29 18:04 ifcfg-ens160 [root@centos8 data]# chown rzx.bin ifcfg-ens160 [root@centos8 data]# ll total 20 -rw-r--r--. 1 root root 312 Mar 29 18:01 2 -rw-r--r--. 1 rzx bin 312 Mar 29 18:04 ifcfg-ens160
chgrp 更改文件所屬組安全
[root@centos8 data]# chgrp root ifcfg-ens160 [root@centos8 data]# ll total 20 -rw-r--r--. 1 root root 312 Mar 29 18:01 2 -rw-r--r--. 1 rzx root 312 Mar 29 18:04 ifcfg-ens160
chmod 更改文件權限bash
[root@centos8 data]# chmod a=rwx ifcfg-ens160 [root@centos8 data]# ll total 20 -rw-r--r--. 1 root root 312 Mar 29 18:01 2 -rwxrwxrwx. 1 rzx root 312 Mar 29 18:04 ifcfg-ens160 -rw-r--r--. 1 root root 312 Mar 16 19:00 ifcfg-ens160.~1~ -rw-r--r--. 1 root root 312 Mar 29 18:04 ifcfg-ens160.~2~ -rw-r--r--. 1 root root 312 Mar 16 19:00 ifcfg-ens161 [root@centos8 data]# chmod 642 ifcfg-ens160 [root@centos8 data]# ll total 20 -rw-r--r--. 1 root root 312 Mar 29 18:01 2 -rw-r---w-. 1 rzx root 312 Mar 29 18:04 ifcfg-ens160 -rw-r--r--. 1 root root 312 Mar 16 19:00 ifcfg-ens160.~1~ -rw-r--r--. 1 root root 312 Mar 29 18:04 ifcfg-ens160.~2~ -rw-r--r--. 1 root root 312 Mar 16 19:00 ifcfg-ens161
suid,u+s,4***權限,在運行該文件時,會臨時獲取該文件全部者的權限來執行,app
sgid,g+s,2***權限,在具備sgid權限的目錄中建立文件時,建立的文件所屬組會從改目錄繼承
sticky,g+t,1***權限,在具備sticky權限的目錄中建立的文件,只有root用戶和文件全部者才能刪除該文件,防止其餘用戶惡意刪除本身的文件
chattr +i +a 爲文件增長特殊屬性,防止root用戶誤操做,+i可讓文件沒法刪除,更名,修改,+a可讓文件只能追加內容,沒法刪除更名。
chpasswd 批量修改用戶口令
chage 修改密碼策略
-d LAST_DAY 上次更改密碼的時間
-m --mindays MIN_DAYS 更改密碼後沒法馬上修改密碼的期限
-M --maxdays MAX_DAYS 密碼有效期
-W --warndays WARN_DAYS 密碼到期前幾天提醒
-I --inactive INACTIVE #密碼過時後的寬限期
-E --expiredate EXPIRE_DATE #用戶的有效期
-l 顯示密碼策略
chsh 臨時修改shell類型
chfn 修改我的信息
D
dd if=/dev/zero of=/data/bigfile bs=1M count=700
建立一個700M的大文件
[root@centos8 data]# dd if=/dev/zero of=/data/bigfile bs=1M count=700 700+0 records in 700+0 records out 734003200 bytes (734 MB, 700 MiB) copied, 3.75938 s, 195 MB/s [root@centos8 data]# ll total 716820 -rw-r--r--. 1 root root 312 Mar 29 18:01 2 -rw-r--r--. 1 root root 734003200 Mar 29 18:14 bigfile
G
getent passwd | shadow |group| gshadow name
查看/etc/下的passwd、shadow、group、gshadow文件,命令後面能夠加用戶名或者組名來只查看改用戶或組,至關於 cat /etc/passwd | shadow |group| gshadow
groupadd 建立組 -g能夠指定gid,-r能夠建立系統組,linux6及之前爲1-499,linux7之後爲1-999
[root@centos8 data]# groupadd -g 10010 ren [root@centos8 data]# getent group ren ren:x:10010: [root@centos8 data]# groupadd -g 587 -r zi [root@centos8 data]# getent group zi zi:x:587:
groupmod 修改組屬性 -n 修改組名字 -g 修改組的GID
groupdel 刪除組
getfacl 查看acl權限
gpasswd 修改組密碼
groups 查看用戶屬於哪一個組
[root@centos8 data]# groups rzx rzx : rzx ren
groupmems 管理附加組的成員關係
-g 更改成指定組 (只有root能使用)
-a 指定用戶加入組
-d 從組中刪除用戶
-p 從組中清除全部成員
-l list #顯示組成員列表
[root@centos8 data]# groups rzx rzx : rzx ren [root@centos8 data]# groupmems -d rzx -g ren [root@centos8 data]# groups rzx rzx : rzx [root@centos8 data]# groupmems -g ren -l rzx root [root@centos8 data]# groupmems -g ren -p [root@centos8 data]# groupmems -g ren -l [root@centos8 data]#
L
lsof lsof |grep delete 查看目前正在使用的文件
ln 設置連接,ln * * 建立硬連接,ln -s * * 建立軟鏈接,硬連接不支持跨分區和文件夾,至關於源文件的另外一個名字,刪除源文件後硬連接不會受影響,文件還在裏面;軟鏈接支持跨分區和文件夾,刪除軟鏈接文件自己不會刪除源文件,刪除源文件會致使軟鏈接沒法使用
lsattr 顯示文件的特殊屬性
M
mkdir -p ,建立目錄時,若是目標父目錄不存在則建立出來父目錄再建立目標目錄
[root@centos8 data]# ll total 716820 -rw-r--r--. 1 root root 312 Mar 29 18:01 2 -rw-r--r--. 1 root root 734003200 Mar 29 18:14 bigfile -rw-r---w-. 1 rzx root 312 Mar 29 18:04 ifcfg-ens160 -rw-r--r--. 1 root root 312 Mar 16 19:00 ifcfg-ens160.~1~ -rw-r--r--. 1 root root 312 Mar 29 18:04 ifcfg-ens160.~2~ -rw-r--r--. 1 root root 312 Mar 16 19:00 ifcfg-ens161 You have mail in /var/spool/mail/root [root@centos8 data]# mkdir asd/asd/ mkdir: cannot create directory ‘asd/asd/’: No such file or directory [root@centos8 data]# mkdir -p asd/asd/ [root@centos8 data]# ll total 716820 -rw-r--r--. 1 root root 312 Mar 29 18:01 2 drwxr-xr-x. 3 root root 17 Mar 29 18:39 asd -rw-r--r--. 1 root root 734003200 Mar 29 18:14 bigfile -rw-r---w-. 1 rzx root 312 Mar 29 18:04 ifcfg-ens160 -rw-r--r--. 1 root root 312 Mar 16 19:00 ifcfg-ens160.~1~ -rw-r--r--. 1 root root 312 Mar 29 18:04 ifcfg-ens160.~2~ -rw-r--r--. 1 root root 312 Mar 16 19:00 ifcfg-ens161
mail 發送郵件
[root@centos8 data]# mail -s hahaha root <<! > aaaaaaaaaa > ! [root@centos8 data]# mail Heirloom Mail version 12.5 7/5/10. Type ? for help. "/var/spool/mail/root": 6 messages 6 new >N 1 Mail Delivery System Wed Mar 25 14:13 83/2758 "Undelivered Mail Returned to Se" N 2 rzx Thu Mar 26 21:40 19/672 "help" N 3 rzx Thu Mar 26 21:48 19/634 "help" N 4 rzx Thu Mar 26 21:53 34/1020 "help" N 5 rzx Thu Mar 26 21:54 34/1020 "help" N 6 root Sun Mar 29 18:38 18/581 "hahaha" & 6 Message 6: From root@centos8.1.rzx.org Sun Mar 29 18:38:21 2020 Return-Path: <root@centos8.1.rzx.org> X-Original-To: root Delivered-To: root@centos8.1.rzx.org Date: Sun, 29 Mar 2020 18:38:21 +0800 To: root@centos8.1.rzx.org Subject: hahaha User-Agent: Heirloom mailx 12.5 7/5/10 Content-Type: text/plain; charset=us-ascii From: root <root@centos8.1.rzx.org> Status: R aaaaaaaaaa
N
newgrp 臨時切換主組
O
openssl rand -base649 或者12 生成隨機字符
P
pstree 查看用戶使用的進程並以樹狀排列出來
[root@centos8 data]# pstree systemd─┬─ModemManager───2*[{ModemManager}] ├─NetworkManager───2*[{NetworkManager}] ├─VGAuthService ├─agetty ├─alsactl ├─atd ├─auditd─┬─sedispatch │ └─2*[{auditd}] ├─automount───4*[{automount}] ├─avahi-daemon───avahi-daemon ├─bluetoothd ├─chronyd ├─crond ├─cupsd ├─dbus-daemon───{dbus-daemon} ├─dnsmasq───dnsmasq ├─firewalld───{firewalld} ├─gssproxy───5*[{gssproxy}] ├─ksmtuned───sleep ├─libvirtd───16*[{libvirtd}] ├─lsmd ├─master─┬─cleanup │ ├─local │ ├─pickup │ ├─qmgr │ └─trivial-rewrite ├─mcelog ├─packagekitd───3*[{packagekitd}] ├─polkitd───5*[{polkitd}] ├─rngd───{rngd} ├─rpc.statd ├─rpcbind ├─rsyslogd───2*[{rsyslogd}] ├─smartd ├─sshd───sshd───sshd───bash───pstree ├─sssd─┬─sssd_be │ └─sssd_nss ├─systemd─┬─(sd-pam) │ ├─dbus-daemon───{dbus-daemon} │ └─pulseaudio───2*[{pulseaudio}] ├─systemd-journal ├─systemd-logind ├─systemd-machine ├─systemd-udevd ├─tuned───3*[{tuned}] └─vmtoolsd───{vmtoolsd}
R
rename 批量修改文件名
rev echo 「**」 |rev 將雙引號內字符按倒序排列
rmdire 只能刪除空文件夾
S
shred 在數據安全需求較高的場景下安全刪除文件,使文件沒法恢復
su - -c cmd 切換用戶執行命令後退回當前用戶
stat 查看文件的詳細屬性
[root@centos8 data]# stat ifcfg-ens160 File: ifcfg-ens160 Size: 312 Blocks: 8 IO Block: 4096 regular file Device: 803h/2051d Inode: 131 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:etc_runtime_t:s0 Access: 2020-03-29 18:47:13.698008002 +0800 Modify: 2020-03-29 18:47:13.698008002 +0800 Change: 2020-03-29 18:47:13.698008002 +0800 Birth: -
setfacl 設置ACL權限
[root@centos8 data]# setfacl -m u:rzx:r ifcfg-ens160 [root@centos8 data]# getfacl ifcfg-ens160 # file: ifcfg-ens160 # owner: root # group: root user::rw- user:rzx:r-- group::r-- mask::r-- other::r--
acl只針對指定的用戶和組,沒法針對other進行限制,在文件具有ACL時,chmod修改權限時 時是設置acl中的mask的參數
T
tree 查看目錄結構
tail -f * 查看文件倒數10行的內容而且不退出
tee
echo 「***」 | tee /* 將***重定向到*中並顯示執行結果,若是名字相同會覆蓋內容
echo 「***」 | tee -a /* 將***重定向到*中並顯示執行結果,若是名字相同會追加內容
tar 壓縮、解壓縮工具
U
useradd 新增用戶
-u UID
-o 配合-u 選項,不檢查UID的惟一性
-g GID 指明用戶所屬基本組,可爲組名,也能夠GID
-c "COMMENT「 用戶的註釋信息
-d HOME_DIR 以指定的路徑(不存在)爲家目錄
-s SHELL 指明用戶的默認shell程序,可用列表在/etc/shells文件中
-G GROUP1[,GROUP2,...] 爲用戶指明附加組,組須事先存在
-N 不建立私用組作主組,使用users組作主組
-r 建立系統用戶 CentOS 6以前: ID<500,CentOS 7之後: ID<1000
-m 建立家目錄,用於系統用戶
-M 不建立家目錄,用於非系統用戶
[root@centos8 data]# useradd -d /data/zi -u 3306 -g zi -s /bin/nologin zi [root@centos8 data]# getent passwd zi zi:x:3306:587::/data/zi:/bin/nologin
/bin/nologin /bin/false 用戶沒法登陸的shell類型 nologin會提示沒法登陸,false不會提示但也沒法登陸
usermod 修改用戶屬性
userdel 刪除用戶
umask 掩碼,建立新文件或目錄時減去umask的值就是文件或目錄的默認權限,目錄的默認權限爲777-umask,文件的默認權限爲666-umask,文件默認不容許帶執行權限,因此計算得出的值爲奇數則須要+1來生成權限
(umask 666;touch /data/2.aaa)只對括號內新建立獲得文件生效
V
vi 文本編輯工具
vim 文本編輯工具,vi的強化版
W
w 能夠查看每一個終端上正在運行什麼程序
通常狀況下,相對路徑指定相對於當前工做目錄,特殊場景下,是相對於某目錄的位置
ls -R 列出當前全部文件夾下全部的文件, 遍歷
ls -ld * 列出*的屬性
ll --time=atime * 查看*文件的查看時間
ll --time=ctime * 查看*文件的屬性更改的時間
Inode 每一個文件的惟一標識,節點編號,df -i 能夠查看各個磁盤分區inode的使用狀況,inode所有使用完後將沒法建立新文件,不管硬盤空間還有多大
ll ~- 顯示上次目錄
*沒法匹配.開頭的隱藏文件
l. 只顯示隱藏文件別名 ls -d .*
ls -d */ 只顯示當前目錄下的子目錄
echo $$ 能夠查看當前終端使用的shell的pid
/dev/urandom 隨機字符 head -c+數字 能夠取出前*位的字符
/etc/null 垃圾箱
>=1> 將輸出結果重定向,會覆蓋源文件,>>向文件中追加內容
2> 將報錯、警報、提示信息重定向,2>>向文件中追加內容
cat /dev/null > * 清空*文件
echo -n > * 清空*文件
> * 清空*文件
&> 把全部輸出重定向,&>>向文件中追加內容
(命令;命令) > * 將多個命令結果重定向
{命令;命令;} > * 將多個命令結果重定向,每一個命令結尾都得加;
<輸入重定向
cat > /* <<EOF 多行重定向,在輸入完後須要在結尾輸入EOF
PS2 影響多行重定向提示符的變量,也叫作就地文本
tr -dc abc 除了abc其餘全刪除,回車符也會刪除,輸入完須要ctrl+d提交
管道符只能傳標準輸出,沒法傳標準錯誤
echo {A..Z} | tr ' ' '\n' 輸出A-Z而且換行
dos2unix unix2dos 將windows文本文件和linux文本文件格式互相轉換
vim
1 set nu 顯示行號
2 set ai 自動縮進,換行時與上一行對齊
3 set paste 複製保留格式
4 set cul 顯示所在行,會有一條橫線
i insert, 在光標所在處輸入
I 在當前光標所在行的行首輸入
a append, 在光標所在處後面輸入
A 在當前光標所在行的行尾輸入
o 在當前光標所在行的下方打開一個新行
O 在當前光標所在行的上方打開一個新行
插入模式 --- ESC-----> 命令模式
命令模式 ---- : ----> 擴展命令模式
命令模式下
ZZ 保存退出
ZQ 不保存退出
擴展命令模式下
w 寫(存)磁盤文件
wq 寫入並退出
x 寫入並退出
X 加密
q 退出
q! 不存盤退出,即便更改都將丟失
r filename 讀文件內容到當前文件中
w filename 將當前文件內容寫入另外一個文件
!command 執行命令
r!command 讀入命令的輸出
地址定界
:start_pos,end_pos cmd
# 具體第#行,例如2表示第2行
#,# 從左側#表示起始行,到右側#表示結尾行
#,+# 從左側#表示的起始行,加上右側#表示的行數,範例:2,+3 表示2到5行
. 當前行
$ 最後一行
.,$-1 當前行到倒數第二行
% 全文, 至關於1,$
/pattern/ 從當前行向下查找,直到匹配pattern的第一行,即:正則表達式
/pat1/,/pat2/ 從第一次被pat1模式匹配到的行開始,一直到第一次被pat2匹配到的行結束
#,/pat/ 從指定行開始,一直找到第一個匹配patttern的行結束
/pat/,$ 向下找到第一個匹配patttern的行到整個文件的結尾的全部行
地址定界後跟一個編輯命令
d 刪除
y 複製
w file: 將範圍內的行另存至指定文件中
r file:在指定位置插入指定文件中的全部內容