Most powerful examples of Unix commands or scripts every programmer should know

后端 未结 25 1464
遇见更好的自我
遇见更好的自我 2021-01-29 18:14

There are many things that all programmers should know, but I am particularly interested in the Unix/Linux commands that we should all know. For accomplishing tasks that we may

25条回答
  •  失恋的感觉
    2021-01-29 19:01

    Repeat your previous command in bash using !!. I oftentimes run chown otheruser: -R /home/otheruser and forget to use sudo. If you forget sudo, using !! is a little easier than arrow-up and then home.

    sudo !!
    

    I'm also not a fan of automatically resolved hostnames and names for ports, so I keep an alias for iptables mapped to iptables -nL --line-numbers. I'm not even sure why the line numbers are hidden by default.

    Finally, if you want to check if a process is listening on a port as it should, bound to the right address you can run

    netstat -nlp
    

    Then you can grep the process name or port number (-n gives you numeric).

    I also love to have the aid of colors in the terminal. I like to add this to my bashrc to remind me whether I'm root without even having to read it. This actually helped me a lot, I never forget sudo anymore.

    red='\033[1;31m'
    green='\033[1;32m'
    none='\033[0m'
    
    if [ $(id -u) -eq 0 ];
    then
        PS1="[\[$red\]\u\[$none\]@\H \w]$ "
    else
        PS1="[\[$green\]\u\[$none\]@\H \w]$ "
    fi
    

    Those are all very simple commands, but I use them a lot. Most of them even deserved an alias on my machines.

提交回复
热议问题