Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux operating system Study Notes     - SpringMVC the use of interceptors (Programming)

- Add your own kernel and ramfs based on an existing Linux LiveCD (Linux)

- Linux System Getting Started Learning: Linux common log file (Linux)

- The correct method to modify the maximum number of concurrent connections Tomcat 7 (Server)

- Ubuntu install Oracle 10g process and problem solution (Linux)

- How to run Docker client in Windows operating system (Linux)

- Hadoop 2.5 Pseudo distribution installation (Server)

- PostgreSQL query lock and kill the process (Database)

- Linux environment MySQL master-slave synchronization (Database)

- Linux System Tutorial: How to browse the Linux command line, weather forecast (Linux)

- Java thread lifecycle (Programming)

- Python 2.7 installed on CentOS 6.5 (Linux)

- Debian 8 Jessie install LAMP server tutorial (Server)

- C ++ Fundamentals study notes (Programming)

- Reset CentOS / RHEL root account password 7 (Linux)

- Design and implementation of environment sniffer running under Linux (Linux)

- linux remote control software (Linux)

- Arronax allows you to easily create desktop startup file (Linux)

- PostgreSQL vacuum principle of a function and parameters (Database)

- Linux Change ssh port and disable remote root login at (Linux)

 
         
  Linux operating system Study Notes
     
  Add Date : 2017-08-31      
         
         
         
  First contact with Linux operating system, just know a few simple commands, when used in work again, had to once again ponder that knowledge and make learning system, will now be learning in the form of note-taking, share some simple knowledge and personal humble opinion, if wrong, please point out.

     basic knowledge:

    Linux disk partition, said:

    Such as: / dev / hda5: / dev / directory which contains hardware device files, hd indicates an IDE device, sd indicates a SCSI device, a hard disk indicates the sequence number, the first hard drive is a, the second block is b ... and so on, just like the C drive disk D under the same windows, 5 denotes a logical partition. Linux partition from the primary partition and extended partitions, the primary partition is not more than 4, logical partitions in the extended partition divided so logical partitions from 5 onwards, regardless of the primary partition is full four partitions, anyway, before the four are allocated to primary partition.

    Similarly, a second hard drive SCSI device second block representation of a logical partition: / dev / sdb6

    File System Type:

    Linux file system type is used by default EXT3 (EXT4), SWAP, but also support other file system types, such as FAT16, FAT32, NTFS, XFS, etc.

    Directory Structure:

    Top level: the root directory (/), the root of several important directory: / root, / bin, / boot, / etc, / home, / var, / usr, / tmp ..... (each directory contains what is important)

    Graphics, characters, interface switching:

    GUI -> character terminal: Ctrl + Alt + Fn (n ranging from 1 to 6, the notes will be introduced later why)

    Character Terminal -> Terminal character: Alt + Fn

    ASCII terminal -> GUI: Alt + F8

After logging in, if the root user, the prompt is "#", if the average user, the prompt is "$"

     Shutdown and reboot commands:

    Reboot: shutdown -r now

          shutdown -r +15 "Warning: The system will be 15 minutes after the restart."

          reboot command also said the restart, but the difference with the shutdown is that it is mandatory to restart, and shutdown command prompts the user to save, it is proposed to use the shutdown command.

    Shutdown: shutdown -h now or halt

    He began to perform some simple commands:

    Note that in Linux is case-sensitive, and this is different windows, the windows powershell is a command or function, whether methods are case insensitive.

 
[Www.linuxidc.com@localhost ~] $ su - root to switch to the root user
Password:
[Root @ localhost ~] # to switch to the root prompt #
[Root @ localhost ~] # date display date and time
March 5, 2013 21:09:09 CST Tuesday
[Root @ localhost ~] # echo $ LANG display Currently supported languages
zh_CN.UTF-8
[Root @ localhost ~] # LANG = en_US Set Language
[Root @ localhost ~] # echo $ LANG
en_US
[Root @ localhost ~] # cal view the current calendar month
     March 2013
Su Mo Tu We Th Fr Sa
                12
 3456789
10111213141516
17181920212223
24252627282930
31
[Root @ localhost ~] # bc open Calculator
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty '.
4 * 3
12
Press the key to leave quit quit
[Root @ localhost ~] #
   Also have some common hotkey commands help increase speed, such as Tab (automatically filled, and in the case have no other commands, and press the TAB key twice all commands will appear, which can also be used as a help it.) ; Ctrl + C: interrupt currently running programs; Ctrl + D: keyboard input end, with Exit; Ctrl + L: clear screen; Ctrl + U clear to the line; Ctrl + K: clear to end of line; "\": Force newline.

    Linux command help:

    Under just said did not play in any order you press the TAB key twice displays all available commands, this method is not commonly used, commonly used method is to help, usage is: command --help, commonly used is the man to help (ie, Manual manual), usage is: man command, there is a method to help info, use the info command, in fact, this is not used, because under normal circumstances, man has been able to solve most of the problem.

    In addition, as the use of man or info command, there will be multiple pages, sometimes more do not want to see, this time press q to exit the help, and because a lot of real information, you how to quickly find what they want it, then, enter "/ character you want to find", press enter to

    You can see the effect of a command: whatis command

    You can also see where a command is located in: which command (except cd, because cd is built in the kernel)

    Handover execution level:

    Checking runlevels: runlevel

    level 0: Off (off available commands init 0, init process will be introduced later in the notes)

    level 3: pure command line mode, that our character mode terminal opened in the graphical interface right

    level 5: GUI mode (as a server, do not enable this basic level, direct access to level 3 character mode)

    level 6: Restart (reboot available command init 6)

   Level 1 represents single-user mode, 2 level indicates the character interface multi-user mode, use unallocated level 4, which does not use three basic levels. So long as we know the above four levels can be. Specific startup process and configuration files will be reflected in subsequent notes.

     Linux Command Category:

     (Linux command: command or program for realizing a function of execution depends on the command interpreter program, such as / bin / bash)

      Internal Command: part belonging to Shell interpreter (understood to command bin / under included)

      External command: independent Shell interpreter program (ie, do not need / bin / bash can also be performed, such as Vim, LVM)

     Linux command format:

     Command word [options] [arguments] Options: specific functions for parameter adjustment commands: Object command operations, such as files, directories, and so on. Options for multiple segments format can be written together but with a "-" to connect.

   Finally, I think a problem is to figure out the linux shell, in fact, Kernel and user shell is an interface between the user and the kernel does not deal directly, but the command entered by the user will be recognized by the kernel, which is the shell effect.

File and directory management and use VI editor

   File and directory management, just beginning to learn the contents of this feeling a lot of very complex, but after completion summarize, discovered that in fact highly organized and is no difficulty, but mastering these commonly used commands on the list. As for the Vim editor, I have to say, after using this editor, I feel the Windows notepad is no technical content.

Briefly summarize the files and directories used to the command, then use a simple skip.

     File manipulation commands: touch, file, which, find, cp, rm, mv, ln

     File Operation Command: cat, more, less, head, tail, wc, grep

     Directory command: pwd, cd, ls, mkdir, du

     Archiving and compression commands: gzip, bzip2, tar

[Linuxidc @ localhost ~] $ pwd ==> Displays the current directory
/ Home / linuxidc
[Jzhou @ localhost ~] $ mkdir dirtest ==> Create a directory
[Linuxidc @ localhost ~] $ cd dirtest ==> enter this directory
[Linuxidc @ localhost dirtest] $ touch testfile ==> Create a file
[Linuxidc @ localhost dirtest] $ mkdir dirtest1 ==> Create a subdirectory
[Linuxidc @ localhost dirtest] $ ls ==> list the contents of the current directory
dirtest1 testfile
[Linuxidc @ localhost dirtest] $ echo hello linux >> testfile ==> append to a file
[Linuxidc @ localhost dirtest] $ cat testfile ==> display file contents
hello linux
[Linuxidc @ localhost dirtest] $ file testfile ==> View Document Type
testfile: ASCII text
[Linuxidc @ localhost dirtest] $ du -sh testfile ==> display space occupied by the file
8.0K testfile
[Linuxidc @ localhost dirtest] number $ wc testfile ==> statistics file lines, words, characters,
 1 2 12 testfile
[Linuxidc @ localhost dirtest] $ echo haha, I love Linux >> testfile ==> additional content
[Linuxidc @ localhost dirtest] $ echo no, no, I hate C plus plus >> testfile
[Linuxidc @ localhost dirtest] $ echo OK, the end >> testfile
[Linuxidc @ localhost dirtest] $ cat testfile ==> View content
hello linux
haha, I love Linux
no, no, I hate C plus plus
OK, the end
[Linuxidc @ localhost dirtest] $ head -2 testfile ==> to view the file before two lines
hello linux
haha, I love Linux
[Linuxidc @ localhost dirtest] $ tail -2 testfile ==> The last two lines to view the file
no, no, I hate C plus plus
OK, the end
[Linuxidc @ localhost dirtest] $ cat testfile | grep "Linux" to find a specific keyword
haha, I love Linux
[Linuxidc @ localhost dirtest] $
These are just simple display of the command usage, many options not joined, head and tail commands by default after the front display 10 rows and 10 rows, du is to look at the amount of space a file or directory, usually larger than the actual size, and often It is an integer multiple of four.

more and less command also view the file contents approach, but less has been gradually replaced more, because of all the features of more have less and less able to view the page up, more can not, cat directly to a screen display file contents out, no matter how long, if all the files for a long time, use less command, meanwhile, will also press q to exit.

[Linuxidc @ localhost dirtest] $ cd dirtest1 ==> just built into subdirectories
[Linuxidc @ localhost dirtest1] $ touch testfile1 ==> Create a new file in a subdirectory
[Linuxidc @ localhost dirtest1] $ echo haha >> testfile1
[Linuxidc @ localhost dirtest1] $ cd .. ==> to return to the previous Directory
[Linuxidc @ localhost dirtest] $ ls
dirtest1 testfile
[Linuxidc @ localhost dirtest] $ cp testfile ./dirtest1/ ==> to copy the file to a subdirectory dirtest1 testfile
[Linuxidc @ localhost dirtest] $ cd dirtest1 / ==> enter into subdirectories
Under [linuxidc @ localhost dirtest1] $ ls ==> See more subdirectories one just copied files
testfile testfile1
[Linuxidc @ localhost dirtest1] $ cd ..
[Linuxidc @ localhost dirtest] $ ls
dirtest1 testfile
testfile file [linuxidc @ localhost dirtest] $ rm -f testfile ==> forcibly remove dirtest directory
[Linuxidc @ localhost dirtest] $ ls ==> testfile file has been deleted
dirtest1
[Linuxidc @ localhost dirtest] $ cd ./dirtest1/ ==> enter into subdirectories
[Linuxidc @ localhost dirtest1] $ mv testfile ./testfile ==> Here, I try to move the target directory error
testfile testfile1
[Linuxidc @ localhost dirtest1] $ pwd ==> so I want to see the current directory, use an absolute path
/ Home / linuxidc / dirtest / dirtest1
[Linuxidc @ localhost dirtest1] $ mv testfile / home / linuxidc / dirtest / ==> the testfile file to the directory dirtest
[Linuxidc @ localhost dirtest1] $ cd ..
[Linuxidc @ localhost dirtest] $ ls ==> well, testfile files have been moved over the
dirtest1 testfile
[Linuxidc @ localhost dirtest] $ ln -s testfile linkfile ==> softlinks
[Linuxidc @ localhost dirtest] $ ls -l ==> Note that the following soft link files are displayed
Total 20
drwxrwxr-x 2 linuxidc jzhou 4096 03-05 22:43 dirtest1
lrwxrwxrwx 1 linuxidc jzhou 8 03-05 22:45 linkfile -> testfile
-rw-rw-r-- 1 linuxidc jzhou 67 03-05 22:40 testfile
[Linuxidc @ localhost dirtest] $
rm files only difference between the role of the files and directories with the -r option is whether or not, because when you delete a directory, the directory which may have nested files and directories, so there must be -r option, cp and rm format are: cp / rm file original target file (Note that the routing problem)

ln link file: divided into soft links and hard links, symbolic links, also known as soft links, namely with the -s option. That soft link is a shortcut to the windows, if the original file is corrupted, invalid shortcuts, hard links and is equivalent to a copy of the original file, usually, rarely used hard links. So when you create a linked file, add the -s option that is usually the soft links. File Type-bit linker file is: l, subsequent notes will be introduced this file permission bits.

  Another point to note is: You can not establish a hard link to the file directory, and hard link to the original file must be in the same partition (file system).

[Linuxidc @ localhost ~] $ cd dirtest /
[Linuxidc @ localhost dirtest] $ ls
dirtest1 linkfile testfile
[Linuxidc @ localhost dirtest] $ tar cf test.tar dirtest1 testfile ==> archive directory and files
[Linuxidc @ localhost dirtest] $ ls ==> more than just a new archive test.tar
dirtest1 linkfile testfile test.tar
[Linuxidc @ localhost dirtest] $ rm -rf dirtest1 testfile ==> delete the original file, to facilitate later confirm whether filing
[Linuxidc @ localhost dirtest] $ ls
linkfile test.tar
[Linuxidc @ localhost dirtest] $ pwd ==> check the current directory, back to the archive solution in this directory
/ Home / linuxidc / dirtest
[Linuxidc @ localhost dirtest] $ tar xf test.tar -C / home / linuxidc / dirtest / ==> unlock the archive, testfile document released
[Linuxidc @ localhost dirtest] $ ls
dirtest1 linkfile testfile test.tar
[Linuxidc @ localhost dirtest] $ rm -f test.tar ==> Delete this archive package, back testing help
[Linuxidc @ localhost dirtest] $ ls
dirtest1 linkfile testfile
[Linuxidc @ localhost dirtest] $ gzip -9 testfile ==> Put this in gz file compression format
[Linuxidc @ localhost dirtest] $ ls
dirtest1 linkfile testfile.gz ==> this post is compressed automatically generated file name
[Linuxidc @ localhost dirtest] $ gzip -d testfile.gz ==> you just untie compression packages
[Linuxidc @ localhost dirtest] $ ls
dirtest1 linkfile testfile ==> see, testfile be extracted out
[Linuxidc @ localhost dirtest] $ bzip2 -9 testfile ==> Put this compressed file formats bz2
[Linuxidc @ localhost dirtest] $ ls
dirtest1 linkfile testfile.bz2 ==> Look, this is just generated bz2
[Linuxidc @ localhost dirtest] $ bzip2 -d testfile.bz2 ==> unlock this archive
[Linuxidc @ localhost dirtest] $ ls
dirtest1 linkfile testfile ==> see, it is released out
[Linuxidc @ localhost dirtest] $ tar jcf test.tar.bz2 testfile ==> This is the bz2 compressed archive format, note that the option is j
[Linuxidc @ localhost dirtest] $ ls
dirtest1 linkfile testfile test.tar.bz2
[Linuxidc @ localhost dirtest] $ rm -r testfile
[Linuxidc @ localhost dirtest] $ ls
dirtest1 linkfile test.tar.bz2
[Linuxidc @ localhost dirtest] $ tar jxf test.tar.bz2 -C / home / linuxidc / dirtest / ==> unlock compressed archive
[Linuxidc @ localhost dirtest] $ ls
dirtest1 linkfile testfile test.tar.bz2
[Linuxidc @ localhost dirtest] $ tar zcf test.tar.gz dirtest1 ==> This is the gz compressed archive format, note that options are z
[Linuxidc @ localhost dirtest] $ ls
dirtest1 linkfile testfile test.tar.bz2 test.tar.gz
[Linuxidc @ localhost dirtest] $ rm -rf dirtest1
[Linuxidc @ localhost dirtest] $ ls
linkfile testfile test.tar.bz2 test.tar.gz
[Linuxidc @ localhost dirtest] $ tar zxf test.tar.gz -C / home / linuxidc / dirtest / ==> unlock compressed archive
[Linuxidc @ localhost dirtest] $ ls
dirtest1 linkfile testfile test.tar.bz2 test.tar.gz
[Linuxidc @ localhost dirtest] $
The above command displays the format not very friendly, because in the real environment, if the original file is deleted, the soft link file can not be used on red background will become. But this does not affect the understanding Oh.

  Note that the archive file or directory just hit a bag, not compressed, and gzip and bzip2 compression is above the last lines of command after the combination of the two to use, that is, first compressed archive.

  tar and gzip bzip2 command format is as follows:

                 tar [option] ... archive source file or directory name == "Create archive
              tar [option] ... archive file name [-C target directory] == "unlock the archive

              gzip / bzip2 [-9] filename or directory == "Create archive

              gzip / bzip2 -d .gz archive / .bz2 format == "unlock the archive

     For the above command, only include the most simple usage, as to achieve greater functionality, using it to go to check what options with each command or man command directly to help those options too much, so I think Just know that there are a command, the specific usage when used to go check and did not need to remember all the options mean.

 

                                                       Common shortcut edit mode VIM editor

   Text editor can be used to create or modify text files, as well as maintenance of Linux systems in a variety of profiles. When first contact the editor due to unskilled but affect the efficiency of editing, but after master commonly used shortcuts, very rapidly. Here are just a brief introduction Vim editor For a more in-depth usage we can look online.

     Early Unix and Linux use the default text editor is Vi, are now using vi enhanced version of vim, because the more accustomed to using vi, so now still called vi, in fact, is an alias alias vi = '/ usr / bin / vim ', this can be seen through the command which vi.

     Vim editor has three modes of operation: command mode, input mode, the last line mode, some data may be said to have 2 operating modes, not to 'line mode' column in which this is not important, the total before two modes is really important; because in these two modes can do many things.

Conversion of these modes also very skilled.

Command mode basic operation:

 (1) display line numbers :: set nu cancel the line number:: set nonu

       Room (2) line Quick Jump: #G: jump to the file in the first # line; G: Jump to the end of the line in the file; 1G or gg: Go to the beginning of the file.

  (3) line Quick Jump: Home End

   Copy and Paste to delete :( command mode)

delete

x or Del

To delete a single character at the cursor

dd

Remove the current cursor line

#dd

# Delete lines from the cursor at the beginning of the

d ^

Delete all the characters before the cursor to the beginning of the current row

d $

Remove the current cursor position to the end of the line all the characters

copy

yy

Copy the contents of the current row entire row to the clipboard

#yy

# Copy lines from the beginning of the cursor

Stick

p

After pasting the contents of the buffer to the cursor position

P

Before pasted to the cursor position

 Find the file contents:

Operation keys

Features

/ Word

From the top down search string "word" in the file

? Word

From below, the search string "word" in the file

n

By locating a match for your search string

N

Positioning a matching search string

   Undo edit and save and exit:

u

Press once to cancel a recent operation

Press u repeatedly, multi-step recovery operation has been carried out

U

It used to cancel all edits made to the current row

ZZ

Save the current contents of the file and exit the vi editor

    Save the file and exit the vi editor :( line mode)

save document

 
: W / root / newfile

Save as other documents

Exit vi

: Q

Unmodified Exit

: Q!

Discard changes to the contents of the file and exit vi

Save the file exit vi

: Wq

 
    Replace the contents of the file :( line mode)

: S / old / new

Find the current line to the first character of the "old" string replaced with "new"

: S / old / new / g

The current line to find all the strings "old" replaced with "new"

: #, # S / old / new / g

Replace all strings "old" in the line number "#," range "new"

:% S / old / new / g

Replace all strings "old" in the whole range of documents "new"

: S / old / new / c

At the end of the command added c Replace command to replace every action will prompt the user for confirmation

To Proficiency Vim editor, first master these shortcuts, these are the most basic.

Rights management files and directories

Part I introduces some simple operations files and directories under, then describes how to manage users and file permissions. First, understand the user and group account profile, then manage user and group accounts, the last to be set up file and directory permissions and ownership.

     Linux-based user identity for resource access control. User accounts into super user root (the equivalent of Administrator windows under), then the average user. Linux is not recommended to use root login system to perform administrative tasks, because it is not safe. If accidentally deleted an important file system, it comes to an end.

     User Account file --passwd

Basic information is used to store user accounts, file location: / etc / passwd, each row corresponds to a user's account record, the following information is to take account of the last two rows, and then to analyze the meaning (of its field for each field room separated by a colon).

Field 1 linuxidc: user account name;

Field 2 x: Password placeholder

Field 3500: user account's UID number (RedHat and CentOS default from 500 begins)

Field 4 500: user account belongs to the primary GID number (default is 500 from the beginning)

Field 5 zhoujie: Full name

Field 6 / home / linuxidc: the user's home directory, home directory

Field 7 / bin / bash: login shell information

Based on system operation and management needs, all users can access the contents of the passwd file, but only the root user can change

User password file --shadow

To save the password string, password aging, and other information, file location: / etc / shadow, each row corresponds to a user's password record.

Name of the user account: Field 1

Field 2: encrypted password string information (using MD5 encryption)

Time of last modification password: Field 3

    Field 4: Minimum number of days a password, the default value 0

Field 5: Maximum number of days a password, the default is 99999

Field 6: how many days in advance to warn the user password is about to expire, the default value is 7

Field 7: Disable user password expires after the number of days (default is empty)

Field 8: Account expiration time (default is empty)

Field 9: Reserved field (not used)

   Default as long as the root user to read the contents of the document, and does not allow root directly edit the contents of the document. How to specify when you add user options to achieve these functions? The following briefly describes how to add users, groups.

Adding user accounts --useradd

 The initial user account profiles

Source files - when a new user account from / etc / skel copied from the directory

    The main initial user configuration files are:

     ~ / .bash_profile: Each time the user performs login
~ / .bashrc: Every time you enter a new execution environment Bash, the default setting some command aliases
  Each time the user logs out when executed: ~ / .bash_logout
 To view the contents of these documents through the cat command.
     Set / change a user's password --passwd
     Usually I do not have no need to explain each parameter with the command, but passwd I will introduce its meaning and usage parameters, because I think in system maintenance will be commonly used.
[Linuxidc @ localhost ~] $ su - root
Password:
[Root @ localhost ~] # passwd -l linuxidc ==> to lock the user account linuxidc
Locking password for user linuxidc.
passwd: Success
[Root @ localhost ~] # passwd -S linuxidc ==> To view the user status
linuxidc LK 2013-02-03 0 99999 7 -1 (Password locked.) ==> a locked state
[Root @ localhost ~] # tail -2 / etc / shadow ==> after the account lockout, there are wood found in front of more than two-bit password !!, the password is unavailable
linuxidc: !! $ 1 $ XRmjIBM9 $ SgXA00pPfvhjvxt / 9..Lh:. 15739: 0: 99999: 7 :::
user1: !!: 15771: 0: 99999: 7 :::
[Root @ localhost ~] # passwd -u linuxidc ==> to unlock the account linuxidc
Unlocking password for user linuxidc. ==> Has been successfully unlocked
passwd: Success.
[Root @ localhost ~] # passwd -S linuxidc ==> To view the user status again
linuxidc PS 2013-02-03 0 99999 7 -1 (Password set, MD5 crypt.)
[Root @ localhost ~] # tail -2 / etc / shadow ==> Observation password level changes, not two !!, the password can be used
linuxidc: $ 1 $ XRmjIBM9 $ SgXA00pPfvhjvxt / 9..Lh:. 15739: 0: 99999: 7 :::
user1: !!: 15771: 0: 99999: 7 :::
[Root @ localhost ~] # passwd -d linuxidc ==> linuxidc clear user passwords
Removing password for user linuxidc. ==> Password has been successfully cleared
passwd: Success
[Root @ localhost ~] # tail -2 / etc / shadow ==> Check password bit what changes
linuxidc :: 15771: 0: 99999: 7 ::: ==> Password changed bit empty. . .
user1: !!: 15771: 0: 99999: 7 :::
[Root @ localhost ~] # passwd linuxidc ==> reset passwords for users
Changing password for user linuxidc.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully ==> OK, the password has been set up successfully.
[Root @ localhost ~] #
Note that the "no password" user account has not completed initialization, in a non-logged, and "empty password" situation is different, ordinary users can use the passwd command, but can only change their own passwords. In addition, the locked account can not log into the system.

Modify user account properties --usermod

     It has several functions and passwd command is the same, such as L and U parameter is the lock and unlock the account, but capitalized. Other options for useradd and the like, is to change the uid, gid, etc.

Delete user accounts --userdel
      Directly on the line when you delete the account "userdel username", but this is deleted, the user's home directory still exists, then you have just to re-establish an account with the same name that is not enough, so I'm used to bring -r option, the point completely deleted, along with the home directory that is deleted together, anyway, after deleting the account home directory is also useless.
There are two domain group accounts related files, namely / etc / group and / etc / gshadow, less commonly used, especially the latter, should know the next on the list.
    Add a group account --groupadd

Add a group account, the new user, the user to specify the gid and group names, you must ensure that this group should exist, it must first establish a group, simple operation as follows:

[Root @ localhost ~] #groupadd -g 1000 test ==> Create a group gid 1000
[Root @ localhost ~] #tail -3 / etc / group
linuxidc: x: 500:
user1: x: 504:
test: x: 1000:
[Root @ localhost ~] #
     Delete group accounts --groupdel

     Very simple, direct access user name as a parameter, delete the group account in the / etc / group file from finding out the corresponding record.

User and group account inquiries:

     id Command - Query User Identity

     groups command - query the user belongs

finger command - query the user for more information

users, w, who logged on to the host command to query the user information

File / directory permissions and ownership of

      Ls will take a direct hit or parameter l ll command, you can view the user's right to use the file.

 The first column permission bits from 10 bits (such as d rwx rwx r-x), of which the first digit indicates the file type, d indicates a directory, l represents the linked file, b represents the block file, c represents the character file - indicates a regular file. About rwx- respectively, read, write, execute, without authority, rwx - four characters are the permissions may be expressed as octal numbers 4,2,1,0, ie rwx rwx rx permissions can also be expressed as 775, of which the first three bit rwx (7) indicates that the file owner (owner) of the file permissions, the middle three rwx (7) indicates that the group files are located (group) for the access to the file, the last three rx (5) represents another user ( other) permissions to the file, that ugo permissions.

--chmod Permission settings file / directory

[Linuxidc @ localhost dirtest] $ ll
Total 36
drwxrwxr-x 2 linuxidc jzhou 4096 03-05 22:43 dirtest1
lrwxrwxrwx 1 linuxidc jzhou 8 03-05 22:45 linkfile -> testfile
-rw-rw-r-- 1 linuxidc jzhou 67 03-05 22:40 testfile
[Linuxidc @ localhost dirtest] $ chmod g-w, o + group permission x testfile ==> settings file testfile and others permission to change permissions note
[Linuxidc @ localhost dirtest] $ ls -l
Total 36
drwxrwxr-x 2 linuxidc jzhou 4096 03-05 22:43 dirtest1
lrwxrwxrwx 1 linuxidc jzhou 8 03-05 22:45 linkfile -> testfile
-rw-r - r-x 1 linuxidc jzhou 67 03-05 22:40 testfile ==>, the authority changed
[Linuxidc @ localhost dirtest] $ chmod 644 dirtest1 / ==> dirtest1 change the directory permissions to read, write | read | read
[Linuxidc @ localhost dirtest] $ ll
Total 36
drw-r - r-- 2 linuxidc jzhou 4096 03-05 22:43 dirtest1 ==> found that it did not change the
lrwxrwxrwx 1 linuxidc jzhou 8 03-05 22:45 linkfile -> testfile
-rw-r - r-x 1 linuxidc jzhou 67 03-05 22:40 testfile
[Linuxidc @ localhost dirtest] $ chown linuxidc: root testfile ==> ordinary users do not have permission to change
chown: Change is "testfile" owner: Illegal Operation
[Linuxidc @ localhost dirtest] $ su root ==> to switch to the root user
Password:
[Root @ localhost dirtest] # ll
Total 36
drw-r - r-- 2 linuxidc jzhou 4096 03-05 22:43 dirtest1
lrwxrwxrwx 1 linuxidc jzhou 8 03-05 22:45 linkfile -> testfile
-rw-r - r-x 1 linuxidc jzhou 67 03-05 22:40 testfile
[Root @ localhost dirtest] # chown root: root testfile ==> testfile file owners and groups belong to root
[Root @ localhost dirtest] # ll
Total 36
drw-r - r-- 2 linuxidc jzhou 4096 03-05 22:43 dirtest1
lrwxrwxrwx 1 linuxidc jzhou 8 03-05 22:45 linkfile -> testfile
-rw-r - r-x 1 root root 67 03-05 22:40 testfile ==> see its file owner and owning group are changed to the root
[Root @ localhost dirtest] #
 Modify the directory permissions and belongs to the group -R option can be specified to achieve the files in the directory or directories can also be recursively changed. If only modify the file / directory by specifying the former owner, that chown root testfile, if only to modify the permissions on the file / directory belongs to the group, in front of the user may write that chown: root testfile.

Additional permission bits

Ordinary users do not have permission to modify the "/ etc / shadow" file, why you can modify their own password it? Temporary get the equivalent of an owner user (root) privileges because passwd command when the program is set SUID privileges, ordinary users execute the command.

     The main purpose of set bits permissions:

Executable (with x permission) file settings, permissions character "s";

When other users execute the file, the owner will have a group of users or permissions.

     Bit set permission types:
SUID: expressed an owner user permissions increase SET-bit;
SGID: expressed in the genus group of users to increase SET-bit access.
     
[Root @ localhost ~] # ls -l / usr / bin / passwd
-rwsr-xr-x 1 root root 19876 2006-07-17 / usr / bin / passwd
==> Ordinary users to the root user, indirect updated their shadow password file
Note: Do not set the permissions for the SET-bit executable files, especially those for the implementation of the program owner, is the root of the group, using the SET bit more authority should be careful. For example, if set SUID permissions for vim editor program, will lead to ordinary users can also use the vim editor to modify the system in any profile

      Sticky bit (Sticky)

       The main purpose:
Public directory (for example, permissions to 777) settings, permissions character "t"
 Users can not delete this directory other users' files
 
Due to the need systems and services running, Linux provides the / tmp, / var / tmp and other temporary directory that allows any user, write data, however Imagine, if any ordinary user can delete a system service use temporary files, What are the consequences? After setting the sticky bit, just to maintain a dynamic balance: to allow each user to arbitrarily write, delete data in the directory, but prohibits arbitrarily delete other users' data.
[Root @ localhost ~] # ls -ld / tmp / var / tmp
drwxrwxrwt 8 root root 4096 09-09 15:07 / tmp ==> t bit is to replace the execute bit x
drwxrwxrwt 2 root root 4096 09-09 07:00 / var / tmp
 In fact, those with special permission bit much, I think that just as several special file explanation fills do not get to the bottom, and know what to send on okay.

Use additional rights

The SET bit, sticky bit permissions
Permissions character
 chmod ug s executable file ...
 chmod o t directory name ...
Digital permissions:
 chmod mnnn executable file ...
 m is 4, corresponding to the SUID, 2 corresponds SGID, 1 corresponding to the sticky bit, can be superimposed
 
SET bit flag characters "s", if using octal digital form, the SUID corresponds to "4", SGID corresponding to "2"; can be "nnnn" in the form of permission mode, such as "4755" means set SUID permissions, "6755" means and set SUID, SGID permission.

The basic file and directory management, the next step is the disk and file system management. How to partition the disk and create a file system?

Adding disk and partition, create and mount the file system

1. Make sure the system disk commands --fdisk

fdisk -l [disk device]

[Root @ localhost ~] # fdisk -l ==> See all partitions currently in the system (results shown here and in interactive mode P commands are the same, talk back)

Disk / dev / hda: 21.4 GB, the file name and capacity 21474836480 bytes ==> Disk
255 heads, 63 sectors / track, 2610 cylinders ==> head, sector and cylinder size
Units = cylinders of 16065 * 512 = 8225280 bytes ==> each cylinder size

   Device Boot Start End Blocks Id System
/ Dev / hda1 * 1 13 104391 83 Linux
/ Dev / hda2 14 1288 10241437+ 83 Linux
/ Dev / hda3 1289 1925 5116702+ 83 Linux
/ Dev / hda4 1926 2610 5502262+ 5 Extended
/ Dev / hda5 1926 1989 514048+ 82 Linux swap / Solaris
Each of the field meanings:

Device: partition device file name Boot: Is the boot partition, the boot area, and if so, use the "*" logo

Start: Start cylinder, namely the partition on the hard disk start position End: the end of the cylinder, that is, the end position of the partition on the hard disk

Blocks: the size of the partition in Blocks (block) as a unit, the default block size is 1024 bytes, 1KB

Id: partition type ID tag number for EXT3 partition 83, LVM partition 8e System: partition type, the system disk partition

 

2, the hard disk partition plan --fdisk

fdisk [disk device]

Use this command to enter interactive manipulation, you can interactively manipulate the following abuses inside, but you must press the q command, you can not leave, remember that press w

# To find out where the root of the system where the disk, and access to relevant information about the hard disk inside
[Root @ localhost ~] # df / <== Key disk file name to find it
File system mount points 1K- block is Used Avail Use%
/ Dev / hda2 9920624 2968604 6439952 32% /
[Root @ localhost ~] # fdisk / dev / hda ==> enter the interactive manipulation mode, note here not to write a specific number

The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (E.g., DOS FDISK, OS / 2 FDISK)

Command (m for help): m <== waiting for input, m is the command menu
Command action
   a toggle a bootable flag
   b edit bsd disklabel
   c toggle the dos compatibility flag
   d delete a partition ==> delete a partition
   l list known partition types ==> create logical partitions
   m print this menu
   n add a new partition ==> to add a partition
   o create a new empty DOS partition table
   p print the partition table ==> display the partition table on the screen
   q quit without saving changes ==> are not stored directly leave fdisk program
   s create a new empty Sun disklabel
   t change a partition's system id to change the partition type
   u change display / entry units
   v verify the partition table
   w write table to disk and exit ==> will operate just write the partition table, careful operation
   x extra functionality (experts only)
  Common operations are: create a primary partition, create an extended partition (all remaining hard drive space as an extended partition), create logical partitions. System code, save the partition table information, to detect changes in the hard disk partition with partprobe

 The following includes a few test cases do not saved when you leave:

 Command (m for help): p ==> view disk partition table, and the role of the terminal fdisk -l command mode the same

Disk / dev / hda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors / track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot Start End Blocks Id System
/ Dev / hda1 * 1 13 104391 83 Linux
/ Dev / hda2 14 1288 10241437+ 83 Linux
/ Dev / hda3 1289 1925 5116702+ 83 Linux
/ Dev / hda4 1926 2610 5502262+ 5 Extended
/ Dev / hda5 1926 1989 514048+ 82 Linux swap / Solaris

Command (m for help): d
Partition number (1-5): 4 ==> Delete the first four partitions

Command (m for help): d ==> Delete the first three partitions
Partition number (1-4): 3

Command (m for help): p ==> displayed again observed below shows only the first two partitions, the first 5 did not show

Disk / dev / hda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors / track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot Start End Blocks Id System
/ Dev / hda1 * 1 13 104391 83 Linux
/ Dev / hda2 14 1288 10241437+ 83 Linux

Command (m for help): n ==> Create a partition
Command action
   e extended
   p primary partition (1-4)
p ==> choose to create partition primary partition type
Partition number (1-4): 4 ==> select partition No. 4 shots
First cylinder (1289-2610, default 1289):
Using default value 1289 ==> If the starting cylinder press enter key is to use the default values
Last cylinder or + size or + sizeM or + sizeK (1289-2610, default 2610): + 512M

Command (m for help): p ==> view the partition table again, we discovered more than just build a partition 4

Disk / dev / hda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors / track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot Start End Blocks Id System
/ Dev / hda1 * 1 13 104391 83 Linux
/ Dev / hda2 14 1288 10241437+ 83 Linux
/ Dev / hda4 1289 1351 506047+ 83 Linux

Command (m for help): n ==> to build a partition
Command action
   e extended
   p primary partition (1-4)
e ==> build extended partition
Selected partition 3 ==> this is the system partition active choice
First cylinder (1352-2610, default 1352):
Using default value 1352
Last cylinder or + size or + sizeM or + sizeK (1352-2610, default 2610):
Using default value 2610

Command (m for help): p

Disk / dev / hda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors / track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot Start End Blocks Id System
/ Dev / hda1 * 1 13 104391 83 Linux
/ Dev / hda2 14 1288 10241437+ 83 Linux
/ Dev / hda3 1352 2610 10112917+ 5 Extended ==> see just the new extended partition
/ Dev / hda4 1289 1351 506047+ 83 Linux

Partition table entries are not in disk order

Command (m for help): n ==> more built several partitions play, but do not save back on the line, huh, huh
First cylinder (1352-2610, default 1352):
Using default value 1352
Last cylinder or + size or + sizeM or + sizeK (1352-2610, default 2610): +2084
Value out of range.
Last cylinder or + size or + sizeM or + sizeK (1352-2610, default 2610): + 2084M

Command (m for help): n ==> Have not found, the last time the establishment of two partitions did not ask us to create a primary partition or an extended partition, why? Because the district has more than 400, you have no choice but to be extended partition. . .
First cylinder (1606-2610, default 1606):
Using default value 1606
Last cylinder or + size or + sizeM or + sizeK (1606-2610, default 2610):
Using default value 2610

Command (m for help): p

Disk / dev / hda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors / track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot Start End Blocks Id System
/ Dev / hda1 * 1 13 104391 83 Linux
/ Dev / hda2 14 1288 10241437+ 83 Linux
/ Dev / hda3 1352 2610 10112917+ 5 Extended
/ Dev / hda4 1289 1351 506047+ 83 Linux
/ Dev / hda5 1352 1605 2040223+ 83 Linux ==> This is followed by another two new partitions
/ Dev / hda6 1606 2610 8072631 83 Linux

Partition table entries are not in disk order

Command (m for help): q ==> q ah here we must act, because I have just demo operation, but also destructive deleted two partitions, if you really want to partition, it is saved according to w.

[Root @ localhost ~] #
After the disk is divided into many areas, to update the kernel, or you may use fdisk -l to see not change after the partition, can only restart. But using partprobe to force the kernel to re-find a partition table on the line.

[Root @ localhost ~] # partprobe [/ dev / hda] <== force the kernel to find once again the partition table, you can see immediately change partition
     NOTE: The normal user does not have permission to the hard disk partition, only the root user can, but the best is relatively safe in single-user mode, in addition, during the time of partition, a partition if the drive is in use among the most likely system Unable to load kernel hard disk partition table, the solution is to use partitions to uninstall and then re-partition once, re-write the partition table.

     3, create a file system in a partition --mkfs, mkswap

(1), mkfs

      Purpose: make filesystem, create a file system that is formatted

Format: mkfs -t partition device file system type (-t option could accept file system format, such as ext3, ext2, vfat, etc., usually does not require additional time option, because the system can automatically determine what file system is used )

Due to the above-described device / dev / hda3 has been mounted, and that I can not mount, but you can uninstall and then mount, not demonstration.

      (2), mkswap

Purpose: make swap, create a file system exchange system

Format: mkswap partition device

1) In the Linux system, the role of SWAP partition similar to Windows "virtual memory", a physical memory shortage situation can be alleviated to some extent
2) If the system does SWAP swap, or swap the existing capacity is not enough, you can create a swap file system via mkswap command to increase the virtual memory
3) swap space enabled, disable the need to use swapon, swapoff command, free command to view the physical memory usage, swap space
4) "swapon -s" command can also view usage of the swap partition
[Root @ localhost ~] # mkswap / dev / hda5 ==> Formatting swap partition
Setting up swapspace version 1, size = 526381 kB
[Root @ localhost ~] # swapon / dev / hda5 ==> enabled swap
[Root @ localhost ~] # free | grep -i swap ==> view swap space
Swap: 514040 0 514040
[Root @ localhost ~] # swapoff / dev / hda5 ==> Disable swap space
[Root @ localhost ~] # free | grep -i swap
Swap: 0 0 0
[Root @ localhost ~] #
      The new hard disk divided into many areas in the future, we need to format a partition (that is, create a file system), and mounted under the Linux system in the specified directory, and can be used to store files, directories and other data. And mount point must be a directory, which is the entrance into the file system. So, you have not any document can be used, must be mounted to the rear of a directory tree of a directory, you can use the file system.
4, mounting and unmounting file systems --mount, umount

(1) mount

Usage: mount a file system, ISO image to a specified folder

Format: mount [-t type] storage device mount point directory ( "-t type" option can usually be omitted, most Linux systems can automatically identify the corresponding file system type)

                mount -o loop ISO image file mount point directory

(2) umount

Uses: Removing a mounted file system
Format: umount storage location
                  umount mount point directory

(3) See Usage mounted partitions (df -hT)

[Root @ localhost ~] # df -hT ==> to view the existing partition hung usage
File system types available capacity has been used with a mount point%
/ Dev / hda2 ext3 9.5G 2.9G 6.2G 32% /
/ Dev / hda3 ext3 4.8G 195M 4.3G 5% / home
/ Dev / hda1 ext3 99M 11M 83M 12% / boot
tmpfs tmpfs 506M 0 506M 0% / dev / shm
[Root @ localhost ~] # mount / dev / hda3 / home / jzhou ==> the device / dev / hda3 mounted in the directory / home / jzhou under
[Root @ localhost ~] # df -hT ==> Check again to mount case
File system types available capacity has been used with a mount point%
/ Dev / hda2 ext3 9.5G 2.9G 6.2G 32% /
/ Dev / hda3 ext3 4.8G 195M 4.3G 5% / home
/ Dev / hda1 ext3 99M 11M 83M 12% / boot
tmpfs tmpfs 506M 0 506M 0% / dev / shm
/ Dev / hda3 ext3 4.8G 195M 4.3G 5% / home / jzhou ==> Look, here more than a mount point
[Root @ localhost ~] # umount / dev / hda3 ==> Uninstall just mount
[Root @ localhost ~] # df -hT ==> once again there is no view, has been successfully uninstalled
File system types available capacity has been used with a mount point%
/ Dev / hda2 ext3 9.5G 2.9G 6.2G 32% /
/ Dev / hda3 ext3 4.8G 195M 4.3G 5% / home
/ Dev / hda1 ext3 99M 11M 83M 12% / boot
tmpfs tmpfs 506M 0 506M 0% / dev / shm
[Root @ localhost ~] #
Also drive and mount the mirror only slightly different syntax is the same, the optical disc device is generally / dev / cdrom or / dev / hdc, mirroring Well, apparently iso compressed format, when you want to add the mirror mount -o loop option, the specific use of the Internet a lot.

      5, set the file system to automatically mount - to modify configuration files

System "/ etc / fstab" file can be viewed as the configuration file mount command, which includes the need to boot automatically after a mounted file system directory.

Check contents of this file as above, wherein the meaning of each field is as follows (the first three fields are important):

First field: Device Location

The second field: mount point directory

The third field: the file system type

The fourth field: Mount parameter, parameter back mount command "-o" option can be used

The fifth field: Indicates whether to dump the file system backup (dump is a backup tool), generally set to 1 indicates a need, set to 0 will be ignored by dump

      Sixth field: This number is used to determine the order of the disk check at system startup, 0 is not checked, the priority 1, 2 followed. For the root partition should be set to 1, the other partition is set to 2

   

Set automatically mount Example: that after each reboot, can be done automatically mount.

Enter vim edits, the device proc mount point from the / proc to / home / jzhou, save and exit

When it starts again, it will automatically mounted to the appropriate directory, the above is a demonstration, after I changed back.

 Explanation:

 After (1) in the / etc / fstab file correctly set the corresponding partition mounted automatically recording, manual mounting and unmounting the partition, simply specify the device name, mount point as an argument any one can, for example, Executive "mount / dev / sdb1" or "umount / mailbox" can complete the uninstallation
(2) mount command without any options, parameter, you can display the current system has been mounted file system information
 

        LVM brief
Logical Volume Manager, the Logical Volume Manager
Shielding the underlying disk layout, easy to dynamically adjust the disk capacity
(Note: p / boot partition for storing boot files, you can not use LVM mechanism)
 
1, the basic concepts of LVM System
(1) PV (Physical Volume, the physical volume)
 The entire hard drive, or use tools such as the establishment of common fdisk partition
 Including a number of default 4MB size of PE (Physical Extent, the basic unit)
(2) VG (Volume Group, Volume Group)
Overall combination of one or more physical volumes from the
(3) LV (Logical Volume, logical)
 Segmented from the volume group a space for a file system
 
Their logic is as follows

I think you already know why this LVM mechanism to exist, with most virtualization something similar to the role, the core or PV, that is the real physical volume, multiple physical volumes into one volume group is after these groups divided into volumes, then the PV completely unrelated, this can be a good use of space and capacity, and when a new physical volume is added, just to add a logical volume on the line. This mechanism is much like the division of VLAN network inside it.
 
    LVM administration commands are the following:

Features

Physical Volume Management

Volume Group Management

Logical Volume Management

Scan Scan

pvscan

vgscan

lvscan

Create establishment

pvcreate

vgcreate

lvcreate

Display Display

pvdisplay

vgdisplay

lvdisplay

Remove Remove

pvremove

vgremove

lvremove

Extend Extended

 
vgextend

lvextend


The main usage of the command:
pvcreate device name
vgcreate vgname physical volume name of a physical volume name 2
lvcreate -L size -n logical name of the volume group name
lvextend -L + Size / dev / vgname / logical name
 
The basic steps to create a logical volume: PV-> VG-> LV-> Format -> mounted file system use
Concrete steps :( my virtual machine can not demonstrate, bash is not the pvcreate command, as under simple theoretical explanation)
(1) conversion of physical volumes
1) planning two partitions using the fdisk command fdisk -l / dev / hda / dev / hdb | grep "LVM"
2) Use the pvcreate command to convert the aforementioned physical volume partition
pvcreate / dev / hda1 pvcreate / dev / hdb1
(2) create a volume group
vgcreate vg_test / hda1 / dev / hdb1
(3), create a logical volume
1) create a logical volume using the lvcreate command lv_test, aside from the volume group 10G space vg_test
  lvcreate -L 10G -n lv_test vg_test
2) Use the mkfs command to create an ext3 file system
mkfs -t ext3 / dev / vg_test / lv_test
(4), formatted as ext3 file system, and mount it to the directory / dirtest
mount / dev / vg_test / lv_test / dirtest
(5), the logical volume expansion can also
1) Use lvextend command logical lv_test expand capacity, from the volume group vg_test again to draw 10G logical lv_test
lvextend -L + 10G / dev / vg_test / lv_test
2) Use resize2fs command to update the system to recognize the file system size
resize2fs / dev / vg_test / lv_test

Management processes and scheduled tasks

 This still describes the Linux system administration basics, content boot process and operational level, management processes and services, set the schedule for the task of Linux to run as before, only briefly, in-depth section I continue learning, hope and learn together, if wrong, please give pointers.

One, Linux boot process

1, the system starts the boot process

First, the system POST, then the computer is turned on to access the hard disk and reads the first sector of the MBR (master boot directory), (Note: The master boot sector of the internal structure, 446 bytes of its content especially for the beginning of " master boot record "(MBR), followed by four 16-byte" partition table "(DPT), and 2-byte end marker (55AA). master boot record of the hard disk and the hard disk itself infos size and location information for each partition is an important entry data information. If it is damaged, the basic data structure of the information on the hard disk will be lost and need to use cumbersome way tentative reconstruction after the data structure information may revisit the original after the data.) read MBR record, then enter the system selection interface, after choosing an operating system, the kernel starts loading, then get control of the system from INIT process enters the initialization process, after you read the appropriate configuration files

  File system initialization process and brief

        1), INIT process and configuration files:

INIT process: loading the Linux kernel to run / sbin / init program, the system is the first process, the first program is the kernel to load, PID (process identifier) is always 1; configuration file is: / etc / inittab

    INIT process starts after launch other programs, generate new processes, these processes started by the init process init process is called the child, and the init process is the parent of these processes
2), inittab file structure:
Look at the contents of / etc / inittab configuration file:
 
[Root @ localhost ~] # grep -v "^ #" / etc / inittab | when grep -v "^ $" ==> to view this file to filter out comment lines and blank lines
id: 5: initdefault:
si :: sysinit: /etc/rc.d/rc.sysinit
l0: 0: wait: /etc/rc.d/rc 0
l1: 1: wait: /etc/rc.d/rc 1
l2: 2: wait: /etc/rc.d/rc 2
l3: 3: wait: /etc/rc.d/rc 3
l4: 4: wait: /etc/rc.d/rc 4
l5: 5: wait: /etc/rc.d/rc 5
l6: 6: wait: /etc/rc.d/rc 6
ca :: ctrlaltdel: / sbin / shutdown -t3 -r now
pf :: powerfail: / sbin / shutdown -f -h +2 "Power Failure; System Shutting Down"
pr: 12345: powerokwait: / sbin / shutdown -c "Power Restored; Shutdown Cancelled"
1: 2345: respawn: / sbin / mingetty tty1
2: 2345: respawn: / sbin / mingetty tty2
3: 2345: respawn: / sbin / mingetty tty3
4: 2345: respawn: / sbin / mingetty tty4
5: 2345: respawn: / sbin / mingetty tty5
6: 2345: respawn: / sbin / mingetty tty6
x: 5: respawn: / etc / X11 / prefdm -nodaemon
[Root @ localhost ~] #
 
  The meaning of each field:

id

Inittab file is used to uniquely identify a configuration record

runlevels

The record is used to specify which run level to run

action

What type of action is used to describe the recording will be performed

process

Command to start the process executed for

 
 id, also known as the flag field, composed of 1 to 4 characters for the configuration different from the other rows, so the id tag field must be unique
 runlevels, run level field for designating the recording operation in which operating level, the digital value of 0 to 6, will be explained in detail later
 action, action type field, action type field describes the configuration of the line corresponding to the category of operations, usually a fixed value, the more common types are as follows:
      initdefault: initialize the system set up after entering the default run level

      sysinit: Setting operating system initialization script

      wait: After the init process will wait for the line corresponding to the configuration script is complete, and then continue to perform other operations

      ctrlaltdel: set when the user presses Ctrl + Alt Delete key combination after the operation +

      powerfail: set what action to take when the system receives the signal power (uninterruptible power supply)

      powerokwait: set what action to take when the system receives the signal power is restored

      respawn: Once the line configuration corresponding to the process is terminated, then restart the process

 process, program or script field that is used to specify the actual operation of the line corresponding to the configuration can be specific commands, scripts, programs, etc.
 3), the other system initialization files Introduction

/etc/rc.d/rc.sysinit
Called for execution by the init process
And set up networking, host name, load the file system initialization clock and other settings (such as checking and enable disk quota feature is done in the script).
/etc/rc.d/rc script file
Called for execution by the init process
rc scripts are loaded by specifying different parameters and termination of different levels of system services, enter the corresponding system run level.
/etc/rc.local script file
By the rc script called for execution
rc.local script is usually carried out by the rc script at the end of loading, and its main function is to set the startup commands for administrators themselves provide a way usually will need to add some start with the system commands and scripts to the file. (User-defined command to save power needs automatically executed)
 
2, run level Linux system
 
1), run level refers to the different modes of running Linux system, each mode corresponding to different combinations of program services.
 
Seven default run level
0: off
1: single-user mode
2: multi-user mode interface characters (not supported by the network)
3: The character interface complete multi-user mode
4: Unassigned use
5: graphical multi-user mode
6: Restart
(Explanation: Linux system is in operation, each with a service used as "run level" to run level similar to the Windows system starts normally, safe mode, safe mode with networking support ...... concepts, different run levels using different combinations of program services, such as "packages" concept, M-zone SMS mobile phone charges $ 10 packages, 15 yuan music package)
2), adjust the default runlevel
Modify / etc / inittab file initdefault configuration, generally for the average user, runlevel is set to 5, that is the image of the operation, but for the server, the default is set to 3, the character interface, for the server, loading graphical interface is very resource intensive, affecting server performance.
[Root @ localhost ~] # vi / etc / inittab
After entering there is this line:
id: 5: initdefault: ==> this automatically means 5 graphics mode is to set the boot
3) to view the run level --runlevel
runlevel: displays Run level before switching and the current run level
If the switch temporarily run level, the init command is run in conjunction level parameters 0-6
 
[Root @ localhost ~] # runlevel ==> to view the current run level
N 5 ==> The first character is not switched before the "N" indicates the level of over-run
[Root @ localhost ~] # init 3 ==> run level to 3
[Root @ localhost ~] # Level runlevel ==> display before and after the reform
53
[Root @ localhost ~] # init 6 ==> Restart (here I pressed ctrl + C, or to restart the system)
[Root @ localhost ~] # init 0 ==> System Shutdown
 
3, the control system starts service

Start state 1), view the system services chkconfig --list [service name]

View network status such as the start of service, use: chkconfig --list network

2), the service script location: /etc/init.d -> /etc/rc.d/init.d

(/etc/init.d Is a symbolic link, the target is /etc/rc.d/init.d, these two can be found in the system directory service corresponding script file)

3), the state set up the system to start services chkconfig --level level list service name on | off

(Explanation: The list of run levels: either 235, 35,5, etc. form; Service Name: name you want to pay attention to the right, if you forget to see the name of the script /etc/init.d/ directory; On | off: Start or OFF ON state)

Such as setting up network services at 2345 levels for the startup state: chkconfig --level 2345 network on

When viewing its services again, you can see the network services enabled in each mode

4), ntsysv system service management tools --ntsysv [--level level list]

 This command to enter a similar graphical interface, you can centralize all system services settings

 

Use ntsysv and chkconfig command and the command to jump start the status comparison service description:

1) When you need to set up individual services at different run levels of start-up state, choose to use the chkconfig command to be more efficient

2) When a need to set up a large number of startup state service, choose to use ntsysv configuration tools to be more suitable

Second, process management

1, the difference between the program and the process

 Program: save hard disk, CD-ROM and other executable code and data media; static code stored

Processes: CPU and memory to run the program code; dynamic code execution; parent and the child: Every process can create one or more processes
2, view the process information

1), ps command

  Purpose: See static process statistics
Format: ps aux ==> display all system processes
                ps -elf ==> Display in long format

2), top command

        Purpose: view the dynamic process of ranking information
       Format: top
 3), pgrep command
Purpose: query process PID information based on specific criteria
 
[Root @ localhost ~] # pgrep "init"
1
[Root @ localhost ~] # pgrep -l "log"
2538 syslogd
2541 klogd
3221 login
[Root @ localhost ~] # pgrep -l -U teacher -t tty1
27483 bash
27584 vim
 
4), pstree command

   Purpose: The tree structure shows the relationship between the processes
Format: pstree [-aup]
 
3 different ways to start the process of
1) Start by hand
Reception start: user input commands directly execute the program
Background Start: End the command line by adding "&" symbol (ie, put this command in the background, after execution, will display a background task sequence number and a PID number)
[Root @ localhost ~] # ls -l &
[1] 28453 ==> background task No. 1 (to remember this, because wake up to use), PID No. 28453
2) scheduled start
      Using the at command, set at a particular time to perform a task
  Use the crontab command to set a fixed period (such as daily, weekly, etc.) to repeat a good pre-planned tasks
   Before and after the dispatcher 3), the process
ctrl + Z: suspend the current process, that is transferred to the background and stop execution
jobs: View the list of tasks in the background
fg: The recovery process in the background to the foreground, you need to specify the task ID
4) Run the termination process
Ctrl + C: interrupt command being executed
kill, killall: terminates the specified process used to kill PID number
killall terminates all processes for the specified name
-9 Option forcibly terminated
 
     Here is what I use the top command to get the processes that are currently running (part)

There are two top of the process, because I opened the two terminal, and then run the top command, if the top command I now want to kill the other terminal is as follows:
[Root @ localhost ~] # kill 3792 ==> In this case the amount of the other terminal will exit the top command
If you kill all the text files are open: killall -9 geidt

Terminate processes running --pkill command
 
[Linuxidc @ localhost ~] $ w | grep -v "root" ==> Check which users except root users outside the terminal in use
 11:17:38 up 1:18, 3 users, load average: 0.14, 0.05, 0.01
USER TTY FROM LOGIN @ IDLE JCPU PCPU WHAT
linuxidc: 0 - 10:01 xdm 18.56s 0.22s / usr / bin / gnome-??
linuxidc pts / 1: 0.0 11:17 0.00s 0.02s 0.01s w
linuxidc pts / 2: 0.0 11:17 10.00s 0.01s 0.01s bash
[Linuxidc @ localhost ~] $
 
There are 2 pts above, because I opened the two terminal, and are based on linuxidc user login, and now I want to stop pts / 1 in all processes:
 
[Linuxidc @ localhost ~] $ pkill -9 -t pts / 1 ==> This command Once running, pts / 1 This terminal will now close
When you view again only one pts / 2 on:
[Linuxidc @ localhost ~] $ w | grep -v "root"
 11:22:13 up 1:22, 2 users, load average: 0.09, 0.12, 0.05
USER TTY FROM LOGIN @ IDLE JCPU PCPU WHAT
linuxidc: 0 - 10:01 xdm 18.56s 0.22s / usr / bin / gnome-??
linuxidc pts / 2: 0.0 11:17 00.00s 0.01s 0.00s w
[Linuxidc @ localhost ~] $
  Third, the task management program

  1, at the command - a one-time task settings

  At a specified date and time to execute commands automatically pre-set operation, a one-time task plan
  Service Script Name: /etc/init.d/atd
  Formatting: at [HH: MM] [yyyy-mm-dd]
 
[Root @ localhost ~] # service atd start ==> start atd service
[Root @ localhost ~] # at 11:35
at> reboot
at> ==> press ctrl + D to submit the task, it is automatically entered here
job 1 at 2013-03-16 11:35
[Root @ localhost ~] # atq
1 2013-03-16 11:35 a root
==> Then I was depressed for a long time, because waiting for three minutes no results, I 11:30 set the scheduled task stands to reason that should have restarted, only to find the original virtual machine I clock and I your computer does not synchronize my computer faster for 5 minutes, ah. . . Waited in vain N-three minutes is constantly looking for reasons, the date command executed only found out now 11:30. . .
2, crontab command

 According to pre-set period of time (minutes, hours, days ......) Repeat the command given operation, cyclical Scheduled Tasks
(1), first look at the / etc / crontab file contents:
 
[Root @ localhost ~] # cat / etc / crontab
SHELL = / bin / bash
PATH = / sbin: / bin: / usr / sbin: / usr / bin
MAILTO = root
HOME = /
# Run-parts ==> here are provided per hour per day per week per month on a regular basis of the script tasks are stored in these directories
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
note:

Enable periodic task has a precondition that the corresponding system service crond must have been run;

Global Configuration and the default configuration does not require the user to modify the general content, users simply set up under / var / spool / cron / directory file with the same name to this account

(2) management plan cron task
Edit scheduled task: crontab -e [-u username]
View scheduled tasks: crontab -l [-u username]
To delete a scheduled task: crontab -r [-u username]
(Root user can manage the user specified scheduled task; ordinary users can only manage their own scheduled task)
(Note: Users only need to execute "crontab -e" command will automatically invoke a text editor (default is vi) and open the "/ var / spool / cron / username" file, without having to manually specify the file location)
 
 (3), crontab simple application example
1) Example 1: root user
Requirements: 7:50 every morning automatically open sshd service, closed 22:50
Emptied once every five days public FTP server directory / var / ftp / pub
Every Saturday at 7:30, restart the httpd service
Every Monday, 17:30 three, five, packages, backup / etc / httpd directory
[Root @ localhost ~] # crontab -e
50 7 * * * / sbin / service sshd start
50 22 * * * / sbin / service sshd stop
0 * * / 5 * * / bin / rm -rf / var / ftp / pub / *
30 7 * * 6 / sbin / service httpd restart
30 17 * * 1,3,5 / bin / tar jcvf httpdconf.tar.bz2 / etc / httpd
2) Example 2: linuxidc user

Demand: every Sunday night at 23:55 copy the contents of "/ etc / passwd" file to the home directory, the file is saved as pwd.txt
[Root @ localhost ~] # crontab -e -u linuxidc
55 23 * * 7 / bin / cp / etc / passwd /home/linuxidc/pwd.txt
3), Example 3:

root users to view your list of scheduled tasks; view and delete scheduled tasks linuxidc user settings
[Root @ localhost root] # crontab -l
50 7 * * * / sbin / service sshd start
50 22 * * * / sbin / service sshd stop
0 * * / 5 * * / bin / rm -rf / var / ftp / pub / *
30 7 * * 6 / sbin / service httpd restart
30 17 * * 1,3,5 / bin / tar jcvf httpdconf.tar.bz2 / etc / httpd
[Root @ localhost root] # crontab -l -u linuxidc
55 23 * * 7 / bin / cp / etc / passwd /home/linuxidc/pwd.txt
[Root @ localhost root] # crontab -r -u linuxidc
[Root @ localhost root] # crontab -l -u linuxidc
no crontab for linuxidc
[Root @ localhost root] #
 

From the above three examples briefly summarize configuration format crontab tasks:

(1) Time period settings: Task content settings:

50 3 2 1 * run_command

Minute hour date month week command

Field

Explanation

minute

The value is an arbitrary integer between 0-59

hour

The value is any integer from 0 to 23

date

The value is an arbitrary integer from 1 to 31

month

The value is any integer between 1 and 12 from

week

The value is any integer from 0 to 7, 0 or 7 represents Sunday

command

Command or script to execute

 

The time pattern of the first five fields specify the task to repeat, the first six field specifies the specific tasks content

crontab task configuration record, the command set in the "minutes + hour + date + month + week" will not satisfy the conditions of operation.

(2), the time value of special representation
* Indicates any time within this range
Representing a plurality of spaced discrete time points
- Represents a continuous time
/ Time interval specified frequency
Application examples:
017 * * 1-5 Monday through Friday 17:00
308 * * 1,3,5 every Monday, Wednesday and Friday 8:30
08-18 / 2 * * * every two hours between 8:00 to 18:00
* * 0/3 * * every 3 days

With the windows operating system, the use of an operating system, it must install some software, this essay focuses on Linux software installation. First, we should understand the composition of Linux applications, familiar management mechanism RPM package, then RPM package management is to use the tools, and compiling packages from source to install the application.

A, Linux Applications Introduction

1, Linux command relationship with an application

(1), File Locations

System Command: Usually in / bin and / sbin directories, or Shell internal instruction
Applications: usually / usr / bin and / usr / sbin directory
(2), the main purpose
System Command: complete the system's basic management tasks such as IP configuration tools
Application: Complete relatively independent of other supporting tasks, such as web browsers
(3), for the environment
System Command: Usually only run in the character the user interface
Application: according to actual needs, some programs can be run in a graphical interface
(4), run format
System Command: Usually includes a command word, command option and command parameters
Applications: Typically there is no fixed format execution
(Personal understanding: strict distinction in Linux commands and programs are not much sense, for the "Install Packages" and "Install Applications" these two arguments, it does not make a strict distinction)

2, the composition of Linux applications

This part of the Linux directory hierarchy has a close relationship, listed below is the directory structure of a typical application:

file type

Save Directory

Normal execution file

/ Usr / bin

Server execution files and manage files

/ Usr / sbin

Application configuration file

/ Etc

Log Files

/ Var / log

Application Documents

/ Usr / share / doc

Application manual page file

/ Usr / share / man

If an application configuration file more often create a special sub-files folder to save the software name, such as "/ etc / httpd"

For example, when viewing the sendmail package, execute rpm -ql sendmail view.

3 packages package type

There are a variety of package types, common RPM package, the extension ".rpm", the source code package, the original is usually compressed package ".tar.gz", ". Tar.bz2" format that contains procedures Code; two more commonly used. Others have deb package, the extension ".deb", provided the package installer, usually file install.sh, setup, .bin format, similar to the windows installation exe files, as well as green-free installation package within the compressed package provides precompiled execution file, unzip the file after the package can be used directly. (Note: Use the tar command made the source code package files, often referred to as "TarBall", namely "Tar package")

Second, use the RPM package management tools

1, RPM Introduction

PRM: RedHat Package Manager, because the RPM package format is the format of the key first proposed by the company and used by Red Hat, after widespread use. It establishes a unified database files, a detailed record of the package installation, uninstallation and change information, it can automatically analyze package dependencies.

The general format of the RPM package: bash-3.1-16.1.i386.rpm (software name, version number, release number, hardware platform, and the extension)

Of course, this format is not fixed, because sometimes may also be combined with the applicable operating system information, such as: wget-1.10.2-7.el5.i386.rpm

2, using the RPM package management commands

The main function of RPM command is:

(1) Related Information Discover RPM software package file
Discover RPM software information installed: rpm -q [sub-option] [software name]
Query file / directory belongs to which software RPM: rpm -qf file / directory name
When general inquiries; use "-q" option actually calls the "/ usr / bin / rpmquery" procedure is completed inquiries for "-qa" query options, command parameters (ie, the package name) is non-mandatory: (Remarks software name need not specify a version number)
[Root @ localhost ~] # rpm -q bash ==> check whether the package is already installed bash
bash-3.1-16.1
[Root @ localhost ~] # rpm -qa | grep bash
bash-3.1-16.1

[Root @ localhost ~] # rpm -qf / usr / bin / vim ==> Discover vim which package is installed
vim-enhanced-7.0.109-3

[Root @ localhost ~] # rpm -ql dhcp ==> Discover the list of files installed by the package dhcp
/etc/dhcpd.conf
/etc/rc.d/init.d/dhcpd
......
Discover RPM package file is not installed: rpm -qp [sub-option] [RPM package file]
Usage: a combination of different sub-options to complete the different queries
-qpi: View details of the software by .rpm package file
-qpl: View .rpm installation package contains the directory, file list
-qpc: View profile within .rpm package contains a list of
-qpd: View a list of documents within the file .rpm installation package contains
[Root @ localhost Server] # rpm -qpl lynx-2.8.5-28.1.i386.rpm
/etc/lynx-site.cfg
/etc/lynx.cfg
......
==> Discover lynx installation package file list
(2) Install, upgrade, uninstall RPM packages
RPM install or upgrade software: rpm [options] [RPM package file] ...
Usage: different options for different situations
 -i: install a new rpm package
 -U: An rpm upgrade software, if the original is not installed, then install it
 -F: Update a software rpm, if the original is not installed, then abort the installation
Uninstall software specified RPM: rpm -e name of the software (Note: only need to specify the name of the software when you can uninstall the software, without having to specify the version number)
 Accessibility brief:
--force: force the installation package rpm specified
--nodeps: install, upgrade or uninstall the software, ignoring dependencies
-h: the "#" sign shows the progress of the installation
-v: Displays detailed information about the installation process
 (Note: - force Accessibility Options used in the following two situations:
    1) deletion of files in a package, you need to cover the installation to retrieve lost files

    2) Install a software version older than the current package (mostly for testing purposes)

  When installing, uninstalling the package, suggesting that the lack of dependencies can not be, If you still want to continue, it should not be combined with option --force --nodeps option)

[Root @ localhost ~] # rpm -ivh lynx-2.8.5-28.1.i386.rpm ==> install a new RPM package
warning: lynx-2.8.5-28.1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing ... ########################################### [100% ]
   1: lynx ########################################### [100%]
==> Install package lynx colleagues show installation progress
[Root @ localhost ~] # rpm -q lynx
lynx-2.8.5-28.1
[Root @ localhost ~] # rpm -e lynx ==> Uninstall lynx Packages
[Root @ localhost ~] # rpm -q lynx
package lynx is not installed
 (Note: "warning: ...... NOKEY ......" warning message is due to RedHat provide not import the public due, but does not affect the installation effects can be ignored, if you need to import the public key file, you can refer to the following steps (after RHEL5 install the software from the CD, it will not happen again warning prompted): [root @ localhost ~] # cd / media / cdrom

[Root @ localhost cdrom] # rpm --import RPM-GPG-KEY-redhat-release)

[Root @ localhost ~] # rpm -i wget-1.10.2-3.2.1.i386.rpm
[Root @ localhost ~] # rpm -q wget
wget-1.10.2-3.2.1
[Root @ mail ~] # rpm -Uvh /media/cdrom/wget-1.10.2-7.el5.i386.rpm ==> Upgrade package wget
warning: /media/cdrom/wget-1.10.2-7.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing ... ########################################### [100% ]
   1: wget ########################################### [100%]
[Root @ localhost ~] # rpm -q wget
wget-1.10.2-7.el5
(Note: when upgrading a package does not exist in the system, upgrade command is functionally equivalent to the installation command)

Resolve package dependencies:

1), equipped with a plurality of software dependencies
Is dependent packages need to be installed
Specify multiple .rpm package file to install
(NOTE: If you need to install dozens of interdependence .rpm package, you can combine Shell "*" wildcard specify these files as parameters)
2), uninstall the dependencies of multiple software
Relies on other packages need to uninstall the program
Specify multiple names uninstall software
3), ignoring dependencies
Binding "--nodeps" option, but it may cause the software exception
 (3) Maintenance RPM database information
 When the RPM database corruption, we need to rebuild the database: rpm or --rebuilddb rpm --initdb

Third, the package compiled from source Installer

1, source compiler Profile

Now that you have RPM installed, then why you need the source code to install it? First, it can obtain the latest version of the software, timely repair bug; then it was according to user needs, the flexibility to customize the software functions. It is also widely used applications, such as when you install a newer version of the application, the installation program can not meet the current or when you need to add new functionality to your application when needed and so on.

Tarball Packet: mostly .tar.gz or tar.bz2 formats.

Confirm the source code compiler environment:

You need to support C / C ++ programming language compiler.

[Root @ localhost ~] # gcc --version ==> or g ++ -v [--version]
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)
Copyright (C) 2006 Free Software Foundation, Inc.
This program is free software; see the source of the copyright notice. This software is no guarantee;
Including warranties of merchantability and no applicability under a special purpose.
[Root @ localhost ~] # g ++ --version
g ++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)
......
(Note: The actual build and install the software operation, in most cases by automatically make calls gcc or g ++ to work without having to manually execute commands such as gcc)

2, the installation program from source basic process

Unpack - tar
    Unpacking, releasing the source code files
Configuration - ./configure (configure usually located in the package directory executable script file)
    For the current system, software environment, configure the installation parameters
Compile - make
    The source code files into a binary executable program
Installation - make install
    Copy the compiled program files to your system
  3, source code compiler installation program example
1), unpack
(Customary to release the package to / usr / src / directory; the location of the source code files unpacked: / usr / src / name of the software - version /)
 
[Root @ localhost ~] # tar zxvf axel-1.0a.tar.gz -C / usr / src /
[Root @ localhost ~] # ls /usr/src/axel-1.0a/
API axelrc.example configure CREDITS gui nl.po tcp.c
axel.1 CHANGES conn.c de.po http.c README tcp.h
axel.c conf.c conn.h ftp.c http.h search.c text.c
axel.h conf.h COPYING ftp.h Makefile search.h

==> Configure execution of the script for the next configuration, README or INSTALL file provides installation methods
2), the configuration

(On the working directory to the directory where the software source code; use the source directory configure script; execute "./configure --help" to find help; a typical configuration options: --prefix = Install directory)

[Root @ localhost ~] # cd /usr/src/axel-1.0a
[Root @ localhost axel-1.0a] # ./configure --prefix = / usr / local / axel
==> If not specify any options, the default value
(Note: different application of its configuration parameters there are differences, so learn to use "./configure --help" very important ( "./" means the current directory); mounted to "/ usr / local application on the user habits / software name "folder; If an error occurs during compilation, usually due to missing dependencies due packages; depending on the size of the software, the configuration process may take a different time)

3) compile: make command

4), the installation: execute make install command

[Root @ localhost axel-1.0a] # make
[Root @ localhost axel-1.0a] # make install
Verify that the compiled program installation is complete:

 
[Root @ localhost axel-1.0a] # ls / usr / local / axel / / usr / local / axel / bin /
/ Usr / local / axel /:
bin etc share
/ Usr / local / axel / bin /:
axel
[Root @ localhost axel-1.0a] # / usr / local / axel / bin / axel -help
Usage: axel [options] url1 [url2] [url ...]
--max-speed = x -s x Specify maximum speed (bytes per second)
......

Acquaintance Shell - bash

Linux is somewhat similar to the shell under cmd.exe Windows or .bat. Manage the entire computer hardware is actually an operating system kernel (Kernel), the user can not directly interact with the kernel, with the kernel through the shell to communicate. That shell between the operating system (Kernel) and users, it is the user and kernel interpreter, is a command interpreter.

Common shell types are: Bsh, Csh, Ksh, Bash, Zsh

Bsh and Csh appeared earlier, Ksh inherits its two features, Bash inherits upgraded version Bsh and Ksh, but also Linux system default shell, Zsh is both a variety of shell program a little, interactive operation more efficient, but still not widely applied and bash.

Shell Environmental switch:

Login Shell: refers to the user after each login system automatically loads the Shell program, most Linux systems use / bin / bash as the default login Shell; / etc / shells file records system supports valid login Shell

 
[Root @ localhost ~] # cat / etc / shells ==> use chsh -l command can also view
/ Bin / sh
/ Bin / bash
/ Sbin / nologin
/ Bin / tcsh
/ Bin / csh
/ Bin / ksh
[Root @ localhost ~] #
The default shell is bash, then how to switch the shell environment? Divided into two types, one is the temporary switch, that is, when the terminal is closed, the next start is still bash, the method is very simple, enter the name of the shell directly in the terminal; the second is to change the user login Shell, need to modify / etc the final field / passwd file the user record, or as previously mentioned use to modify the user's command: usermod -s shell program path to the user name, you can also use the chsh command, effective next logon.

View the current shell can be viewed through the / etc / passwd, you want to view the system's default shell, you can use echo $ SHELL.

bash common features:

1) Tab key automatically filled
This feature allows you to play a lot fewer words, and determines whether the input is correct. tab bonded after the first word of the command string, for the command completion; the second word later if connected to a string of commands, for the file completion; direct prompt, double-click the tab key in bash , you can display all executable commands.
2) command to edit shortcuts
As mentioned before ctrl + D, ctrl + L, ctrl + U, etc.
3) Command History
Save the user who executed the command operation; storage location is: ~ / .bash_history hidden files; just use the View command history command history on the line.
Call history command:
! N: execution history of the n-th order
! Str: History to "str" the beginning of the command
Historical records set several commands: Modify HISTSIZSE parameters can be (in the / etc / profile file), the default is 1000.
(Note: The correct usage history command to improve the command line input efficiency, such as: the future, if the recently performed "service network restart" command, then re-modify the network card configuration file, usually only need to perform "ser!" Operation that is this history can be invoked command to restart the network service several reasonable historical control commands can improve security, root user's command history is generally recommended to be less than 100)
4) command aliases
 To use the command line to set a higher complexity of intermittent call name, storage location is: ~ / .bashrc hidden files. Simply view the command alias alias command.
(Note: the alias manually using the alias command set is only valid in the current Shell environment, such as alias rm = 'rm -i'; For each alias settings when you log Shell environment are valid, you need to modify the host directory. " bashrc "file, add the appropriate alias settings)
5) Standard Input Output
Interactive hardware:
Standard input: receiving user input data from the device
Standard output: the output data to the user through the device
Standard Error: execution error message through the device report
Types of

Device file

File Description Number

Default Device

Standard Input

/ Dev / stdin

0

keyboard

Standard output

/ Dev / stdout

1

monitor

Standard error output

/ Dev / stderr

2

monitor

(Note: / dev / stdin, / dev / stdout, / dev / stderr these three documents is a symbolic link, input and output redirection close relationship)

6) redirection
Change the standard input, standard output, standard error of direction:
Types of

Operators

use

Redirecting standard input

<

The way the command receives the input is changed from the default keyboard for the specified file

Redirect standard output

>

The command execution results are output to the specified file, rather than displayed directly on the screen

>>

The results of the additional output command to the specified file

Redirect standard error

2>

Empty the contents of the specified file and saves the information to the standard error file

2 >>

The standard error message appended to the specified file

Redirect standard output

Standard error

&>

The standard output, standard error, save all the contents to the specified file, rather than displayed directly on the screen

7) Pipeline Operation
Pipeline operator symbol is "|", connect the left and right commands, the results will be the output of the left command as input for the right command (processed). Pipeline is a feature of the scripting language that can speak multiple functions connected together to form a large functional, object-oriented and this is very different.

For example, I now want to view the history of the command line 4: 4 before you can first command is displayed in the last four shows before a command: history | head -4 | tail -1 so that is taken out of the fourth command.

Shell Variables

Shell variables and other variables Meaning Language similar, that can be stored in different content, it also provides specific parameters for the flexible management of Linux systems. Usually there are two meanings: the variable names: use a fixed name, preset by the system or user-defined; variable values: the user can set the system environment changes.

Shell variable types:

User-defined variables: defined by the user, modify and use
Environment variables: maintained by the system, is used to set the user's Shell environment, only a handful of users can modify variables
Predefined variables: predefined Bash special variable, not directly modify
Position variable: the execution parameters passed to the program via the command line, such as ls -l / etc / httpd, which the latter two parameters can be regarded as positional parameters.
Assignments and references variables:

To define a new variable names start with an English letter or an underscore, a case-sensitive format: variable name = variable value

Check the value of a variable: echo $ variable name

[Root @ localhost ~] # DAY = Sunday
[Root @ localhost ~] # echo $ DAY ==> variable name specified by $ symbol reference value
Sunday
[Root @ localhost ~] #
(Note: When viewing variable, if the variable name is easy, and the string back together to cause confusion, you should use curly braces to enclose the variable name, use the form: $ {variable name}, for example: If the known variables Var value Benet, "echo $ Var3.0" command is executed after the results show ".0" rather than "Benet3.0", because in the order, will be "Var3" as a variable name (the default is undefined this variable). If you want to correctly display "Benet3.0" the output, you need to do "echo $ {Var} 3.0")

[Root @ localhost ~] # Var = Benet
[Root @ localhost ~] # echo $ Var
Benet
[Root @ localhost ~] # echo $ Var3.0
.0
[Root @ localhost ~] # echo $ {Var} 3.0
Benet3.0
[Root @ localhost ~] #
Input from the keyboard to the variable assignment, the format is: read [-p "Enter message"] variable name

[Root @ localhost ~] #read var
haha ==> here waiting for input
[Root @ localhost ~] #echo $ var
haha
[Root @ localhost ~] #
When variables are assigned using the difference between the different quotes to:

1) When using double quotation marks, allows the use of "$" symbol reference values of the other variables in the range of double quotes (variable reference)
2) When using single quotes, references will not allow the value of the other variables in single quotes range of "$" symbol, or any other symbol to look as ordinary characters
 
[Root @ localhost ~] # name = linuxidc
[Root @ localhost ~] #echo $ name
linuxidc
[Root @ localhost ~] #myname = "$ name is me" ==> here is double quotes
[Root @ localhost ~] #echo $ myname
linuxidc is me ==> will be executed out of the $ name variable
[Root @ localhost ~] #myname = '$ name is me' ==> here using single quotes
[Root @ localhost ~] #echo $ myname
$ Name is me ==> displayed as a, $ name is not performed
[Root @ localhost ~] #
 
3) When using the anti-apostrophe, allowing to perform a specific output of the command assigned to the variable (command substitution), anti-apostrophe in the content requires executable commands. You need nested, you can be anti-apostrophe to $ (...) form
     So to speak, in a string of commands within the `command will be executed first, and then execute it as a result of external input information.
 
[Linuxidc @ localhost ~] $ locate crontab
/ Etc / anacrontab
/ Etc / crontab
/ Usr / bin / crontab
/usr/share/man/man1/crontab.1.gz
.....
[Linuxidc @ localhost ~] $ ls -l `locate crontab` ==> perform locate crontab, then execute ls -l
-rw-r - r-- 1 root root 298 2006-12-18 / etc / anacrontab
-rw-r - r-- 1 root root 255 2006-07-15 / etc / crontab
-rwsr-sr-x 1 root root 315416 2008-07-15 / usr / bin / crontab
-rw-r - r-- 1 root root 1846 2008-07-15 /usr/share/man/man1/crontab.1.gz
.....
[Linuxidc @ localhost ~] $
 
 Set the variable scope, format: export variable name

 Under normal circumstances, custom variables of the parent process can not be used in the child, but after the adoption of export variable into the environment variable, can be used in the child process.

 
[Root @ localhost ~] # name = linuxidc
[Root @ localhost ~] #echo $ name
linuxidc
[Root @ localhost ~] # export name ==> output as global variables
[Root @ localhost ~] # zsh
[Root @ localhost] ~ # echo $ name
linuxidc
[Root @ localhost] ~ # exit
[Root @ localhost root] # unset name ==> eliminate variable content
[Root @ localhost root] # echo $ name

[Root @ localhost ~] #
There is also a variable benefit, when you frequently visit a directory, and this directory is relatively long, it can be a simple variable pay, so just cd into this directory when the variable on the line. As work = "~ / temp / 2013 / test /", then simply enter the directory cd work.

Numeric variable operation:

Mentioned before that you can use to open a command bc calculator, in fact, Bash program not suitable for powerful mathematical operations such as decimal or exponential operation, usually only a simple integer operations, without using bc, you can also use the following format for simple numerical calculation:

Format: expr variable 1 variable 2 operator [.. operator variable n ...]

expr command commonly used operators are: +, -, \ * (Note that only \), /,%

[Linuxidc @ localhost ~] $ expr 10 * 2
expr: syntax error
[Linuxidc @ localhost ~] $ expr 10 \ * 2
20
[Linuxidc @ localhost ~] $ expr 10 + 2
12
[Linuxidc @ localhost ~] $
Environment Variables

   Profile environment variables: global configuration file: / etec / profile

User Profiles: ~ / .bash_profile

View the environment variables: env

    set (set command to see all of Shell variables, including environment variables)

Common environmental variables:

$ USER, $ LOGNAME variable represents the current user's login name
$ UID variable represents the current user's UID number
$ SHELL variable represents the user's login Shell
$ HOME variable represents the user's home directory
$ PWD variable represents the user's current working directory
$ PS1 and $ PS2 variable representing the current user's primary prompt (command prompt) and secondary prompt (for example, to perform at the command post ">")
Position variable:

    He expressed as $ n, n is a number from 1 to 9 between the role of $ n parameter is passed execute the script file.

    When using the ls command, ls command program How do I know whether the user has entered the "-l", "- a" option? How do you know which user wants to view the catalog? It is the position of the variable used to solve this problem, it can be entered at the command line parameters you copied to a particular variable, and then handed over to the program to deal with
(For example, when executing "service network restart" command line, with the first one positional parameters "$ 1", corresponding to a value of "network", with the first two positional parameters "$ 2", corresponding to a value of "restart" ; when the position of user input parameters over 9, the position variable $ 9 will automatically include all the last part of the string (even if there is a space-delimited))
[Linuxidc @ localhost ~] ls -a -l -l ==> a position variable is the first one, and so, in fact, this command is ls -al
 Predefined variables:

[Root @ localhost ~] # bash
[Root @ localhost ~] # echo $ 0 $$ ==> view the name of the currently executing process, PID number
-bash 32484
[Root @ localhost ~] # exxit ==> execute a bad command
bash: exxit: command not found
[Root @ localhost ~] # echo $?
127 ==> returns a non-zero value, indicating that the previous command exception
[Root @ localhost ~] # exit
exit
[Root @ localhost ~] # echo $?
0 ==> returns 0 if the previous command normal
   Flexibility in the use of these variables will significantly enhance Shell scripting features, $ 0 for the predefined variables, indicating the name of the currently executing program, we need to position $ 1 to $ 9 variables distinguish.

 Introduction of shell scripts

     shell script:

Purpose: to complete a specific, more complex system administration tasks
Format: centralized save multiple Linux commands, plain text files
Implementation modalities: according to a preset order of interpreted
(Shell script similar to the Windows system .bat batch file, simply have the appropriate command interpreter, do not need to compile
  Shell scripts in order to complete certain administrative tasks to create, so the script file each command is not just haphazard placement and require users to organize and design)
 
 Build script file contains the statement is executed:
[Root @ localhost ~] # vi repboot.sh
#! / Bin / bash ==> Statement of the shell environment, according to the different modalities of implementation can be added from time to increase
# To show usage of / boot directory and mode of kernel file.
echo "Useage of / boot:"
du -sh / boot
echo "The mode of kernel file:"
ls -lh / boot / vmlinuz- *
[Root @ localhost ~] # chmod a + x repboot.sh
Shell script file extension is not critical constraints do not necessarily have to be ".sh" at the end, just for easy identification
 
Run Shell script:
Execute the script file with the "x" permission directly
    For example: ./ repboot.sh
Using the specified interpreter program execution script contents
    For example: bash repboot.sh, sh repboot.sh
A read command script content by source (or.)
    For example:. Souce repboot.sh or hello.sh
(Note:
During the commissioning phase can be called directly using the Shell script file, the script is not required to have executable permissions, the format is: bash script name
After setting the property executable script file, the command line in the Shell scripts can be executed directly through the path of the script file
Use the Bash internal command. "" When the script file is executed, it will not open a new Shell environment. When using this approach, as the script file. "" Arguments to the command, so the same is not required to have executable permissions. )

Simple syntax for writing Shell scripts

Mentioned program, conditions, branches, loops, and other grammar certainly missed. shell scripting too, was just below combined with some simple grammar recent study did note, if wrong, please correct me.

if conditional statement

Conditional test operation

test command:

Purpose: to test specific expression is established when the condition is satisfied, the return value is 0 after the command is executed, otherwise other values

Format: test or conditional expression

[Conditional expression] (Note: You need at least one space between brackets [] and conditional expression statements)

Common types of tests: Test file status; string comparison; integer comparison; logic test

Test file status: [operator file or directory]

Common test operators
-d: test whether a directory (Directory)
-e: test directory or file exists (Exist)
-f: test whether a file (File)
-r: to test whether the current user has permission to read (Read)
-w: tests whether the current user has permission to write (Write)
-x: test whether the current user can perform (Excute) the file
-L: Testing whether the symbolic link (Link) file
How to determine where the current working directory is / usr / src?
[$ PWD = "/ usr / src"] && echo "YES" || echo "NO"
[Root @ localhost ~] # [-d / etc / vsftpd]
[Root @ localhost ~] # echo $?
0 ==> return value of 0 indicates the step test condition is satisfied
[Root @ localhost ~] # [-d / etc / hosts]
[Root @ localhost ~] # echo $?
1
[Root @ localhost ~] # [-e / media / cdrom] && echo "YES" ==> If the test condition is established, the output "YES"
YES
[Root @ localhost ~] # [-e / media / cdrom / Server] && echo "YES"
[Root @ localhost ~] #
&& Is above "and" meaning, "... && echo YES" means that if there is no output, then the test condition is not satisfied or previously executed command error. (Note: l test files can be written (-w), do not perform the test as root (privileged user) identity, otherwise it may not be able to accurately judge)

Comparison of integer values: [integer integer 1 Operator 2]

Common test operators
-eq: equal (Equal)
-ne: not equal (Not Equal)
-gt: greater than (Greater Than)
-lt: less than (Lesser Than)
-le: less than or equal to (Lesser or Equal)
-ge: greater than or equal to (Greater or Equal)
 
[Root @ localhost ~] # who | wc -l
5
[Root @ localhost ~] # [ `who | wc -l` -le 10] && echo" YES "==> If the number of users log on less than or equal to 10 output YES
YES
[Root @ localhost ~] # df -hT | grep "/ boot" | awk '{print $ 6}'
12%
[Root @ localhost ~] # BootUsage = `df -hT | grep" / boot "| awk '{print $ 6}' | cut -d"% "-f 1`
Explained: df -hT view disk space usage for all partitions
grep "/ boot" to filter out on / boot points in the data row
awk '{print $ 6}' with a space as a separator, just take sixth field data
cut -d "%" -f1% as the delimiter, just take the first field data
[Root @ localhost ~] # echo $ BootUsage
12
[Root @ localhost ~] # [$ BootUsage -gt 95] && echo "YES" ==> If the / boot partition disk usage exceeds 95% of the output YES
Test conditions Operation: [1 = String String 2]

Common test operators
=: The same string content
! =:! String contents are different, number indicates the opposite meaning
-z: string is empty
[Root @ localhost ~] # read -p "Location:" FilePath
Location: / etc / inittab
[Root @ localhost ~] # [$ FilePath = "/ etc / inittab"] && echo "YES" ==> If you type the path to the specified directory consistent output YES
YES
[Root @ localhost ~] # [$ LANG! = "En.US"] && echo $ LANG ==> If the current locale is not en_US, the output value of the LANG variable
zh_CN.UTF-8
(String comparison can be used to check user input, for example in the provision of interactive operation, it is determined whether a selection input by the user matches the specified variable content)

Logic test: [Expression 1] operator [Expression 2]

     Common test operators
-a or &&: logical and, "and" mean (before and after the two expressions are set up throughout the test result to be true, and false otherwise)
-o or ||: logical or, "or" means (at least one is true on both sides of the operator, the result is true, otherwise the result is false)
!: No logic (when a specified condition is not satisfied, return the result is true)
[Root @ localhost ~] # echo $ USER
root
[Root @ localhost ~] # [$ USER! = "Teacher"] && echo "Not teacher" ==> If the user is not a teacher, you are prompted to "Not teacher"
Not teacher
[Root @ localhost ~] # [$ USER = "teacher"] || echo "Not teacher"
Not teacher
Refers to a logical test: use two (or more) when the conditional expression, the relationship between them is determined
if sentence structure - the appropriate action when "conditions are met."

      Single branches:

if a conditional test command

    then the command sequence

fi

if the statement is simple application example

#! / Bin / bash
temp = 2
if [$ temp -eq 2]
then
    echo 'temp is 2'
fi
   Save the file as a test, and set it to executable (+ x)

[Jzhou @ localhost ~] # chmod 775 test
[Jzhou @ localhost ~] # bash test
temp is 2
     (Note: lthen and if a line can be written, but separated by a semicolon, for example: if [$ RATE -gt 80]; then)

Single branches:

if a conditional test command

    then the command sequence 1

    else command sequence 2

fi

 
Analyzing mysqld is running, if it has to run the system outputs, otherwise restart the mysqld service
#! / Bin / bash
service mysqld status &> / dev / null
if [$? -eq 0] ==> determine whether the sentence is executed successfully
    then
        echo "mysqld service is running."
    else
        /etc/init.d/mysqld restart
fi
 
 
Prompts the user to enter an integer, how to determine whether the value is less than 100?
read "Input an integer:" NUM;
           if [$ NUM -lt 100]; then
               echo "less than 100"
           else
              echo "greater than or equal to 100"
           fi
 
Multi-branch:

if a conditional test command 1; then

    Command sequence 1

elif conditional test command 2; then

    Command sequence 2

elif ...

else

    Command sequence n

fi

for loop - depending on the values of variables, repeating a set of commands to perform the operation

Structure for statements

The value for the variable name in the list

do

    Command sequence

done

Simple application examples for statements

 
Sequentially outputs three text messages, including the day of the "Morning", "Noon", "Evening" string
[Root @ localhost ~] # vi showday.sh
#! / Bin / bash
for TM in "Morning" "Noon" "Evening"
do
    echo "The $ TM of the day."
done
 
[Root @ localhost ~] # sh showday.sh
The Morning of the day.
The Noon of the day.
The Evening of the day
 
 Example 2: The number of files to get users to meet the conditions of
#! / Bin / bash
DIR = "/ opt"
LMT = 100
ValidUsers = `grep" / bin / bash "/ etc / passwd | cut -d": "-f 1` ==> use bash as a login shell get a list of user names
for UserName in $ ValidUsers
do
    Num = `find $ DIR -user $ UserName | wc -l`
    if [$ Num -gt $ LMT]; then
         echo "$ UserName have $ Num files."
    fi
done
 
[Root @ localhost ~] # sh chkfileown.sh
root have 6737 files.
teacher have 344 files.
while loop - repeat the test conditions specified, as long as the condition is satisfied then repeatedly execute the corresponding command operation

Structure while statement

 while a command or expression

 do

      Command List

 done

while statement is simple application example

Bulk add 20 system user account, the user name followed by "stu1", "stu2", ......, "stu20"
#! / Bin / bash
i = 1
while [$ i -le 20]
do
    useradd stu $ i
    echo "123456" | passwd --stdin stu $ i &> / dev / null
    i = `expr $ i + 1`
done
 
 
Batch delete system above to add 20 user accounts
#! / Bin / bash
i = 1
while [$ i -le 20]
do
    userdel -r stu $ i
    i = `expr $ i + 1`
done
Branch control statements

case statement - according to different values of variables, performs different command operation

variable values in case

    Mode 1)

          Command sequence 1

          ;;

    Mode 2)

          Command sequence 2

          ;;

......

    *)

          The default command sequence executed

esac

(When confronted with double semicolons ";;" after the jump to esac indicates the end of a branch. If you could not find a match value, the execution of the last model "*)" after the default command sequence, until after the encounter esac end branch)

#! / Bin / bash
case $ 1 in
    start)
        echo "Start MySQL service."
        ;;
    stop)
        echo "Stop MySQL service."
        ;;
    *)
        echo "Usage: $ 0 start | stop"
        ;;
esac
(Various types of script /etc/init.d/ directory, the extensive use of case statements branching structure)

#! / Bin / bash
read -p "Press some key, then press Return:" KEY
case "$ KEY" in
  [A-z] | [A-Z])
      echo "It's a letter."
      ;;
  [0-9])
      echo "It's a digit."
      ;;
  *)
      echo "It's function keys, Spacebar or other keys."
esac
(Match mode, you can use square brackets indicate a continuous range, for example, "[0-9]"; use the vertical bar symbols "|" representation or, for example, "A | B" (A or B))

unitl statement - repeated operations based on criteria

until conditional test command

do

      Command sequence

done

(Until the loop command structure while similar, "until then by detecting the subsequent command returns the value" $? "To determine whether to exit the loop

   until: until "test conditions" was established loop is terminated, and while is: When the cycle "test conditions" set up

   That is: until the implementation of the test condition is false (non-zero) when the loop condition is true (0) to exit the loop, just the opposite and while loop)

 

shift statement - for migration position variable, the $ 1 to $ 9 in turn passed to the left (not used)

For example, if the current position variable script obtained as follows:
 $ 1 = file1, $ 2 = file2, $ 3 = file3, $ 4 = file4
After a shift command is executed, the position of each variable as follows:
 $ 1 = file2, $ 2 = file3, $ 3 = file4
After executing shift command again, each position variables are:
 $ 1 = file3, $ 2 = file4
Passing multiple integer values through command line parameters, and calculates the sum
[Root @ localhost ~] # vi showday.sh
#! / Bin / bash
Result = 0
while [$ # -gt 0] ==> $ # predefined variable that represents the number of positional parameters
do
    Result = `expr $ Result + $ 1`
    shift
done
echo "The sum is: $ Result"
 
[Root @ localhost ~] # ./sumer.sh 12 34 56
The sum is: 102
Loop control statements

break: in for, while, until, etc. loop and the case for out of the current loop, the statement after the loop body is executed; not exit the program. After execution break command to jump done after the statement.


continue: in for, while, until circulatory statement, used to skip the rest of the loop body statement, re-determine the conditions for the implementation of the next cycle

shell Function

Define a new function:

Defined function call: function name

Passed into the function arguments: Function name Parameter 1 Parameter 2 ......

#! / Bin / bash
adder () {
    echo `expr $ 1 + $ 2`
}
adder 12 34
adder 56 789
[Root @ localhost ~] # sh adderfun.sh
46
845
(Inside the script, the function has been defined like "internal command", as can be directly used as an execution statement)
     
         
         
         
  More:      
 
- sa weak passwords intrusion prevention (Linux)
- Fedora10 use Git version Configuration Management (Linux)
- C ++ casts New Standard Comments (Programming)
- C / C ++ various data types Conversion Summary (Programming)
- 5 steps to help you become a good Docker contributors (Linux)
- Run Windows in FreeBSD bhyve (Linux)
- CUDA (including GPU card driver) installation process under Ubuntu (Linux)
- Oracle 11g 10g induced into error (Database)
- 10 useful Linux command Interview Questions and Answers (Linux)
- Git 2.5 increase in the working tree, triangle improved workflow performance (Linux)
- Linux simple commands (Linux)
- C ++ hash function (Programming)
- To create a Linux server network security (Linux)
- Linux /var/spool/ insufficient clientmqueue space solutions (Linux)
- Python closure and function objects (Programming)
- Linux dual physical network card set to a virtual NIC (Linux)
- Oracle Database Delete Delete million or more common method of heap table data (Database)
- Android HTTP request with Get Information (Programming)
- How to install Ubuntu applications Device 7 (Linux)
- Zypper command for SUSE Linux package management (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.