Unix_Linux_Learn

  1. The UNIX operating system is made up of three parts; the kernel, the shell and the programs.
  2. Everything in UNIX is either a file or a process.
  3. A process is an executing program identified by a unique PID (process identifier).
  4. A file is a collection of data. They are created by users using text editors, running compilers etc.
  5. The directory structure:
  6. Files beginning with a dot (.) are known as hidden files and usually contain important program configuration information. ls -a
  7. The command cat can be used to display the contents of a file on the screen. The command less writes the contents of a file onto the screen a page at a time. less is used in preference to cat for long files.
  8. If you do cat > somefile.txt then cat will read whatever you type and then write it to that file.
  9. $ export TESTING="this is some environment var"
    $ echo $TESTING => this is some environment var
    $ unset TESTING
  10. ls -l:
    -rw-r--r--:
        the first indicate file type: '-' file, 'd' directory, 'l' link file, 'b'可供存储的接口设备, 'c':serial device 
        after the first one, next 9 characters come in 3 groups, the first 3 represent the owner permission
        the second 3 means the group permission; the third means the world permission

    -rwxrwxrwx root root 293 Oct 19 21:24 test
    (file.property) (user) (group) (file size) (edit time) (file name) r:4, w:2, x:1, so -rwxr-xr-x is equivalent to 755 chmod function: chmod 755 # chmod u+rw filename_here u/g/o/a : user,group,other,all +,-: add permission, remove permission
  11. $ head -5 demo01.txt: print out the first 5 lines of the file. default is 10; same as tail command.
  12. in less mode, use "/" + string to search the string you want.
  13. grep: option -c count; -i ignore case; -v display lines not match; -n precede each matching line with line number. eg: $ grep -ivc science science.txt
  14. account and root info: /etc/passwd; password in: /etc/shadow; user group name: /etc/group
  15. 如果想对他人开放某个目录,需开放x属性!!
  16. passwd: change password
  17. date: display local timezone; date -u: display UTC time
  18. $ uname: display which version of UNIX is used, -s(system name, default), -a(all), -m(machine), -n(nodename), -r(release), -v(version).
  19. $ tty: 'teletype', displays the name of the terminal you are currently using.
  20. $ who: lists those people currently logged in to the system by username.$ who -u: more information, '.'means the currently using user.
  21. $ mailx -s "some subject" usrname: send usrname a mail of subject "some subject", Ctrl-D to finish
  22. $ write usrname: write instant message to usrname for logged in users. use $ mesg n to deny incoming messages, $ mesg y to reinstate. $ talk is as write(same syntax) but work character by character. Ctrl-C to terminate.
  23. $ whoami: display the usrid, $ who: display all the users currently logged in. $ w: display who logged in and what they are doing.
  24. $ Ctrl-D: to log out.$ Ctrl-C: terminate a command. $ passwd: change password. $ last your-user-id: the last time you logged in. $ Ctrl-Z: undo
  25. X Window is a system that provides services to programs that work with graphical data.
  26. LAYERS: hardware->device drivers in the kernel->X Window->Window Manager->Desktop Environment->Apps/Users
  27. Metacity is the window manager of GNOME(GNU Network Object Model Environment), and kwm is the window manager of KDE(Kool Desktop Environment). Unix GUIs are created by a combination of X Window, a window manager and a desktop environment. CLI: Command Line Interface.
  28. in a UNIX system, every object is presented by either a file or a process.
  29. Virtual consoles #1-6 are full-screen, text-based terminals for using a CLI. Virtual console #7 is a graphics terminal for running a GUI. <Ctrl-Alt-F1> for virtual console #1, graphic one is <Ctrl-Alt-F7>.
  30. virtual console & terminal emulator: konsole(terminal emulator), console(the special terminal that an admin uses).
  31. $ su newuserid: change to another userid. $ su - neruserid: change to another userid and also change to that user's environment. $ su - is equivalent with $ su - root, $ sudo id: display the current userid.
  32. su: substitute userid, sudo: substitute userid and do somethin.
  33. the ones who can use sudo command is kept in a file named /etc/sudoers, and it can be changed only by superuser.
  34. Most UNIX programs are written so they can be customized by editing a Configuration file. Within windows, programs store configuration information in two places, in the Registry ,and sometimes, in .ini files. In UNIX, there is no central Registry, every programs is alowed to have its own configuration file. To look into a configuration file, we use program less(b for back page, space for next page, h for help, q for quit), which displays the content of a file, one screenful at a time.
  35. init: change runlevel. $ sudo init 0: shutdown computer. $ sudo init 5: multiuser GUI runlevel. Normally, a runlevel is chosen as part of the startup process in order to boot the system. RUNLEVEL: 0(shutdown), 1(single-user-mode, command line), 3(multiuser-mode, command line), 5(multiuser-mode, GUI), 6(reboot). command reboot(change to runlevel 6) and shutdown($ sudo shutdown now:tells the computer to shutdown now, that is change to runlevel 0 right away)
  36. display the boot message: $ dmesg | less.for more info see: http://www.linfo.org/dmesg.html, the output of dmesg is maintained in the log file /var/log/dmesg
  37. In linux, serial port devices are usually designated /dev/ttyS*, * represents integers beginning with 0.
  38. 4 types of terminal: xterm(Mac OS X), VT220, VT100, 3270; a global environment TERM whose value is set to the type of terminal you are using. $ echo $TERM$ printenv: display the values of all the environment varibles within your shell. Environment variables are given upper case letters such as TERM.
  39. UNIX uses a set of keyboard signals to control the operation of programs. ^C(cancel command or stop a program) is mapped to the intr signal. erase, werase, kill signals. ^W(signal of werase): erase a word previously written. ^U(signal of kill): kill a line. ^S: stop displaying output, ^Q:  start. ^D: end of file eof signal. ^Z: pause a program(mapped to the susp signal). Use fg(foreground) to restart a program you stopped. ^M: equivalent with return(enter), ^J: line feed.(Unix:each line end with ^J,\n, Windows end with ^M^J,\r\n; Mac end with carriage return ^M, \r).
  40. Bash trapping the eof signal: set envrionment variable IGNOREEOF=5, means ^D five times for logging out. To set IGNOREEOF automatically you have put the command in the .profile file.
  41. To display the key mappings on your system, use: $ stty -a, (stty: set terminal, -a show all info), $ stty kill ^k: change key mapping.
  42. which: shows the full path of (shell) commands. 
    1 $ which date less vi emacs
    2 /usr/bin/less
    3 /usr/bin/vi
    4 /usr/bin/emacs
  43. The type command is used to find out if command is builtin or external binary file. It also indicate how it would be interpreted if used as a command name. 
    $ type date
    date is /bin/date 
    $ type type
    type is a shell builtin
  44. $ cal 7 1975: calendar of month 7, 1975. $ cal -j 12 2000: display the number of days of 2000, -j stands for Julian.
  45. uptime: displays information about how long your system has been up(continuously). hostname: displays the name of your computer. uname: shows you the name of your system. whoami: displays the user id you logged in. users: shows you the current users logged in. who: shows more info(has userid, tty name, login time, computer name) than users. w: "who is doing what", more info than who.
  46. leave: set leave alarm. such as:
    $ leave 10:33  // leave at 10:33
    $ leave +15  // leave 15 minutes later, +: time interval
  47. bc: a builtin calculator. If you want to use the builtin functions, do: $ bc -l(L), use ";" for multiple expressions:
    $ bc -l
    10 + 10; 20 + 20
    // you will see :
    //20  
    //40
    // use Ctrl-D or quit to quit.
    // check scale
    $ scale
    // set scale
    $ scale=3 // keep three digits to the right of the decimal point.
    // when you start bc, the scale is set automatically to 0, when you use mathematical library, the scale is set
    // to 20
    // ibase is used for input base, default is 10, obase is for output.
    // A always stand for 10(10 base)(as with BCDEF), so ibase=A is safe.
  48. bc worked by converting its input to RPN and then calling upon dc to do the actual work. dc, a stack-based RPN caculator program.
  49. in dc:
    34 25 + 15 *
    p            // display the top of the stack
    885
    // to change the precision to 14 enter:
    14 k
    // display the current precision:
    K p // push the current precision to the top of the stack. use q to quit program
  50. in less, use <Space> to scroll one screen down, b up. g: go to top, G: go to end. /pattern: search for patter, such as /output.(tells the the paging program to skip forward to the next line that contains the word output, keep pressing / for more the same pattern), search backward use ? instead of /.
  51. in a man page, use !(exclamation mark) following a command, to execute the command, then press <Return> to return to the man page. Such as, !date<Return>, BANG (CHARACTER) is "!". When searching on the Web, use this form: "man whatis" to search a specific man page(include quotation mark). Or use: "man pages" Linux. Or use $ xman&, GUI based man page, using the &(ampersand) character tells the shell to start running the program on its own in the background. 
  52. Eight sections of man page:
    1 Commands
    2 System calls
    3 Library functions    // subroutines
    4 Special files    // usually represents a physical device, device drivers
    5 File formats    // used by the system, including configuration file
    6 Games
    7 Miscellaneous information
    8 System administration
  53. Sepcifying section number: $ man 2 kill: 2 is for section 2. Intro page: 
    1 man man 
    2 man intro
  54. Structure of Manual: NAME, SYNOPSIS, DESCRIPTION, OPTIONS, FILES, ENVIRONMENT, AUTHOR, 
  55. Environment variables: whose values are available to all programs and shell scripts(UPPERCASE LETTERS).
  56. whatis(display command description) as a synonym for man -f, display the NAME section of the specified command. Quick summary. apropos as a synonym for man -k(search for info containing keyword following -k). apropos command searches through all the one-line command descriptions, looking for those that contain the same string of characters you specify.
  57. INFO: is an online help system used to document GNU utilities. info + command name. INFO contains links and support more commands than the online manual. Inside INFO, use "l"(L) to return to previous node. The root of a tree is called the TOP NODE. <Space> for next page, <Backspace> for previous page. b: jump to beginning of current node. n: jump to next node. p: jump to previous node. t: jump to top node. l(L): jump to last viewed node. d: jump to directory node(main menu for the entire system), <tab>: moves down to the next link. M-<tab>: moves to the previous link.
  58. Entering more than one command: use ";" to seperate them:
    $ date; cal
    // equal to :
    $ date
    $ cal
  59. Command syntax: $ command-name options arguments, options(switches, flags). When you use more than one single-character option, you can combine them by using a single hyphen, and specify them in any order:
    $ ls -la    // equals to
    $ ls -al    // - read as 'dash'
  60. --help and --version.
  61. ARGUMENTS: are used on the command line to pass information to the program you want to run. WHITESPACE: refers to one or more consecutive spaces or tabs. You should never use spaces in the name of a file. 
  62. Unix Syntax, rules:
    1 Items in square brackets are optional
    2 Items not in square brackets are obligatory
    3 Anything in boldface must be typed exactly as written
    4 Anything in italics must be replaced by an appropriate value
    5 An argument followed by an ellipsis(...) may be repeated any number of times
    6 If you see a single option grouped with an argument, the option and argument must be used together
    7 Two or more items seperated by a | character, indicates that you are to choose one item from a list
  63. 1 man -f     // equals: $ whatis
    2 man -k    // equals: $ apropos
  64. show what shells your system has: 
    $ less /etc/shells
    $ echo $SHELL // show your current shell
  65. Unix uses two files to keep track of all the userids in the system. 1./etc/passwd(contains basic information about each userid); 2./etc/shadow(contains the actual password); the file /etc/shells contains the pathnames of the available shells.
  66. shell variables & environment variables. With the shell, variables can only store character string. Child process & parent process(child inherits parents' environment). In Bourne Shell, both of'em are given uppercase names, you're only allowed to create local variables. The export command changes a shell variable into a shell+environment variable.
  67. env: display default variables; same as printenv. set: display shell variables along with their values. Compare the output of set with output of env to find out which variable is shell variable or environment variable.
  68. To display the value of a variable: $ echo {TERM}.  Use double quotes to avoid display metacharacters, such as:
    $ echo "The terminal type is <$TERM>"
  69. If you want to use a variable such that it is not seperated from its neighbors, you must use braces to delimit it. For example:
    // ACTIVITY has a value of surf
    $ echo "my favorite sport is $<ACTIVITY>ing."
    // will display: my favorite sport is surfing.
  70. set variable:
    $ VAR_ONE=cool
    $ VAR_TWO="string containing spaces"
    $ export VAR_ONE VAR_TWO    // export variables to environment
    // same thing:
    $ PAGER=less; export PAGER
    $ export PAGER=less    // syntax is export NAME[=value]
    // examples:
    $ export PAGER=less EDITOR=vi PATH="/usr/local/bin:/usr/bin:/bin"
  71. unset variable, syntax: $ unset NAME..., in Bourne shell family, the only way to remove a variable from the environment is to destroy it.
  72. SHELL OPTIONS: use to control shell's behavior. 2 ways, 1st, CLI command; 2nd:
    // to set an option:
    $ set -o option
    // to unset an option:
    $ set +o option
    // option is the long name of an option
    // use $ set -o(easy to read) or $ set +o(easey to use as data) to have a look at the options
  73. QUOTE the character to avoid use the metacharacter. 3 ways:
    1 // use backslash(strongest, even escape newline character): (the backslash for this purpose is called escape character)
    2 $ echo It is wam and sunny\; come over and visit
    3 // single quotes(strong quotes):
    4 $ echo 'It is (warm and sunny); come over & visit'
    5 // double quotes(weak quotes): preserve the meaning of $, \, `(backquote)
    6 $ echo "My userid is <$UER>; my terminal is <$TERM>"
  74. External commands have their own man page, builtins do not. To check if a command is a builtin or not:
    $ type command...
  75. all the builtin commands are documented within the man page for the shell. See them in: $ apropos builtin, For linux, use $ man builtins, Use $ help COMMAND-NAME to display help info, help itself is a builtin command. If you only want to look at the syntax for a command, use -s option:
    $ help -s kill
  76. When the shell needs to find an external command, it checks each directory in the search path in the order they are specified. Example of modifying PATH:
    export PATH="/bin:/usr/bin:/usr/local/bin"
    // add $HOME/bin to PATH:
    $ export PATH="$PATH:$HOME/bin"  // or:
    $ export PATH="$HOME/bin:$PATH" 
    // as a programmer, you may wish to add your "working directory" to the PATH:
    $ export PATH="$PATH:."
    // put your personal directories in the end of PATH except that you are an expert.
  77. bash, modify the shell prompt:
    $ export PS1="$ "
  78. When you use the value of a variable, better to use brace brackets:
    $ echo "My userid is ${USER}"
    // #=> My userid is xxx
    $ export PS1='My lucky number is ${RANDOM} $ ' // things will change
    $ export PS1="Userid is ${USER} $ " // things won't change
    // difference between ' with ":
  79. Special codes in Bash prompt:\w(working directory, ~ notation), \W(working directory, basename only), \h(host name of your computer), \u(current userid), \s(name of the shell), \@(time, AM/PM notation), \A(time, 24hour notation), \d(date), \!(history list, event number).
  80. Command Substitution: embed one command within another, the shell first execute the embedded command and replace it by its output, the shell then executes the overall command. Syntax: you embed a command within another by enclosing the first command in backquote character(`). eg:
    $ echo "The time and date are `date`."
  81. basename: command that read a full pathname and output the last part of it:
    $ basename /bin/bash    // bash
    $ basename $SHELL      // bash
  82. <UP>: previous command, <backspace>: erase signal, erase one character left, <delete> or ^D: remove one character right.
  83. History List: as you enter commands, 
  84. touch
    $ touch newfile.txt // Creates a file known as "newfile.txt", if the file does not already exist. If the file already exists the accessed and modification time is updated for the file newfile.txt
  85. display free disk space using human readable format: 
    $ df -h /
    // watching processes running on your mac:
    $ top
    // print the file /etc/hosts on your default printer:
    $ lpr /etc/hosts
    // display ip address
    $ ipconfig getifaddr en0 // For wired
    $ ipconfig getifaddr en1 // For wireless
    // see who owns the domain name OREILLY.COM:
    $ whois oreilly.com | less
  86. a
  87. a
  88. aa
  89. a
  90. a
  91. a
  92. a
  93. a
  94. a
  95. a
  96. aa
  97. a

转载于:https://www.cnblogs.com/wade-case/archive/2013/02/19/2916440.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值