Linux版本
uname -a 查看系统信息(包括kernel name、hostname、kernel release、kernel version、operating system等)
lsb_release -a 查看LSB(Linux Standard Base)和Distribution信息
cat /etc/system-release 查看Linux版本
cat /etc/redhat-releasehtml
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 java
内存信息
cat /proc/meminfonode
硬盘信息
df -h 查看硬盘信息
df -i 查看inode信息mysql
进程
ps -ef | grep java | grep -v grep 查看Java进程
kill -9 #### 杀死进程
ps -ef | grep java | grep -v grep | awk '{print $2}' | xargs kill -9 杀死全部Java进程
netstat -tlnp | grep 8080 查看端口占用linux
env 显示当前用户的环境变量
tmpwatch -afv 5d /tmp 删除tmp目录5天未使用的文件
update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0/bin/javasql
systemctl start/stop firewalld 启动/中止防火墙
firewall-cmd --state
firewall-cmd --zone=public --add-port=5000/tcpvim
visudo 编辑/etc/sudoers文件
passwd 修改用户密码
chown 修改文件/目录拥有者和组
chmod 修改文件/目录权限
authconfig 管理系统认证资源
setfacl 设置文件/目录访问权限
getfacl 获取文件/目录访问权限缓存
sytemctl
systemctl list-units 列出服务
systemctl daemon-reload reload系统配置
systemctl reload NAME... reload服务(修改服务配置后须要reload)
systemctl enable NAME... enable服务
systemctl disable NAME... disable服务
systemctl restart network 重启网络
systemctl reboot 重启
systemctl poweroff 关机
chkconfig
chkconfig --list 查看全部系统服务
chkconfig --list [name] 查看某一服务
chkconfig --add [name] 添加服务
chkconfig --del [name] 删除服务
chkconfig [name] on Enable a service in runlevels 2, 3, 4, and 5
chkconfig [name] on --level runlevels Enable a service in certain runlevels only (example: chkconfig abrtd on --level 35)
chkconfig [name] off Disable a service in runlevels 2, 3, 4, and 5bash
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
network /etc/sysconfig/network
NETWORKING=yes NETWORKING_IPV6=no HOSTNAME=xxx GATEWAY=xxx.xxx.xxx.xxx
iptables /etc/sysconfig/iptables-config
DNS /etc/resolv.conf
hosts /etc/hosts
hostname /etc/hostname
SELinux /etc/selinux/config
mount /etc/fstab
nfs /etc/exports 或在/etc/exports.d/目录下建立配置文件,内容以下:
"/exports/registry" 10.184.12.221(rw,root_squash) "/exports/metrics" *(rw,root_squash) "/exports/logging" *(rw,root_squash) "/exports/logging-es-ops" *(rw,root_squash) "/exports/etcd" *(rw,root_squash,sync,no_wdelay)
修改配置后执行exportfs -ar,nfs须要的服务有rpcbind、nfs、nfslock。
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.monthly
systemctl start/stop crond 启动/中止定时服务
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 个字段是执行的字符串
CentOS 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/localtime
yum install ntp systemctl start ntpd
服务启动后会自动从上级ntp服务器同步时间
/etc/ntp.conf为配置文件,可配置上级服务器
客户端也可不启动ntpd服务,经过crontab同步时间:
*/3 * * * * (/usr/sbin/ntpdate 10.184.13.14 && /sbin/hwclock -w) &> /dev/null
Keychain 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.
经过程序访问远程机器执行操做时,经常使用Keychain来缓存密钥。可从rpmfind下载keychain RPM进行安装。将密钥对id_rsa、id_rsa.pub放在.ssh目录下,权限设置为600,而后运行:
eval `keychain --eval --agents ssh id_rsa`
在/etc/pam.d/login中增长:
session required/lib/security/pam_limits.so
而后在/etc/security/limits.conf加入以下内容:
* hard maxlogins 1
在找不到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
安装工具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/directory
/bin/bash^M: bad interpreter: No such file or directory
$ vi :set ff=unix :wq
autoexpect - generate an Expect script from watching a session
鸟哥的Linux私房菜