linux下一些常用命令和访问目录

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 OVERWRITTEN
nameserver 192.168.1.1
nameserver 114.114.114.114
nameserver 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 interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.1.69
gateway 192.168.1.1
netmask 255.255.255.0

3. 查看是否启动应用

ps -ef|grep nginx
root       939     1  0 09:42 ?        00:00:00 nginx: master process ./sbin/nginx
www-data   940   939  0 09:42 ?        00:00:00 nginx: worker process
xiao      1797  1672  0 18:10 pts/3    00:00:00 grep --color=auto nginx
xiao@ubuntu:~$ ps -ef|grep php
root       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 www
nobody     891   889  0 09:42 ?        00:00:00 php-fpm: pool www
xiao      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详解:  http://www.cszhi.com/20120513/nginx_nginx-conf.html

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=2000
HISTSIZE=2000
HISTTIMEFORMAT=”%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