普通账户(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` rsync_backup@10.0.0.41::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