基本的文件目录操作
ls命令 #用于查看文件以及目录(list)
shell
$ ls #查看当前目录下文件
auto CHANGES CHANGES.ru conf configure contrib html
LICENSE Makefile man objs README src andyx.net的配置文件.txt
SHELL
3 lines|206 chars
auto
$ ls conf #查看conf目录下文件
fastcgi.conf fastcgi_params koi-utf koi-win
mime.types nginx.conf scgi_params uwsgi_params win-utf
AUTO
3 lines|159 chars
auto
$ ls -a #显示所有文件(包含以点(.)开头的隐藏文件,)
. auto CHANGES CHANGES.ru conf configure contrib
.. html LICENSE Makefile man objs README src 上次配置文件.txt
AUTO
3 lines|228 chars
auto
$ ls -l #以长格式显示文件的详细信息,可以查看文件权限,所属用户,日期等
total 788
AUTO
3 lines|120 chars
pwd命令 #用于打印当前目录(print work directory)
auto
$ pwd #显示当前绝对路径位置
/root/project/nginx-1.10.2-sourcecode
AUTO
2 lines|78 chars
cd命令 #用于进入目录(Change Directory)
auto
$ cd ../ #进入上层目录
$ cd ../../ #进入上上层目录
$ cd ../../../ #进入上上上层目录
$ cd ~ #进入当前用户的家目录
$ cd - #返回上一次的目录
$ cd /root/nginx/conf #进入指定/root/nginx/conf目录
AUTO
6 lines|322 chars
mkdir命令 #用于创建目录(Make Directory)
auto
$ mkdir andyx #创建一个andyx目录
$ mkdir -p backup/sql #参数-p递归创建目录(如果目录不存在则创建完整路径的目录)
AUTO
2 lines|174 chars
rm命令 #用于删除目录或文档(Remove)
auto
$ rm init.sh #删除init.sh文件(不加-r参数不能删除目录)
$ rm -r conf #递归删除文件或目录(可以删除文件夹,系统会询问你是否删除,输入y表示确认,然后回车即可)
$ rm -rf backup #不会询问(-f参数慎用),直接递归删除文件或目录
AUTO
3 lines|332 chars
mv命令 #用于移动/重命名目录或者文档(Move)
auto
$ mv linux andyxnet #将linux文件或者目录重命名为andyxnet
$ mv vhost.sh conf/ #将vhost.sh移动到conf目录下
AUTO
2 lines|151 chars
cp命令 #用于复制目录或者文档(Copy)
auto
$ cp linux andyxnet #将linux文件复制一份命名为andyxnet(注意区别:如果存在andyxnet目录,则将linux文件复制到andyxnet目录下,文件名不变为linux)
$ cp -r andyxnet/ conf/ #将andyxnet目录(包含里面文件)复制到conf目录下
AUTO
2 lines|311 chars
wget命令 #用于从互联网下载文档(Web Get)
auto
$ wget https://andyx.net/andyximg/logo-footer.png #下载文件,可加参数-c断点续传;-T 设置超时时间后面跟秒
$ wget https://andyx.net/andyximg/logo-footer.png -O /root/andyx.png #下载文件,参数-O大写O意为另存为
AUTO
2 lines|254 chars
cat命令 与 grep命令 #cat用于查看文档内容,grep命令用于筛选文档关键字
auto
$ cat /etc/hosts #显示hosts文档的所有内容
$ grep '关键字' /etc/hosts #在文档/etc/hosts中搜索包含'关键字'的关键字
$ cat /etc/hosts | grep andyx.net #与上一行命令效果相同,显示hosts文件中过滤包含andyx.net字符的行
AUTO
3 lines|333 chars
awk命令 #强大的文本处理引擎
取一个公网ip地址
auto
ifconfig | grep 'inet addr:' | cut -d: -f2 | grep -v ^10. | grep -v ^192.168 | grep -v ^172. | grep -v ^127. | awk '{print $1}' | awk '{print;exit}'
AUTO
1 lines|181 chars
常用系统资源管理命令
df命令 #常用于查看系统磁盘空间状态(Disk Free)
auto
$ df -h #通常与参数-h使用,方便阅读(Human-readable)
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 48G 6.9G 38G 16% /
devtmpfs 486M 0 486M 0% /dev
tmpfs 496M 0 496M 0% /dev/shm
tmpfs 496M 13M 483M 3% /run
tmpfs 496M 0 496M 0% /sys/fs/cgroup
tmpfs 100M 0 100M 0% /run/user/0
AUTO
8 lines|411 chars
top命令 #动态的查看进程消耗资源(cpu、内存,作用相当于windows进程管理器)
auto
$ top
Threads: 174 total, 1 running, 173 sleeping, 0 stopped, 0 zombie
%Cpu(s): 15.7 us, 2.7 sy, 0.0 ni, 78.6 id, 3.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1014520 total, 74664 free, 635088 used, 304768 buff/cache
KiB Swap: 2097148 total, 2050812 free, 46336 used. 177184 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
32054 apache 20 0 472392 53192 8096 S 10.7 5.2 0:08.65 php-fpm
32051 apache 20 0 468248 48736 7688 S 7.0 4.8 0:08.37 php-fpm
9 root 20 0 0 0 0 S 0.3 0.0 2:12.20 rcu_sched
32015 nginx 20 0 355648 35800 2432 S 0.3 3.5 0:01.58 nginx
1 root 20 0 207432 2752 1548 S 0.0 0.3 1:25.29 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:03.59 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 lru-add-drain
11 root rt 0 0 0 0 S 0.0 0.0 0:04.17 watchdog/0
**小技巧:使用快捷键Ctrl+s可以冻结屏幕,使用快捷键Ctrl+q可以解冻屏幕
AUTO
22 lines|2,536 chars
更高级的进程管理工具请参见《htop进程管理器:比top更好用的Linux进程管理监控工具》
free命令 # 查看内存、swap使用情况,当然top也可以看
auto
$ free -h #通常与-h参数使用,便于阅读(Human-readable)
total used free shared buff/cache available
Mem: 990M 623M 68M 9.3M 298M 169M
Swap: 2.0G 45M 2.0G
AUTO
4 lines|282 chars
常用压缩与解压缩命令
tar命令 #用于打包/压缩/解压文档或目录(tape archive)
auto
$ tar -czf andyx.net.tar.gz /root/andyx.net #tar打包压缩(不跟压缩参数默认仅打包不压缩)
$ tar -xzf andyx.net.tar.gz #解压tar包到当前目录
AUTO
2 lines|247 chars
zip & unzip #用于打包/压缩/解压zip文档
auto
$ zip -r andyx.net.zip /root/andyx.net #zip压缩当前andyx.net目录为andyx.net.zip
$ unzip -q andyx.net.zip #参数-q是安静的zip解压
AUTO
2 lines|223 chars
MySQL数据库简单操作命令
mysql命令 与 mysqldump命令 #mysql命令用于终端管理数据库,mysqldump用于备份数据库
auto
$ mysqldump -uroot -pmysqlpwd -B andyx > andyx_db.sql
# root为用户名,mysqlpwd为密码,andyx数据库名字,将数据库andyx导出备份andyx_db.sql 文件
$ mysql -uroot -pmysqlpwd #命令行进入MySQL管理(参数连用不能有空格)
Enter password: mysqlpwd
$ mysql -uroot -pmysqlpwd < andyx_wp.sql #从备份数据库andyx_wp.sql导入数据,通常用做数据库恢复
AUTO
7 lines|433 chars
(未完待续,以后慢慢补充。。。)
