Linux版本
uname -a                       查看系统内核信息
lsb_release -a                查看LSB(Linux Standard Base)和Distribution信息
cat /etc/issue                  查看Linux版本
cat /etc/system-release
cat /etc/redhat-release
env                                  显示当前用户的环境变量
CPU信息
lscpu - display information about the CPU architecture
cat /proc/cpuinfo
vmstat - reports information about processes, memory, paging, block IO, traps, disks and cpu activity
top 
内存信息
cat /proc/meminfo
进程
ps -ef | grep java             查看Java进程
kill -9 ####                       杀死进程
netstat -tlnp | grep 8080  查看端口占用
fuser                                Show which processes use the named files, sockets, or filesystems
fuser -k -n tcp 80             杀死占用80端口的进程
tmpwatch -afv 5d /tmp      删除tmp目录5天未使用的文件
update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0/bin/java
CentOS/RHEL 7:
# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpmCentOS/RHEL 6:
# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm也可以到以下网站查找安装包:
Package search
RPM Search
RPM Find
yum install -y gcc gcc-c++   安装编译器
yum install -y libstdc++ libstdc++-devel
yum groupinstall “Development Tools”  安装Development Tools
(如出现there is no installed groups file错误,请附加参数--setopt=group_package_types=mandatory,default,optional)
yum groupinfo "Development Tools"      查看组Development Tools的内容
yum list installed                                    列出已安装的包
systemctl start firewalld
firewall-cmd --state
firewall-cmd --zone=public --add-port=5000/tcp
visudo 编辑/etc/sudoers文件
pwd                       显示当前工作路径
cd -                       返回上次所在的目录
mkdir -p /dir1/dir2  创建一个目录树
cp -a dir1 dir2        复制一个目录
true > test.txt              清空文件的内容
find
与时间有关的选项:-atime, -ctime 与 -mtime,以 -mtime 说明
-mtime  n  :n 为数字,意义为在 n 天之前的『一天之内』修改过内容的文件
-mtime +n :列出在 n 天之前(不含 n 天本身)修改过内容的文件
-mtime -n :列出在 n 天之内(含 n 天本身)修改过内容的文件
-newer file :file 为一个存在的文件,列出比 file 还要新的文件
CentOS 7 支持 -newerXY 参数,可直接指定时间,具体请查阅find帮助文档。
find AIRLINE -name *0813* -type f | xargs du -ck  查找名字包含0813的文件并统计总大小,以Kb为单位
find执行action
find / -name \*.rpm -exec chmod 755 ‘{}‘ \;   从根目录搜索以 ‘.rpm‘ 结尾的文件并定义其权限,其中{}位置放置find执行结果,\; 为action结束标志
find -type d -exec mkdir -p /new_folder/{} \;   复制当前目录下的目录结构
find AIRLINE -wholename **/attach/*0813* -type f -exec rm -f {} \;  根据wholename查找文件并删除which [-a] command    寻找可执行文件(-a :将所有PATH 目录中可以找到的命令均列出,而不止第一个被找到的命令名称)
whereis [-bmsu] filename/folder   从一些特定的目录查找
locate [-ir] keyword   依据/var/lib/mlocate资料库的记载查找文件(执行updatedb更新资料库)
SSH          /etc/ssh/sshd_config
网络参数   /etc/sysconfig/network-scripts/ifcfg-eth0
DNS          /etc/resolv.conf
hosts         /etc/hosts
hostname  /etc/hostname
network     /etc/sysconfig/network
NETWORKING=yes  
NETWORKING_IPV6=no  
HOSTNAME=xxx  
GATEWAY=xxx.xxx.xxx.xxx  iptables /etc/sysconfig/iptables
mount /etc/fstab
user                    /etc/passwd
user password    /etc/shadow
group                  /etc/group
group password  /etc/gshadow
/etc/cron.daily
/etc/cron.hourly
/etc/cron.monthly
/etc/cron.weekly
/etc/anacrontab
#period in days   delay in minutes   job-identifier          command
1                          5                          cron.daily              nice run-parts /etc/cron.daily
7                         25                         cron.weekly           nice run-parts /etc/cron.weekly
@monthly           45                         cron.monthly         nice run-parts /etc/cron.monthlyservice crond start/stop 启动/停止定时服务
crontab 编辑定时任务
crontab [-u user] [ -e | -l | -r ]
-e     edit user‘s crontab
-l      list user‘s crontab
-r     delete user‘s crontab
-ir     prompt before deleting user‘s crontab
crontab [-u user] file
以file做为crontab的任务列表文件并载入
crontab file的格式:
crontab 文件中的行由 6 个字段组成,不同字段间用空格或 tab 键分隔。
前 5 个字段指定命令要运行的时间
分钟 (0-59)
小时 (0-23)
日期 (1-31)
月份 (1-12)
星期几(0-6,其中 0 代表星期日)
第 6 个字段是执行的字符串
First look if you have any uncomplete transactions with: yum-complete-transaction
If this doesn‘t help then take a look at the package-cleanup tool which is part of the yum-utils package.
package-cleanup --dupes lists duplicate packages
package-cleanup --cleandupes removes duplicate packages
在找不到so文件时(cannot open shared object file),使用ldconfig来配置共享。配置文件位于/etc/ld.so.conf.d目录下。
比如,安装了mysql,so文件位于/usr/lib64/mysql下,可在/etc/ld.so.conf.d目录创建mysql.conf文件,其中内容为 /usr/lib64/mysql,然后运行:
$ sudo ldconfig -v
yum install ntp
service ntpd start服务启动后会自动从上级ntp服务器同步时间
/etc/ntp.conf为配置文件,可配置上级服务器
客户端也可不启动ntpd服务,通过crontab同步时间:
*/3 * * * *     (/usr/sbin/ntpdate 10.184.13.14 && /sbin/hwclock -w) &> /dev/nullCentOS 7
$ timedatectl
Local time: Tue 2016-11-22 06:07:42 UTC  
Universal time: Tue 2016-11-22 06:07:42 UTC
RTC time: Tue 2016-11-22 06:07:42  
Time zone: UTC (UTC, +0000)  
NTP enabled: yes  
NTP synchronized: no  
RTC in local TZ: no  
DST active: n/a  timedatectl list-timezones  查看时区
timedatectl set-timezone Asia/Shanghai   设置时区
timedatectl set-timezone UTC 
CentOS 6
# vim /etc/sysconfig/clock
ZONE="UTC"
cp /usr/share/zoneinfo/UTC /etc/localtimeKeychain helps you to manage SSH and GPG keys in a convenient and secure manner. It acts as a frontend to ssh-agent and ssh-add, but allows you to easily have one long running ssh-agent process per system, rather than the norm of one ssh-agent per login session.
This dramatically reduces the number of times you need to enter your passphrase. With keychain, you only need to enter a passphrase once every time your local machine is rebooted. Keychain also makes it easy for remote cron jobs to securely "hook in" to a long-running ssh-agent process, allowing your scripts to take advantage of key-based logins.
在/etc/pam.d/login中增加:
session required/lib/security/pam_limits.so然后在/etc/security/limits.conf加入如下内容:
* hard maxlogins 1安装工具extundelete
yum install e2fsprogs e2fslibs-dev或下载extundelete-x.x.x.tar.bz2,运行tar -jxvf extundelete-x.x.x.tar.bz2解压后安装。
恢复某一目录,执行:
extundelete partition_name --restore-directory path/of/directoryautoexpect - generate an Expect script from watching a session
鸟哥的Linux私房菜
Top 5 Yum Repositories for CentOS/RHEL 7/6/5
原文:http://blog.51cto.com/7308310/2163076