1. 程式人生 > 實用技巧 >bash: command types and commands

bash: command types and commands

  • user
    • sudo <command> <arguments>: to work as root user
  • Terminal
    • echo
    • printf
  • System and Env
    • pgrep <command name>: to get command process
      • /proc/$PID/environ: process <PID>'s environment

  • echo
    • echo -e "<string with regexp>"
    • $ echo -e "1\t2\t3"
      > 1    2    3
    • set color
    • \e[1,31m: to set color red
    • \e[0m: to reset color
    • for text: reset=0; black=30; red=31; green=32; yellow=33; blue=34; magenta=35; cyan=36; white=37
    • for background:reset=0; black=40; red=41; green=42; yellow=43; blue=44; magenta=45; cyan=46; white=47
    • $ echo -e "\e[1;31m test \e[0m"
      > test
       

    • $ echo -e "\e[1;41m test \e[0m"
      > test
      

          

  • printf
    • %s, %c, %d, %f
    • -: left justifying
    • $ printf "%-5s %-5s %-5s\n" This is test
      > This  is    test
      
  • <process>
    • $ pgrep bash
      > 8111
      $ cat /proc/8111/environ
      > USER=aaaHOME=/u/aaaPATH=/bin......
      $cat /proc/8111/environ|tr '\0' '\n'
      > USER=aaa
      HOME=/u/aaa
      PATH=/bin
      ....
      

    • sss
    • sss