[b](1)文件/文件夹[/b]
[color=blue]pwd - 显示当前路径[/color]
$ pwd
[color=blue]cd - 跳到指定文件夹[/color]
$ cd /usr/local/src
$ cd ~/ ←移动到用户的home
[color=blue]ls - 显示当前文件夹下自己能看到的所有文件/文件夹一览[/color]
$ ls ←显示文件名
$ ls -l ←显示详细信息
$ ls -a ←显示隐藏文件
$ ls -t ←按做成时间降序显示
$ ls -l /usr/src/test/ ←显示指定文件夹的信息
[color=blue]mkdir - 创建文件夹[/color]
$ mkdir folder1
$ mkdir -p /usr/local/src/folder1/folder2/folder3 ←一次性创建多层次的目录
[color=blue]cp - 拷贝文件[/color]
$ cp data.dat data_new.dat ←拷贝文件
$ cp -f test.dat tmp.dat ←文件存在时覆盖文件
$ cp /usr/local/src/localtest.txt . ←拷贝到当前文件夹下
$ cp out.txt test.dat tmpdir/ ←拷贝多个文件
$ cp -r dir/ dir2/ ←拷贝文件夹
[color=blue]mv - 移动文件或修改文件名[/color]
$ mv -f test.txt /usr/local/src/test.txt ←移动文件
$ mv localtest.txt rename_local.txt ←修改文件名
[color=blue]rm - 删除文件/文件夹[/color]
$ rm rename_local.txt ←删除文件
$ rm -r tmpdir/ ←删除文件夹
$ rm -rf tmpdir/ ←不用确认强制删除
[color=blue]touch - 生成一个0byte空文件[/color]
$ touch test.txt
[color=blue]vi - 编辑文本文件[/color]
$ vi test.txt
i-插入模式、dd-删除整行、:wq-保存后结束、:q!-不保存退出、/-检索
[color=blue]chmod - 修改文件/文件夹的访问权限[/color]
$ chmod 755 file.dat ←所有者以外不可写
$ chmod -R 777 test ←递归修改文件权限
$ chmod +x script.sh ←追加可执行权限
[quote]文件权限:Unix系统通过三位数字设置权限比如755,分别是所有者/组/其他人。
每位数字是读r(4)/写w(2)/执行x(1)的和。比如7就是rwx
755的意思就是所有者读写执行都可,组/其他人只可以读和执行[/quote]
[color=blue]chown - 修改文件的所有者[/color]
$ chown user1 test.txt ←修改用户为user1
$ chown -R user1 topic/
$ chown :group1 file2 ←修改用户组为group1
$ chown user1:group1 test.txt
[color=blue]cat - 显示文件内容[/color]
$ cat test.txt
$ cat -n file1 ←显示行号
$ cat /etc/fstab | grep sys
[color=blue]head - 显示文件的开头内容[/color]
$ head /etc/passwd ←默认输出前10行
$ head -5 /etc/passwd ←指定输出行数
[color=blue]tail - 显示文件的末尾内容[/color]
$ tail /etc/passwd ←默认输出最后10行
$ tail -5 /etc/passwd ←指定输出行数
$ tail -f access.log ←监视文件的写入情况
[color=blue]find - 查找文件[/color]
$ find . -maxdepth 1 -type f -name "*.txt"
[color=blue]ln - 创建文件/文件夹链接[/color]
$ ln -s /usr/local/bin bin
[b](2)用户/用户组[/b]
[color=blue]id - 确认用户名/ID/用户组[/color]
$ id ←显示自己的ID
$ id postgres
$ id -gn postgres
[color=blue]useradd - 添加用户[/color]
$ useradd usr01
$ useradd user1 -d /home/user1 -G nobody
$ useradd -s /sbin/nologin ngnix ←做成不能登录的用户
$ useradd -M shilpi ←做成没有Home文件夹的用户
[color=blue]userdel - 删除用户[/color]
$ userdel usr01 ←删除usr01
$ userdel -r usr01 ←同时删除Home文件夹
[color=blue]passwd - 修改用户密码[/color]
$ passwd ←修改自己的密码
$ passwd usr01 ←修改usr01的密码(# echo redhat | passwd --stdin user1)
$ passwd -d usr01 ←删除用户密码
[color=blue]su - 切换用户[/color]
$ su - ←切换到root
$ su - postgres
[color=blue]sudo - 用其他用户的权限来运行程序[/color]
$ sudo npm install -g cordova
[b](3)进程[/b]
[color=blue]ps - 显示正在执行的进程[/color]
$ ps aux
$ ps aux | grep sshd
$ ps -ef | more ←查看当前运行的进程
[color=blue]kill - 终了进程[/color]
$ kill 12705
$ kill -9 12705 ←强制终了
[color=blue]killall - 以命令为单位结束进程[/color]
$ killall httpd
[color=blue]crontab - 定时执行[/color]
$ crontab -e ←修改crontab文件
$ crontab -l ←显示crontab文件
[b](4)网络[/b]
[color=blue]wget - 下载文件[/color]
$ wget http://www.xxx.com/file.tar.gz
$ wget -r ftp://ftp.xxx.com/dir/ ←下载dir文件夹下所有文件
$ wget -O newfile.zip http://www.xxx.com/file.tar.gz ←下载文件并另存
[color=blue]ping - 通过往网络上的其他计算机发送数据包确认网络连接[/color]
$ ping wwww.baidu.com
$ ping -c 3 wwww.baidu.com ←发送3次数据包
[color=blue]ifconfig - 配置网络设备(网络接口卡)[/color]
$ ifconfig
[color=blue]netstat - 显示网络相关信息[/color]
$ netstat -ant
$ netstat -lnp | grep 8080 ←查看端口是被哪个进程占用
[color=blue]route - 显示路由表[/color]
$ route
[color=blue]mount - 挂载Windows网络共享[/color]
$ mount -t cifs //server/share -o username=user,password=P4ssw0rd /mnt/windowsfs
[b](5)压缩/解压[/b]
[color=blue]tar - 压缩与解压缩[/color]
$ tar zcvf filename.tar.gz file1 file2 ←压缩
$ tar zcvf filename.tar.gz /path/to/folder
$ tar zxvf filename.tar.gz ←解压缩
$ tar ztvf archive_name.tar ←查看压缩文件里的内容
[color=blue]zip/unzip - 压缩与解压缩[/color]
$ zip filename.zip file1 file2 ←压缩
$ zip -r backup.zip /root/backup ←压缩文件夹
$ unzip filename.zip ←解压缩
$ unzip filename.zip -d folder1 ←解压缩到指定目录
$ unzip -l filename.zip ←查看文档内容(不解压缩)
[b](6)包管理[/b]
[color=blue]rpm - 软件包管理[/color]
$ rpm -q mysql ←查找包
$ rpm -qa | grep mysql
$ rpm -qi mysql ←显示包的详细信息
$ rpm -qi mysql | awk '/(Version|Release)/{ print $1,":",$3 }'
$ rpm -ivh /usr/local/src/mysql.rpm ←安装
$ rpm -Uvh /usr/local/src/mysql.rpm ←更新
$ rpm -e mysql ←卸载
$ rpm -qpR xxx.rpm ←检查依赖关系
[color=blue]yum - 自动的RPM包管理[/color]
$ yum list mysql ←查找包
$ yum search mysql
$ yum info mysql ←显示包的详细信息
$ yum install mysql ←安装
$ yum update mysql ←更新
$ yum remove mysql ←卸载
[b](7)系统管理[/b]
[color=blue]history - 显示历史指令记录[/color]
$ history
$ history -c ←清除记录
[color=blue]chkconfig - 服务自启动设置[/color]
$ chkconfig --add myserv
$ chkconfig --del myserv
$ chkconfig --list ←显示所有服务
NetworkManager 0:off 1:off 2:off 3:off 4:off 5:off 6:off
$ chkconfig --list | grep myserv ←检查某个服务的状态
$ chkconfig --list | grep 5:on ←检查某个服务是否On/Off
$ chkconfig httpd on ←设置服务自启动
$ chkconfig --level 35 httpd on
$ chkconfig httpd off ←停止服务自启动
$ chkconfig --level 35 httpd off
[color=blue]service - 启动或停止系统服务[/color]
$ service httpd start
$ /etc/init.d/httpd start
$ service httpd stop
$ /etc/init.d/httpd stop
[color=blue]date - 时钟查看和设置[/color]
$ date ←显示时间
$ date '+%Y-%m-%d' ←指定格式显示时间
$ date MMDDhhmmYYYY ←设置时间
$ date -s "02/08 14:11 2014" ←设置时间
[color=blue]uptime - 显示系统运行情况[/color]
$ uptime
[color=blue]which - 查看可执行文件的位置[/color]
$ which java
[color=blue]clear - 清除屏幕信息[/color]
$ clear
[color=blue]shutdown - 关闭系统[/color]
$ shutdown
$ shutdown -r now ←重启
$ shutdown -h now ←关闭
[color=blue]reboot - 重启机器[/color]
$ reboot
[color=blue]man - 显示命令的帮助信息[/color]
$ man ls
[color=blue]df - 显示磁盘使用情况[/color]
$ df -h
[color=blue]free - 显示内存信息[/color]
$ free -m
[b](8)其他[/b]
diff、grep、sed、awk
[b]随机生成密码[/b]
$ yum install expect
$ mkpasswd
as1xVY)8p ←默认是9位英数字符号
$ mkpasswd -l 16
l2dohtpM2;cbyqTw ←指定总长度(-l)
$ mkpasswd -l 16 -d 5
7yLVx|5w74flkgq1 ←数字个数(-d)
$ mkpasswd -l 16 -c 8 -C 5
CUHdh}t6ckLRtd1q ←小写字母个数(-c)と和大写字母个数(-C)
$ mkpasswd -l 16 -c 8 -C 5 -s 0
jozPfORhAV00tmsj ←特殊字符个数(-s)
[b]快捷键[/b]
TAB:自动补全
CTRL+A:光标移到开头,CTRL+E:光标移到结尾
CTRL+K:删除光标后所有字符,CTRL+U:删除光标前所有字符
CTRL+L:清屏相当于clear命令
CTRL+C:中断当前运行命令,Ctrl+Z:挂起当前运行命令(fg/bg/jobs/&/ctrl+z)
[b]命令中常用的几个符号:[/b]
[color=blue]* - 通配符,任意多个任意字符[/color]
$ ls
file.txt file1 file2 file3 hello.c sys.log
$ rm file*
$ ls
hello.c sys.log
[color=blue]? - 通配符,任意一个字符[/color]
$ ls
file01 file02 file03 file04 file11 file12 file13 file14
$ rm file?3
$ ls
file01 file02 file04 file11 file12 file14
[color=blue]; - 多条命令顺序执行[/color]
$ date ; sleep 2m ; date
2014年 10月 6日 月曜日 14:33:06 CST
2014年 10月 6日 月曜日 14:35:06 CST
・command1 & command2 ←command1执行完后执行command2
・command1 && command2 ←command1执行结果返回0后执行command2
・command1 || command2 ←command1执行结果返回0以外执行command2
・command1 & ←后台执行command1
・nohup command1 & ←不挂断地运行命令
[color=blue]| - 组合执行多条命令[/color]
$ ps aux | grep apache
[color=blue]> - 保存命令执行结果到文件[/color]
$ ls -a > ff.txt
$ echo World! >> file2
・command1 > tmpfile ←执行结果写入文件
・command1 >> tmpfile ←执行结果追加到文件
・command1 >& tmpfile ←执行结果和错误信息写入文件
・command1 2> tmpfile ←错误信息写入文件
・command1 2>> tmpfile ←错误信息追加到文件