format:
commond [-options] parameter1 ... help:
man/info commond
commond --help ls -al 列出当前目录下的所有文件的详细信息 ls -sh 易读形式显示文件大小 ls -rt 按时间逆序显示 ls -R 显示目录下的子目录(递归) ls -d */ 只显示目录 ls -L 列出链接文件
chmod u+w file 对所有者添加写权限 chmod +x file 对所以人添加执行权限 chmod 644 file 设置文件权限为644
chown -R tomcat:tomcat /var/lib/a 将文件的所有者和所属组改为tomcat
cd ~ 进入家目录 cd 进入家目录 cd /home/qq 或~qq 进入/home/qq/ cd ./download/a 当前目录下的download/a cd .. 上级目录 cd - 返回上个目录
pwd -P 显示当前路径,而非链接文件本身的目录名
mkdir -p a/b/c 递归创建目录 mkdir -m 711 a 创建目录a,并设定目录权限为711
cp ../a.txt . 复制上级目录的a.txt到当前目录 cp -a oms ooo/ -a同-pdr 连同属性/链接文件属性/递归复制 -f 若存在强制覆盖 -i 覆盖i前询问 -u 比要覆盖的new才会覆盖
ln -s /etc/passwd passwd2 软链接
rm -fr a/ 强制递归删除目录下的所以文件和子目录 rm -i 9* 删除9开头的文件,并询问
mv a1/ a2.txt b/ 移动目录a1(包括子目录和文件)和文件a2.txt到b目录下 -f 强制 -i 询问 -u 若已存在,并比存在的新,才更新
whereis/locate passwd 查找相关的文件
ls -lR | grep ':'| sort -k 6M -k 7n -k 8n #所以的目录和文件按时间排序
find /etc -name '*httpd*' /etc/下文件名含有httpd的文件 find /etc -newer /etc/passwd 比/etc/passwd新的文件 find / -mtime 0 24小时内有改动的 find / -mtime -4/+5 4天内/5天前的 find / -user tomcat 所有者是tomcat的 find / -type f/b,c/d/l/s 一般文件/设备文件/目录/链接文件/socket文件 find / -perm 777 权限为777的
find ./name -maxdepth 1 -perm -600 -exec ls -ld {} \; ./name目录下权限最小是600的文件和目录 find ~ -name 9* -delete 删除9开头的文件
df -hT 显示文件系统类型,易读的形式显示大小
du 当前目录和子目录的占用空间,只显示目录 du -a 文件也显示 du -sm /* 根目录下每个目录所占容量多少M
mount /dev/sda1 /mnt/qq 挂载sda1分区到/mnt/qq umount /mnt/qq 卸载 mount -t vfat/ext3/ntfs-3g/iso9660 /dev/sda1 /mnt/qq 指定分区类型 mount -o loop centos6.3_x86_64.iso /mnt/centos_dvd loop挂载
tar -zcvf etc.tar.gz /etc 打包并压缩为gzip tar -jpcvf etc.tar.bz2 /etc 保留属性打包并压缩为bzip2 tar -jtf etc.tar.bz2 查看打包内的文件名 tar -zxvf etc.tar.gz -C /tmp 解压到/tmp tar -cvf - /etc | tar -xvf - 将/etc复制到当前目录下 tar -rf a.tar 1.txt 将1.txt追加到a.tar tar -jcvf backup.tar.bz2 -X /root/*.bz2 -X /root/logs/* /etc /root
zip a.zip 1.txt -r 2/ 递归打包 zip -u a.zip 3.txt 追加或替换旧的文件 zip -m a.zip 4.txt 移动到包,不保留原文件 zip a.zip -d 1.txt 删除包里的1.txt unzip -l a.zip 列出包里的文件 unzip a.zip -d una 将包解压到una目录
echo ${PATH} PATH=$PATH:/vara:/varb export varc declare -x/+x varc
source ~/.bashrc 读入环境配置文件
cd /lib/modules/`uname -r`/kernel cd /lib/modules/$(uname -r)/kernel
alias lm='ls -l | more' alias rm='rm -i' unalias lm 取消别名 \rm 忽略别名
history 30 查看最近30条的历史命令 !66 执行第66条命令 !! 执行上一条命令 !al 执行最近以al开头的命令 !$ 上个命令的最后一个参数
ctrl+c 终止命令 ctrl+d 结束符 ctrl+z 暂停命令 ctrl+s/q 暂停/恢复屏幕输出
ctrl+a 光标移到行头 ctrl+e 移到行尾 ctrl+w 删除光标前一个单词 ctrl+u 删除整行
find /home -name .bashrc 2> /dev/null 不显示错误消息 find /home -name .bashrc > list 2> error.txt 正确和错误消息输出到不同文件 cat > catfile < ~/.bashrc 将.bashrc复制到catfile
ls -al /etc |less
ls -l / |tee -a file | more 输出到屏幕并追加到file
sync; sync; shutdown -h now 同步写入磁盘然后关机 ls /tmp/abc || mkdir /tmp/abc && touch /tmp/abc/hehe ls /tmp && echo "exist" || echo "not exist"
cat -A file 查看文件显示不可见字符 -n/-b 打印行号/只打印非空行行号 tac file 逆序查看
more file 分页查看,不能向前翻页 less file 分页查看,可进行搜索,同vim
head -n 20 file 显示前20行,默认10行 head -n -100 file 除了最后100行都显示 tail -n 20 file 显示后20行 tail -n +100 file 显示100行之后的数据 tail -f file 持续显示 tail -f ps.log | perl -pe 's/(8080-exec-[0-9]+:\) [0-9]+)/\e[1;31m$1\e[0m/g' 实时打印日志,并用红色显示关键字

cat /etc/passwd | sort -t ':' -k 3 以第三列排序 -f 忽略大小写 -b 忽略最前面的空格 -M 按月份的名字排序 -n 使用纯数字排序 -r 逆序 -u 排序列相同的只出现一次
last | cut -d ' ' -f1 | sort | uniq -c 每个人登陆次数 -i 忽略大小写
tr '[a-z]' '[A-Z]' file 将小写字符改为大写字符 cat file.dos | tr -d '\r' > file.linux 去掉dos断行符
join -t ':' -1 4 /etc/passwd -2 3 /etc/group 根据相同子段整合
paste file1 file2 直接粘贴在一起
split -b 300k mysql.log log 切割成300k名字以log开头的小文件 cat log* >> mysql.log 合并 ls -l / | split -l 100 - lsroot 按行切割
find /sbin -perm +7000 | xargs ls -l ls / | xargs -p -e'endfile' rm 删除直到endfile文件 -n 参数个数 xargs -n 10 < file 每行10个单词显示
grep -n -A 2 -B 3 "eth" file 显示eth行和后2行前3行,并显示行号 grep -v eth file 不含eth的行 grep '[^a-zA-Z0-9]pp' file pp前面不是字母和数字的行 grep '\.$' file 以点结尾的行 grep '^[^a-zA-Z]' 不是英文字母开头的行 grep '^$' file 空行 ls -l /etc |grep '^|' 链接文件 grep 'go\{2,3\}g' file 含goog或gooog的行 grep -E 'go{2,3}g' file 同上 grep 'ab\|ac' file 含ab或ac的行 grep -E 'ab|ac' file 同上 egrep 'ab|ac' file 同上 grep -e 'ab' -e 'ac' file 同上 grep ab file | grep ac 含有ab和ac的行 grep -F '*' /etc/profile 匹配固定文本 grep -rF "218.245.5.77\:20130" tomcat/webapps grep -rE "218.245.5.77\\\:20130" tomcat/webapps grep -r "218.245.5.77\\\:20130" tomcat/webapps 递归匹配218.245.5.77\:20130 -c 匹配的行数 -i 忽略大小写的不同,所以大小写视为相同 -r 递归 -l 只显示匹配的文件名 -o 只显示匹配的内容 grep -o ab file | wc -l 匹配项出现的次数
sed -i '2,$d' file 删除2到最后一行 sed '2a drink tea' 在第2行后加drink tea sed '2i drink tea' 在第2行前插入drink tea sed -n '/uuid/p' 显示含有uuid的行 sed -i '/uuid/c drink tea' 将含uuid的行替换为drink tea sed -i 's/0/1/g' 所有的0替换为1 ifconfig eth0 |grep 'inet addr'|sed 's/^.*addr://g'|sed 's/Bcast.*$//g' 提取IP sed -r 's/((\S+\s+){10})/\1\n/g' file 每行10个单词显示
awklast -n 5 | awk '{print $1 "\t" $3}' 取出账户和IP tail -f catalina.out |grep {.*} | awk 'BEGIN{RS=",|=|{|}"}{print}' json格式日志 awk -F: '{print $1,$NF}' /etc/passwd 用户的shell awk -F: 'BEGIN{printf "%10s %10s\n\n","user","shell"}!/nologin/{printf "%10s %10s\n",$1,$NF}' /etc/passwd 同上
diff -bBi file1 file2 比较2个文件,忽略多个空格/空行/字母大小写 diff -Naur old/ new/ > mysoft.patch 制作布丁文件
patch -p0 < mysoft.patch 更新补丁文件
jq . file 格式化json jq '.contributors[]|name' file jq '.contributors[]|{name}' file
sudo commond 用root权限执行命令 su 切换到root用户
crontab -e 编辑例行任务 crontab -l 查看例行任务
tar -zpcf /tmp/etc.tar.gz /etc > /tmp/log.txt 2>&1 & 后台执行任务 nohup commond & 后台执行任务,与终端无关
jobs 查看后台工作任务 ctrl+z 暂停前台任务并丢到后台 fg %n 把后台序号为n的任务,放到前台继续执行 bg %n 把后台序号为n的任务,在后台执行
kill -9 pid 强制终止 killall httpd 终止httpd相关的所有进程
top 查看进程和系统状况 top -b -n 10 > /tmp/top.txt top信息进行2次并输出到文件
netstat -tunlp | grep mysql/3306 网络监控
service --status-all 所有系统服务的状态 service httpd start/stop/restart/status 对系统服务启动/停/重起/查看状态 /etc/init.d/httpd start/stop/restart/status 同上
chkconfig --list [httpd] 查看服务是否开机启动的情况 chkconfig httpd on/off 设置httpd服务开机启动/不启动 /etc/rc.d/rc.local 将非系统服务程序加入开机启动
rpm -ivh name.rpm 安装rpm并显示详细信息和进度条 --prefix /usr/lib 指定安装路径 -Uvh 已经安装的更新,没有安装的安装 -Fvh 已经安装的更新,没有安装的不会安装 rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 导入数字证书文件 rpm -e zip 删除软件
查询已安装软件 rpm -qa 已经安装的软件 rpm -q mysql 查询mysql是否已经安装 rpm -qi mysql mysql的详细信息 rpm -ql mysql mysql的所有文件和目录 rpm -qc mysql mysql的所有配置文件 rpm -qd mysql mysql的所有帮助文件 rpm -qR mysql mysql的依赖软件 rpm -qf file 查询file属于哪个已安装软件
查询rpm包 rpm -qp[icdlR] name.rpm 查询要安装的rpm的信息
yum search raid 搜索raid yum info raid 查看软件信息 yum list pam* 列出以pam开头的软件 yum list updates 可以更新的软件列表 yum provides passwd 哪些软件含有passwd文件 yum insatll pam-devel -y 安装 yum remove pam-devel 卸载
yum grouplist 列出软件组 yum groupinfo XFCE 软件组信息 yum groupinstall XFCE 安装软件组 yum groupremove XFCE 删除软件组
ssh 192.168.1.100 ssh -p521 user@host 'mkdir -p .ssh && cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub 将本地文件内容追加到远程主机文件 cd && tar czv src | ssh user@host 'tar xz' 将$HOME/src/目录下面的所有文件,复制到远程主机的$HOME/src/目录 ssh user@host 'tar cz src' | tar xzv 将远程主机$HOME/src/目录下面的所有文件,复制到用户的当前目录。 ssh user@host 'ps ax | grep httpd' 查看远程主机是否运行进程httpd
scp -P 522 local_file user@host:/remote_folder/remote_file 本地到远程 scp user@host:/remote_folder/remote_file local_file 远程到本地 scp -r local_folder user@host:/path/remote_folder 拷贝文件夹
wget -t 5 url -O filename -o log 下载,最多重试5次,并指定保存的文件名和日志 wget -c url 断点续传 wget --ask-password url 需要验证的
curl url -o localfile 下载并保存, curl url --silent -O 不显示进度信息,并保存为原有文件名 curl -C - -O url 断点续传 curl -u user url curl -u ftpuser:ftppass -O ftp://ftp_server/public_html/ 列出文件下的目录列表 curl -ls -O ftp://ftpuser:ftppass@ftp_server/public_html/ 列出文件下的目录列表 curl -u ftpuser:ftppass -O ftp://ftp_server/public_html/xss.php 下载ftp文件 curl -u ftpuser:ftppass -T "{file1,file2}" ftp://ftp.testserver.com 上传文件 curl –u name ftp://www.xxx.com/ -X 'DELE mp3/[1-9].mp3' 删除ftp上文件名为1到9的mp3文件
|