zoukankan      html  css  js  c++  java
  • linux 常用技巧

    1--查看版本

    查看内核版本

    # cat /proc/version

    查看linux版本

    # lsb_release -a 或者 cat /etc/issue ,遇见了一个centos的虚拟机上边的都看不出来,可以 cat /etc/redhat-release

    2--linux服务器测速

    speedtest-cli

    wget -O speedtest-cli https://raw.github.com/sivel/speedtest-cli/master/speedtest_cli.py
    chmod +x speedtest-cli
    

    运行

    ./speedtest-cli   #不指定服务器未知
    ./speedtest-cli --server 5120     #编号获取:http://www.speedtest.net/speedtest-servers-static.php
    

    关于wget

    encode your username and password within a URL:

    ftp://user:password@host/path
    http://user:password@host/path
    

    在命令行指定了包含密码的URL ,用户名和密码会在系统上的所有用户可见(用PS)
    所以,用wget -i

    一些选项(可以使用前边的省略形式)
    “-q” “quiet” 关闭Wget的输出
    “-O" "output" 制定写入到哪个文件。 比如wget -O haha.txt http://XXXXXXX
    "--limit-rate=20k" 限制20k/s 还可以用m

    3--Vim 保存只读文件的修改内容

    :w !sudo tee %
    

    w执行写文件操作。这里调用了sudo命令,使得我们有root权限;将文件写入到tee来处理,这里tee的后缀参数为文件名。而%在Vim中的意思是当前文件名。

    4--使用except实现自动登陆脚本

    示例(登陆一台机器后再上边登陆另一台机器):

    #!/usr/bin/expect
    set timeout 30
    set password "123456789"
    spawn ssh jcuan@222.222.222.222
    expect "*password*"
    send "$password
    "
    expect "*Last login*"
    send "ssh root@172.17.0.3
    "
    expect "*password*"
    send "1234567890
    "
    interact
    

    注意:
    #!/usr/bin/expect  
    spawn是进入expect环境后才可以执行的expect内部命令!!
    [interact]执行完成后保持交互状态,把控制权交给控制台,这个时候就可以手工操作了。如果没有这一句登录完成后会退出。

    5--用proxychains为程序设置代理

    proxychains支持http/https/socks4/socks5。

    sudo apt-get install proxychains
    

    配置文件/etc/proxychains.conf
    dynamic_chain,按照列表中出现的代理服务器的先后顺序组成一条链,如果有代理服务器失效,则自动将其排除,但至少要有一个是有效的。
    strict_chain,按照后面列表中出现的代理服务器的先后顺序组成一条链,要求所有的代理服务器都是有效的
    random_chain,列表中的任何一个代理服务器都可能被选择使用,这种方式很适合网络扫描操作(参数chain_len只对random_chain有效)。
    例子:shadowsocks,本地端口1080

     [ProxyList]
     socks5  127.0.0.1 1080
    

    6--管理开机启动项目

    相关目录

    • /etc/init.d 包含许多系统各种服务的启动和停止脚本
    /etc/init.d/networking restart    #可以这样使用
    
    • /etc/rc*.d/ 每次系统进入这个脚本的时候都会运行这个下边的脚本
      S开头的是需要运行的,K开头的是需要停止的
      S或者K的后边有两位数,这个是有关运行顺序的,自己填的数字,运行update-rc.d mysql defaults(比如我修改的是mysql的)会自动调整

    • 关于inittab
      ubuntu类似这个文件的功能是/etc/init/rc-sysinit.conf,在这个地方可以看见我的运行级别是2

    关于运行级别

    linux.com:introduction-services-runlevels-and-rcd-scripts

    # 0 - 停机
    # 1 - 单用户模式
    # 2 - 多用户
    # 3 - 
    # 4 – 多用户
    # 5 - 多用户
    # 6 - 重新启动
    

    可以安装rcconf来快速地管理服务

           --on service[,service,...]
                Set services to be on.  This option enables rcconf in command line
                mode and no select menu will be displayed.
    
           --off service[,service,...]
                Set services to be off.  This option enables rcconf in command
                line mode and no select menu will be displayed.
    
           --list
                List services which includes current status(on/off).  This option
                enables rcconf in command line mode and no select menu will be
                displayed. Use --expert option together if you want to list all
                services.  This result can be used as config_file of --config.
    
    

    关于/etc/rc.local

    This script is executed at the end of each multiuser runlevel.

    7--允许root通过ssh登录

    修改/etc/ssh/sshd_config,设置PermitRootLogin yes就行

    8--boot分区满了

    需要卸载掉以前安装的内核,一定不要乱删里边的东西!

    deinstalled的表示已经移除了

    #先查看安装过的内核版本
    jxdz@jxdz:/$ sudo dpkg --get-selections |grep linux-imagelinux-image-3.13.0-143-generic			install
    linux-image-3.13.0-24-generic			deinstall
    linux-image-3.13.0-66-generic			deinstall
    linux-image-3.13.0-67-generic			deinstall
    linux-image-3.13.0-68-generic			deinstall
    linux-image-3.13.0-71-generic			install
    linux-image-3.13.0-74-generic			install
    linux-image-3.13.0-76-generic			install
    linux-image-3.13.0-77-generic			install
    linux-image-extra-3.13.0-143-generic		install
    linux-image-extra-3.13.0-24-generic		deinstall
    linux-image-extra-3.13.0-66-generic		deinstall
    linux-image-extra-3.13.0-67-generic		deinstall
    linux-image-extra-3.13.0-68-generic		deinstall
    linux-image-extra-3.13.0-71-generic		deinstall
    linux-image-extra-3.13.0-74-generic		install
    linux-image-extra-3.13.0-76-generic		install
    linux-image-extra-3.13.0-77-generic		deinstall
    linux-image-extra-3.13.0-79-generic		deinstall
    linux-image-generic				install
    
    ### 查看当前使用的版本
    uname -a
    Linux jxdz 3.13.0-76-generic #120-Ubuntu SMP Mon Jan 18 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
    
    ### 删除非当前的版本
    sudo apt-get remove linux-image-xxx-generic
    

    9-kill多个进程

    ps -ef|grep php-fpm|grep -v grep|cut -c 9-15|xargs sudo kill -9 
    
    • grep -v grep 是排除含有“grep”的进程
    • cut用来截取PID
    • xargs命令是用来把前面命令的输出结果(PID)作为“kill -9”命令的参数,并执行该命令

    10-在后台运行

    nohup command 1>output 2>&1 &
    
  • 相关阅读:
    OpenCV && C++ 01
    图像矩的理解
    Halcon Example
    LabVIEW
    Working Experience
    Working Experience
    Working Experience
    C++
    Trigger,Cursor
    Paging
  • 原文地址:https://www.cnblogs.com/jcuan/p/5724826.html
Copyright © 2011-2022 走看看