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

后端 未结 25 1471
遇见更好的自我
遇见更好的自我 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 18:56

    When things work on one server but are broken on another the following lets you compare all the related libraries:

    export MYLIST=`ldd amule | awk ' { print $3; }'`; for a in $MYLIST; do cksum $a; done
    

    Compare this list with the one between the machines and you can isolate differences quickly.

    0 讨论(0)
  • 2021-01-29 18:57

    I find commandlinefu.com to be an excellent resource for various shell scripting recipes.

    Examples

    Common

    # Run the last command as root
    sudo !!
    
    # Rapidly invoke an editor to write a long, complex, or tricky command
    ctrl-x ctrl-e
    
    # Execute a command at a given time
    echo "ls -l" | at midnight
    

    Esoteric

    # output your microphone to a remote computer's speaker
    dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp
    
    0 讨论(0)
  • 2021-01-29 18:57

    Your shell is the most powerful tool you have available

    1. being able to write simple loops etc
    2. understanding file globbing (e.g. *.java etc.)
    3. being able to put together commands via pipes, subshells. redirection etc.

    Having that level of shell knowledge allows you to do enormous amounts on the command line, without having to record info via temporary text files, copy/paste etc., and to leverage off the huge number of utility programs that permit slicing/dicing of data.

    Unix Power Tools will show you so much of this. Every time I open my copy I find something new.

    0 讨论(0)
  • 2021-01-29 18:57

    Start all WebService(s)

         find -iname '*weservice*'|xargs -I {} service {} restart
    

    Search a local class in java subdirectory

         find -iname '*.java'|xargs grep 'class Pool'  
    

    Find all items from file recursivly in subdirectories of current path:

         cat searches.txt| xargs -I {} -d, -n 1 grep  -r {} 
    

    P.S searches.txt: first,second,third, ... ,million

    0 讨论(0)
  • 2021-01-29 18:59

    The tr command is the most under-appreciated command in Unix:

    #Convert all input to upper case
    ls | tr a-z A-Z
    
    #take the output and put into a single line 
    ls | tr  "\n" " "
    
    #get rid of all numbers
    ls -lt | tr -d 0-9
    
    0 讨论(0)
  • 2021-01-29 18:59

    Finding PIDs without the grep itself showing up

    export CUPSPID=`ps -ef | grep cups | grep -v grep | awk '{print $2;}'`
    
    0 讨论(0)
提交回复
热议问题