背景質(zhì)量團隊 Linux 日常操作培訓(xùn),提升團隊整體 Linux 水平。
幫助命令及工具詳見: Linux 幫助命令及工具 用戶和用戶組用戶和組常用命令# 創(chuàng)建組$ groupadd daodaotest2# 修改組名$ groupmod -n daodaotest daodaotest2# 創(chuàng)建用戶$ useradd daodaotest# 指定參數(shù)創(chuàng)建用戶,-u uid;-g 用戶組名;-G 附加組;-d 主目錄;-c 用戶描述;-s shell $ useradd -u 550 -g daodaotest -G root -d /home/daodaotest -c 'test user' -s /bin/bash daodaotest# 修改用戶信息$ usermod -c 'update test user' daodaotest # 查看用戶和組信息$ id daodaotestuid=550(daodaotest) gid=1009(daodaotest) 組=1009(daodaotest),0(root)# 設(shè)置用戶密碼$ passwd daodaotest# 查看用戶密碼$ passwd -S daodaotest或$ chage -l daodaotest# 僅切換用戶$ su daodaotest# 切換用戶,并同時切換環(huán)境變量$ su - daodaotest# 以 root 身份安裝軟件$ sudo yum install jq -y# 查看當(dāng)前有效用戶$ whoami# 查看當(dāng)前實際用戶$ who am i# 退出$ exit# 刪除用戶,強制刪除并刪除與用戶的相關(guān)文件(home、郵件等)$ userdel -rf daodaotest# 刪除組$ groupdel daodaotest 用戶和組相關(guān)文件
文件和目錄文件類型 命令列表 文件和目錄常用命令# 長數(shù)據(jù)格式列出所有目錄,并按時間排序$ ls -lat# 長數(shù)據(jù)格式列出所有目錄,并按時間反序排序$ ls -lart# 長數(shù)據(jù)格式列出所有目錄,并按大小反序排序$ ls -larS# 進入 home 目錄$ cd ~或$ cd # 進入上一次工作目錄$ cd -# 進入上層目錄$ cd ..# 顯示當(dāng)前目錄 $ pwd# 查看軟鏈接的實際路徑$ pwd -P# 遞歸創(chuàng)建目錄$ mkdir -p daodaotest/test# 遞歸刪除目錄$ rmdir -p daodaotest/test# 創(chuàng)建文本$ touch 1.txt# 查看文件類型$ file 1.txt# 復(fù)制文件$ cp 1.txt 2.txt# 查看文件 md5$ md5sum 1.txt 2.txt# 比較文本$ diff 1.txt 2.txt# 遞歸復(fù)制目錄$ cp -r daodaotest daodaotest2# 修改文件名稱$ mv daodaotest2 daodaotest22# 移動文件或目錄$ mv 2.txt daodaotest22# 刪除文件$ rm 2.txt# 強制遞歸刪除 $ rm -rf daodaotest# 顯示樹狀目錄和文件$ tree .# 僅顯示樹狀目錄$ tree -d .# 顯示指定層級目錄和問題$ tree -L 2 .# 查看文本內(nèi)容$ cat /etc/passwd$ more /etc/passwd$ less /etc/passwd$ nl /etc/passwd# 與 cat 相反,從最后一行開始查看文本內(nèi)容$ tac /etc/passwd # 統(tǒng)計行數(shù)$ ls -l | wc -l$ cat /etc/passwd | wc -l# 查看前幾行$ head -5 /etc/passwd# 動態(tài)查看文本內(nèi)容$ tail -f /var/log/messages 顯示部分行內(nèi)容詳見:Linux 打印文本部分行(前幾行,后幾行,奇偶行,匹配行等) 查找查找常用命令
權(quán)限權(quán)限碼 常見權(quán)限表 命令列表 umask權(quán)限常用命令# 修改文件權(quán)限$ chmod 755 test.txt$ chmod +rw test.txt# 修改文件權(quán)限,遞歸(-R)修改$ chmod -R 755 /tmp/daodaotest# 修改文件屬主用戶和屬組$ chown jlh.jlh test.txt# 修改文件屬組用戶$ chgrp jlh test.txt 進程
Linux 查詢應(yīng)用進程號、端口、文件(知道其中之一查詢其他)詳見: Linux 查詢應(yīng)用進程號、端口、文件(知道其中之一查詢其他) 壓縮解壓Linux 常見的壓縮包格式:tar、gz、tar.gz、bz2、tar.bz2、zip 壓縮率一般來說: tar.bz2 > tar.gz > zip > tar tartar 是最常用的解壓縮命令。 參數(shù)說明:
# 歸檔 tar 包,不壓縮$ tar -cvf test.tar test1.log test2.log$ tar -# 僅查看包中文件,不解壓$ tar -tvf test.tar# 歸檔并壓縮為 tar.gz、tar.bz2$ tar -zcvf test.tar.gz test1.log test2.log$ tar -jcvf test.tar.bz2 test1.log test2.log# 解壓$ tar -xvf test.tar$ tar -zxvf test.tar.gz$ tar -jxvf test.tar.bz2# 解壓到指定目錄$ tar -xvf test.tar -C dir zip & unzip參數(shù)說明:
# 打包 test 目錄下的文件$ zip -r test.zip test/ # 打包 test 目錄下文件,且壓縮包不帶 test 目錄$ zip -rj test.zip test/# 指定壓縮比率,數(shù)值(1-9)越大,壓縮率越高,耗時越長$ zip -r8 test.zip test/* # 解壓 zip 包$ unzip test.zip -d dir# 查看壓縮包中的文件$ unzip -l test.zip # 查看更多信息,例如crc校驗信息等$ unzip -v test.zip # 解壓jar包$ unzip -o java.jar -d dir gzip & unzip參數(shù)說明:
# 壓縮$ gzip test1.log# 解壓$ gunzip test1.log 磁盤磁盤常用命令
json 解析命令 jq |
|