前言
記錄自己用過的linux命令,方便自己查看,持續更新~
命令
用戶
useradd <username> ## 添加用戶
passwd <username> ## 給用戶設置密碼
userdel <username> ## 刪除用戶
- 給用戶添加sudo權限
chmod u+w /etc/sudoers
vim /etc/sudoers
## 添加如下內容
username ALL=(ALL) ALL
chmod u-w /etc/sudoers
- 修改用戶默認(登錄)shell
cat /etc/shells ## 查看所有shell
vim /etc/passwd ## root用戶下修改任意用戶shell
chsh -s shell絕對路徑 ## 普通用戶修改自己的shell
- 切換用戶:(switch user)
su <username> ## 只切換身份
su - <username> ## 切換身份和shell(包含環境變量)
目錄/文件
mkdir dir ## 創建目錄
mkdir -p dir ## 若目錄的父級目錄不存在,依次創建之
touch file ## 創建文件
rm -r dir ## 遞歸刪除目錄/文件
cp [-r] 原目錄|文件 目標目錄/文件名 ## 複製目錄/文件到目標目錄
mv [-r] 原目錄|文件 目標目錄/文件名 ## 移動目錄/文件到目標目錄
- 修改目錄/文件權限
chmod 777 <dir|file> ## 設爲最高權限
## u->user;g->group;o->other;
chmod a+x <dir|file> ## 所有人添加執行權限
chmod u-x <dir|file> ## 自己去除執行權限
chmod u=rwx,g=x,o=x <dir|file>
- 修改文件屬主,屬組
chown <username>:<groupname> <dir|file>
搜索
updatedb ## 更新數據庫
locate <內容>
網絡
- 下載
wget url ## 下載文件到當前目錄,不打印文件內容
wget -O <filename> url ## 下載文件到指定目錄,並重命名之,缺省則爲原文件名
wget url -O - ## 打印文件內容,不保存到文件
curl url ## 打印文件內容,不保存到文件
curl -O <filename> url ## 下載文件到指定目錄,並重命名之,缺省則爲原文件名
服務管理
- centos7
systemctl start|stop|status|restart **d.service
systemctl enable|disable **d.service ## 開啓|關閉自啓動
systemctl is-enabled **d.service ## 查看服務是否自啓動
安裝
sh -c "$(wget url**.sh -O -)" ## 執行指定url的shell文件,一般爲install.sh