Tuesday, 6 September 2016

unix

1. vi
  • move within line: 0(begin), $(end), w(next), b(previous)
  • move within file: 1G(begin), G(end), nG(line) 
  • move between screen: ctrl+f(forward), ctrl+b(back), ctrl+d(forward half), ctrl+u(back half)
  • u(undo) 
  • edit: i(insert), x(delete), o(insert line before), O(insert line after), d0(delete from 0), d$(delete to $), dd(delete line), ndd(delete n line), yy(copy line), nyy(copy n line), p(paste),
  • search: /(search forward), ?(search backward), n(next forward), N(next backward)
  •  replace: :%s/text1/text2/g
  • line number: ^g(show current line number and total line number), :set number, :set nonumber, :1,10y(copy line 1-10)

2. ls
  • ls -altr  //a=all, l=long_format, t=sort_by_time, r=reverse_order

3. less
  • F (become tail -f)
  • ctrl+g (show statistics)
  • v (edit)
  • h (help)
  • -N (display line number)
  • G (go to end of file)
  • g (go to start of file)

4. grep
  • grep -n pattern file

5. cron

6. get information of linux machine
  • primary ip address: /sbin/ifconfig -a
  • OS version: uname -a
  • ps -ef | grep proc_name
  • hostname ip conversion: nslookup [address] [hostname]

7. ssh tunnelling
       ~/.ssh/config

       host wstasapp016
       LocalForward 50404 10.200.10.222:1521

       to test: ssh -p 50404 localhost

8. keep console busy
  • prstat
  • while sleep 300; do echo -ne "\a"; done &

9. sudo and su
  • sudo     //ask for root permission
  • su         //switch to another user
  • sudo su - user  //open a login shell as user

10. shell argument
  • "$@" is an array-like construct of all positional parameters, {$1, $2, $3 ...}
  • "$#" is the number of positional parameters
  • "$0" is the name of the shell or shell script
  • -z string true if the string is null
  • -n is the opposite of -z
  • foo=${variable:-default}  # If variable not set or null, use default.

11. ping -c 3                               //ping with 3 packet


reference
1. setup ssh tunnel using putty
2. ssh tunnelling using config file
3. dollar sign shell variable
4. linux test command

No comments:

Post a Comment