402v /posts/fu-wu-qi-ming-ling-kuai-su-cha-xun

服务器命令快速查询

###Shell

  1. 判断文件存在和是否为空

    • -s FILE:FILE exists and has a size greater than zero,如果文件存在且文件大小大于零,则返回真;

    • -e FILE:FILE exists,如果文件存在,则返回真。

        #! /bin/sh
            
        if test -s file.txt; then # 也可以写成:if [ -s file.txt ]; then
                echo "hi"
        else
                echo "empty"
        fi
      
  2. env指定

     #!/usr/bin/python 是告诉操作系统执行这个脚本的时候,调用/usr/bin下的python解释器;
     #!/usr/bin/env python 这种用法是为了防止操作系统用户没有将python装在默认的/usr/bin路径里。当系统看到这一行的时候,首先会到env设置里查找python的安装路径,再调用对应路径下的解释器程序完成操作。
     #!/usr/bin/python 相当于写死了python路径;
     #!/usr/bin/env python 会去环境设置寻找python目录,推荐这种写法
    

###Linux命令

  1. 创建rsa密钥

     ssh-keygen -t rsa
    
  2. 查看系统内核和操作系统版本

     uname -a
    
  3. 查看操作系统的版本(Redhat)

     cat /etc/redhat-release
    
  4. Dotfile配置

      git clone git@github.com:kimimaro/Dotfile.git
    
  5. 看进程

      ps aux | grep xxx 
    
  6. 看端口,哪些进程占用了这个端口

      lsof -i :80 or 5000
    
  7. 查看Log文件

      tail -f xxx/log
    
  8. 查看当前Shell

     echo $SHELL
    
  9. 创建用户

    • useradd: 创建出的user无home、passwd和group

      useradd test -d /home/test

    • adduser: 有交互的,更人性化的命令。perl脚本

  10. 删除用户:userdel or deluser

  11. 显示用户信息

    • whoami:显示当前用户名
    • who:显示目前登入系统的用户信息
    • w:显示目前登入系统的用户信息,更详细
  12. 强制杀死80端口的进程

    sudo fuser -k 80/tcp ; sudo /etc/init.d/nginx restart
    
  13. 修改只读文件

    visudo -f filename
    
  14. 增加sudoers,在sudoer.d/目录下新增文件后没有读取成功

    visudo -f /etc/sudoers 
    
  15. 测试Nginx

    nginx -t
    
  16. 创建软链接

    ln -s file link
    
  17. 快速拷贝&输入

    cp config/database.yml{,.example}
    echo config/database.yml >> .gitignore
    

###SSH

  1. 关闭ssh后server上的进程会停止

  2. ssh到服务器并进入指定目录

     ssh -t root@128.199.81.231 "cd /var/www/ghost/content/themes/vno ; bash"
    

###Rails

  1. gem卸载: gem uninstall capistrano -v 3.4.0

###Vim

  1. Linux环境下VI/VIM 编辑文件时无权限保存的解决方法:

     :w !sudo tee %
    
  2. Vundle

    • Install

        git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
      
    • Plugins

    Launch vim and run :PluginInstall

    To install from command line: vim +PluginInstall +qall

###Ghost

  1. Ghost服务状态:service ghost status
  2. 配置文件:/etc/init.d/ghost
  3. 网站所在路径:/var/www/ghost/
  4. 重启Ghost服务:service ghost restart

###Mac

  1. Sublime软链接 ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/sublime

评论 · 0

还没有评论。