博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux下一些常用命令和访问目录
阅读量:4549 次
发布时间:2019-06-08

本文共 10119 字,大约阅读时间需要 33 分钟。

1. 目录

      ls   列出目录文件名
      ll    列出所有目录文件的访问权限等相关信息,包括 .   ..
      ls -a  列出所有目录文件名,包括 .   ..
    ls -l  列出目录文件的访问权限等相关信息
    ls -R  递归显示子目录结构
    ls -ld  后加目录名,显示目录和链接信息
    cd ~
    cd /
    cd ../../
    cd

2. 手动设置IP

  一、dns设置   sudo vim /etc/resolv.conf  修改完之后保存,然后执行sudo resolvconf -u
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTENnameserver 192.168.1.1nameserver 114.114.114.114nameserver 8.8.8.8

    二、ip设置

     sudo vim /etc/network/interfaces

# This file describes the network interfaces available on your system# and how to activate them. For more information, see interfaces(5).# The loopback network interfaceauto loiface lo inet loopback# The primary network interfaceauto eth0#iface eth0 inet dhcpiface eth0 inet staticaddress 192.168.1.69gateway 192.168.1.1netmask 255.255.255.0

3. 查看是否启动应用

ps -ef|grep nginxroot       939     1  0 09:42 ?        00:00:00 nginx: master process ./sbin/nginxwww-data   940   939  0 09:42 ?        00:00:00 nginx: worker processxiao      1797  1672  0 18:10 pts/3    00:00:00 grep --color=auto nginx
xiao@ubuntu:~$ ps -ef|grep phproot       889     1  0 09:42 ?        00:00:01 php-fpm: master process (/data/service/php53/etc/php-fpm.conf)nobody     890   889  0 09:42 ?        00:00:00 php-fpm: pool wwwnobody     891   889  0 09:42 ?        00:00:00 php-fpm: pool wwwxiao      1799  1672  0 18:11 pts/3    00:00:00 grep --color=auto php

4. 重启和关闭nginx

平滑启动    sudo /data/service/nginx/sbin/nginx -s reload    关闭        sudo /data/service/nginx/sbin/nginx -s stop

5. 启动php

cd /data/service/php53/sbin/php-fpm
php 杀死主进程 kill 889

 

6. 修改挂载命令

sudo vim /etc/rc.local/bin/sh -c 'cd /data/service/php53;./sbin/php-fpm;'/bin/sh -c 'mount -t cifs -o username=ubuntu,password=12345,gid=65534,uid=65534 //192.168.1.25/PAPA /data/www-data/www'/bin/sh -c 'mount -t cifs -o username=ubuntu,password=12345,gid=65534,uid=65534 //192.168.1.25/PAPA /home/xiao/work'# start nginx/bin/sh -c 'cd /data/service/nginx;./sbin/nginx;'#/bin/sh -c 'cd /data/service/mysql; ./bin/mysqld_safe --user=mysql &'/bin/sh -c 'cd /usr/local/mysql; ./bin/mysqld_safe --user=mysql &'exit 0

7. nginx文件配置

Nginx安装及配置文件nginx.conf详解: 

cd /data/service/nginx/conf/vhost/ sudo vim aa.conf server {        listen       443;        server_name app.chenlu.cn;        root /data/www-data/www/chenlu_api/app3;       #autoindex on;        ssl on;        ssl_certificate      /home/xiao/papa.crt;        ssl_certificate_key  /home/xiao/papa.key;        ssl_session_timeout  5m;        ssl_protocols  SSLv2 SSLv3 TLSv1;        ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;        ssl_prefer_server_ciphers   on;        #charset utf-8;        #access_log  logs/host.access.log  main;        location / {            index  index.html index.htm index.php;        }        #error_page  404              /404.html;        # redirect server error pages to the static page /50x.html        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }location ~ \.php$ {            fastcgi_pass   127.0.0.1:9000;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;            fastcgi_param  ENV local;            include        fastcgi_params;        }        # deny access to .htaccess files, if Apache's document root        # concurs with nginx's one        #        #location ~ /\.ht {
# deny all; #a} set $rule_allow 0; if ($request_filename !~ "^.*.(gif|jpg|jpeg|png|ico|swf|css|js|txt|ttf|TTF)$"){ set $rule_allow 2$rule_allow; } if ($rule_allow = "20"){ rewrite ^/(.*) /index.php?$1 last; } }

 

server {        listen       80;        server_name admin.api.esut.cn;        root /home/wwwroot/default/PaPaWebAdmin;        autoindex on;        location / {            index  index.html index.htm index.php;        }        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }        location ~ \.php$ {            fastcgi_pass  unix:/tmp/php-cgi.sock;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;            #fastcgi_param  ENV local;            include        fastcgi_params;            include fastcgi.conf;            include pathinfo.conf;        }        set $rule_allow 0;        if ($request_filename !~ "^.*.(gif|jpg|jpeg|png|ico|swf|xml|css|js|txt|ttf|TTF)$"){                set $rule_allow 2$rule_allow;        }        if ($rule_allow = "20"){                rewrite ^/(.*) /index.php?$1 last;        }}

 

server {        #listen 80 default        listen 443 ssl;        server_name pub.api.esut.cn;        root /home/wwwroot/default/PaPaPublicWebService;        ssl_certificate /usr/local/nginx/conf/server.crt;        ssl_certificate_key /usr/local/nginx/conf/server.key;        #charset utf-8;        #access_log  logs/host.access.log  main;        location / {            index  index.html index.htm index.php;        }        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }        location ~ \.php$ {            fastcgi_pass  unix:/tmp/php-cgi.sock;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;            #fastcgi_param  ENV local;            include        fastcgi_params;            include fastcgi.conf;            include pathinfo.conf;        }        set $rule_allow 0;        if ($request_filename !~ "^.*.(gif|jpg|jpeg|png|ico|swf|css|js|txt|ttf|TTF)$"){                set $rule_allow 2$rule_allow;        }        if ($rule_allow = "20"){                rewrite ^/(.*) /index.php?$1 last;        }}

 

server {        #listen 80 default        listen 443 ssl;        server_name app2.api.esut.cn;        root /home/wwwroot/default/PaPaWebAPP2;        ssl_certificate /usr/local/nginx/conf/server.crt;        ssl_certificate_key /usr/local/nginx/conf/server.key;        #charset utf-8;        #access_log  logs/host.access.log  main;        location / {            index  index.html index.htm index.php;        }        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }        location ~ \.php$ {            fastcgi_pass  unix:/tmp/php-cgi.sock;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;            #fastcgi_param  ENV local;            include        fastcgi_params;            include fastcgi.conf;            include pathinfo.conf;        }        set $rule_allow 0;        if ($request_filename !~ "^.*.(gif|jpg|jpeg|png|ico|swf|css|js|txt|ttf|TTF)$"){                set $rule_allow 2$rule_allow;        }        if ($rule_allow = "20"){                rewrite ^/(.*) /index.php?$1 last;        }}

 8.文档操作

跳到文档结尾开头 方法是按shift+g,另外,到文件开头是gg。

 只查看末尾几行 tail -n 100 20160202.log

9.查找文件

sudo find / -type f -name .bash_history

 前一次登陆以前所运行过的命令在你的家目录内的 .bash_history ! 不过,需要留意的是,~/.bash_history 记录的是前一次登陆以前所运行过的命令, 而至于这一次登陆所运行的命令都被缓存在内存中,当你成功的注销系统后,该命令记忆才会记录到 .bash_history 当中!

10.linux系统中如何查看日志 (常用命令)

常用日志文件如下:    access-log   纪录HTTP/web的传输     acct/pacct   纪录用户命令     aculog     纪录MODEM的活动     btmp      纪录失败的纪录     lastlog     纪录最近几次成功登录的事件和最后一次不成功的登录     messages    从syslog中记录信息(有的链接到syslog文件)     sudolog     纪录使用sudo发出的命令     sulog      纪录使用su命令的使用     syslog     从syslog中记录信息(通常链接到messages文件)     utmp      纪录当前登录的每个用户     wtmp      一个用户每次登录进入和退出时间的永久纪录     xferlog     纪录FTP会话

 但是~/.bash_history里面是没有时间的记录的,可以用下面的脚本来记录时间。

通过在/etc/profile里面加入以下代码就可以实现:

PS1="`whoami`@`hostname`:"'[$PWD]'  history  www.2cto.com    USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'` #print $NF取最后一个域的字段  if [ "$USER_IP" = "" ]  then  USER_IP=`hostname`  fi  if [ ! -d /tmp/dbasky ]  then  mkdir /tmp/dbasky  chmod 777 /tmp/dbasky  fi  if [ ! -d /tmp/dbasky/${LOGNAME} ]  then  mkdir /tmp/dbasky/${LOGNAME}  chmod 300 /tmp/dbasky/${LOGNAME}  fi  export HISTSIZE=4096  DT=`date " %Y%m%d_%H%M%S"`  export HISTFILE="/tmp/dbasky/${LOGNAME}/${USER_IP} dbasky.$DT"  chmod 600 /tmp/dbasky/${LOGNAME}/*dbasky* 2>/dev/null 其实通过上面的代码不能看出来,在系统的/tmp新建个dbasky目录,在目录中记录了所有的登陆过系统的用户和IP地址

history命令只显示所执行的历史命令,

编辑/etc/bashrc文件,加入如下三行: HISTFILESIZE=2000HISTSIZE=2000HISTTIMEFORMAT=”%Y%m%d-%H%M%S: ”export HISTTIMEFORMAT 保存后退出,关闭当前shell,并重新登录这个时候,在~/.bash_History文件中,就有记录命令执行的时间了

 

  日 志 文 件 说 明

/var/log/message 系统启动后的信息和错误日志,是Red Hat Linux中最常用的日志之一      /var/log/secure 与安全相关的日志信息      /var/log/maillog 与邮件相关的日志信息      /var/log/cron 与定时任务相关的日志信息      /var/log/spooler 与UUCP和news设备相关的日志信息      /var/log/boot.log 守护进程启动和停止相关的日志消息

   系统:

# uname -a # 查看内核/操作系统/CPU信息      # cat /etc/issue      # cat /etc/redhat-release # 查看操作系统版本      # cat /proc/cpuinfo # 查看CPU信息      # hostname # 查看计算机名      # lspci -tv # 列出所有PCI设备      # lsusb -tv # 列出所有USB设备      # lsmod # 列出加载的内核模块      # env # 查看环境变量

   资源:

# free -m # 查看内存使用量和交换区使用量      # df -h # 查看各分区使用情况      # du -sh 
<目录名>
# 查看指定目录的大小 # grep MemTotal /proc/meminfo # 查看内存总量 # grep MemFree /proc/meminfo # 查看空闲内存量 # uptime # 查看系统运行时间、用户数、负载 # cat /proc/loadavg # 查看系统负载

   磁盘和分区:

# mount | column -t # 查看挂接的分区状态      # fdisk -l # 查看所有分区      # swapon -s # 查看所有交换分区      # hdparm -i /dev/hda # 查看磁盘参数(仅适用于IDE设备)      # dmesg | grep IDE # 查看启动时IDE设备检测状况

   网络:

# ifconfig # 查看所有网络接口的属性      # iptables -L # 查看防火墙设置      # route -n # 查看路由表      # netstat -lntp # 查看所有监听端口      # netstat -antp # 查看所有已经建立的连接      # netstat -s # 查看网络统计信息

   进程:

# ps -ef # 查看所有进程      # top # 实时显示进程状态(另一篇文章里面有详细的介绍)

   用户:

# w # 查看活动用户      # id 
<用户名>
# 查看指定用户信息 # last # 查看用户登录日志 # cut -d: -f1 /etc/passwd # 查看系统所有用户 # cut -d: -f1 /etc/group # 查看系统所有组 # crontab -l # 查看当前用户的计划任务

   服务:

# chkconfig –list # 列出所有系统服务      # chkconfig –list | grep on # 列出所有启动的系统服务

   程序:

# rpm -qa # 查看所有安装的软件包

 

转载于:https://www.cnblogs.com/zhuiluoyu/p/4469608.html

你可能感兴趣的文章
微信小程序picker组件 - 省市二级联动
查看>>
Dynamics CRM 给视图配置安全角色
查看>>
Eclipse修改已存在的SVN地址
查看>>
C++ ACM基础
查看>>
(转)使用 python Matplotlib 库绘图
查看>>
进程/线程切换原则
查看>>
正则表达式语法
查看>>
20165301 2017-2018-2 《Java程序设计》第四周学习总结
查看>>
Vue的简单入门
查看>>
使用最快的方法计算2的16次方是多少?
查看>>
urllib 中的异常处理
查看>>
【SQL Server高可用性】高可用性概述
查看>>
通过SQL Server的扩展事件来跟踪SQL语句在运行时,时间都消耗到哪儿了?
查看>>
SQL优化:重新编译存储过程和表
查看>>
PCB“有铅”工艺将何去何从?
查看>>
Solr环境搭建
查看>>
IE兼容性的一些。。
查看>>
第二章-递归与分治策略
查看>>
快速排查SQL服务器阻塞语句
查看>>
推荐系统常用数据集
查看>>