普通賬戶(userxxx)使用sudo命令設置:
chmod u+w /etc/sudoers 添加寫權限
/etc/sudoers作如下修改
在 root ALL=(ALL:ALL) ALL處添加
userxxx ALL=(ALL:ALL) ALL
chmod u-w /etc/sudoers 刪除寫權限
2. gzip怎麼把.gz文件解壓到指定目錄下?
tar xvzf foo.tar.gz -C /some/where/you/want
3 . 運維監控的幾個命令
找出使用CPU最多的前10名進程
ps -auxf | sort -nr -k 3 | head -10
找出消耗內存最多的前10名進程
ps -auxf | sort -nr -k 4 | head -10
最佔空間文件名(找1G以上的大文件)
sudo find / -type f -size +1024000k -exec du -h {} \;
4.查找系統中的大文件,並刪掉
find . -type f -size +1G -print0 | xargs -0 ls -l
cat /dev/null|sudo tee /home/changhongit/loving/cpx-gateway-setting-event-process-qa/cpx-gateway-setting-event-process-qa.log
tee bigfile:是標準輸出命令,將/dev/null 的內容(爲空)輸入到大文件bigfile中,相當於把bigfile置空,不能直接rm刪除,否者刪除了仍然不釋放,要重啓才行。
find /usr/local/backups -mtime +10 -name "*.*" -exec rm -rf {} \;
5.find 的幾種用法
1)查找文件並移動到某個目錄下
find /backup/abc/ -type f -name *.log|xargs -I '{}' mv {} ./waitmovedfiles
find /backup/ -type f -name *.log -exec mv {} ./waitmovedfiles/ \;
2) 查找並處理,反引號用法
rsync -avz `find /backup -type f -name *.tar.gz -mtime +7` [email protected]::backup/ --password-file=/etc/rsync.password
3)-exec 和xargs用法
find /backup -type f -name *.tar.gz -mtime +7 -exec ls -l {} \;
find /backup -type f -name *.tar.gz -mtime +7|xargs ls -l
6 . du查看某個文件或目錄佔用磁盤空間的大小
du -ah --max-depth=1