Some common commands for Linux
These days it's time to study Linux and plan to deploy the next project on a Linux-system server that has increased security (lost by Window 2003), decided to use the CentOS version of the Linux system after all the understanding and deliberation. This version is well suited as a server version and is relatively stable. The CentOS 6.4 version has just been installed on the virtual machine.
Linux commands are commands for managing a Linux system. For Linux systems, whether the CPU, memory, disk drives, keyboards, mice, or users are all files, the Linux System Management command is the core of its normal operation, similar to the previous DOS command. There are two types of Linux commands in the system: built-in shell commands and Linux commands.
Generally as a server-side version is to promote the non-installation of graphical interface, only use the command line for management, so master the necessary Linux commands become necessary, I will record some common commands (in future use will be constantly updated)
Shutdown-H now-R Today restarts reboot -If you are currently a normal user, enter this command to switch to the administrator user (root), If you want to switch to a different user , type Su-user name such as: Su- shenlianglogout Log off from the current user (or enter the exit command to exit the current user if it is in the terminal of the graphical interface) CD /means switch to the root of Linux!! (/) indicates the root directory "PWD shows the command under which the user is currently under (This command is very much used, you can enter the command if you do not know the current folder in the command line PWD
For creating, deleting users
useradd username " Add a user" such as: Useradd shenliangpasswd username "Change password for specified user name" such as: passwd shenlianguserdel username - R username "delete a user and delete the subfolder with the user in the home folder" such as: Userdel-r Shenliang
Some actions for folders and files (using the highest frequency)
ls "Lists files and directories" such as: LS/Home (list all files and directories under Home) LS-L "lists the files and directories displayed in a long list" such as: Ls-l/Homels-A "list hidden files and directories" such as: ls-a/homemkdir "Create directory" such as: mkdir testrmdir "Delete empty directory" such as: RmDir test (can only delete empty directory, if there are other files in the directory is not valid) touch "create empty file" such as: Touch TEST.JAVACP "Copy command" such as: CP/home/test.java/(Copy the Test.java file under the home path to the root directory) CP-R dir1 Dir2 "-R for recursion, copy the folder that Dir1 represents and the file inside it to the DIR2 path "such as: CP-r/home/test/(Copy the test folder under home to the root) MV "Move and change the file name" such as: MV/home/test.java/(means to move the Test.java file under home to the root directory) MV/test.java/Hello.java (means change Test.java file name to Hello.java) RM "Delete files and directories" such as: RM/Test.java (remove Test.java from root) "Note: If the file is a folder, you cannot delete the RM-RF * "(-R for recursion, F for forced deletion) deletes all content, including directories and folders" such as: rm-rf/home/Test (Force Delete test folder under Home) ln "establishes symbolic links similar to shortcuts in Windows (requires root or appropriate user rights)" LN-s source target target such as: Ln-s/etc/inittab/Inittab (This will create a inittab link in the root directory, which points to the Inittab file under the ETC directory) more "show file contents with pagination" Less "show file contents with pagination" If there's a lot of content in one of our files, You can use the more command to paging to it as: more/etc/prelink.conf (to display the contents of the prelink.conf file below etc)| "Pipeline Command" "This command is used in many Linux systems" (| The function of this command is to give | The result of the previous command |The following command to process) such as: LS/etc | More (| The previous command is to show all files and directories under the ETC folder, |The next command is displayed as a paging, so the command means to display all the files and directories in the ETC directory with pagination, grep "query content in text" This command is used in many ways: grep"Shenliang"/home/Test.txt (the line of text that contains the Shenliang in the Test.txt file) is used if it is necessary to display the number of rows in which the text is being checked: grep-N "Shenliang"/home/Test.txt (Query the number of rows in the Test.txt file that shenliang the information and line all text) find "Search files and directories" such as: Find/Home-name Test.java (look for a file named Test.java under the home folder or all subfolders in home) redirect command ">, >>, <"such as: LS-l/etc>A.txt (ETC, the following list information is written to the a.txt file "overwrite", if the A.txt file does not exist before, then create the A.txt file and then write the information in, if there is a a.txt file, it will overwrite the previous information) LS-al/etc>>aa.txt (Append the following list information from etc to the Aa.txt file information) Enter information from the file AAA<BBB "Cat, VI" (CAT command can only view files, vi command can view files and modify files, for some of the key files we generally use the Cat command to view) such as: Cat/etc/profile (just view the contents of the file) Vi/etc/profile (view, and can modify the contents of the file)
Write content to file: Overwrite (the original content in the file is overwritten) echo"111111111" >. txt add-on notation (new content is added after the original content) echo"111111111" >> java.txt1. Explanation of Main catalogue
Home directory:/root,/home/username for super users and user directories
User-Executable:/bin,/usr/bin,/usr/local/bin General user commands
System instructions:/sbin,/usr/sbin,/usr/local/sbinroot will use the
Other mount points (mount point):/media,/mnt when we need to access a resource (such as a U-disk) media system is complete, MNT users do it themselves
Configuration:/etc
Temp file:/tmp,/var/tmp var/tmp tend to root user
Kernel Boot:/boot
Service data (Business data):/var
System Information:/proc,/sys a Micro file system in memory (Cpuinfocup information, meminfo memory) cat/proc/cupinfo
Shared files:/bin,/usr/bin,/usr/local/bin
2. Command
Internal, external (Command Help man command) (command--help) (Usr/share/doc) Red Hat Goole it
PWD: View your directory
-L: Options
mkdir: Create directory (n ... If you want to build a space, like A\ B,
RMDIR: Deleting a directory
Touch: New File
RM: Deleting files
LS–D * *: Show all directories
LS–R: Show all directories R recursion
CP:/directory/File ..... target/Directory/
./: Current directory
-f:root do not ask for action
MV: Rename, move as: MV file NewFile
Cat: View Files
Root operation: RM–FR * Delete all files in the current directory
Ii. File Editor (VIM)
1, Command mode: Can browse, can paste, change mode (MI file)
2. Edit mode: Insert
3. Extended mode: ESC Exit Edit mode: W modified Save: Q exit: Wq Save exit: q! Force quit can edit two files at the same time, use: n switch another file: N back to the first file: X Save: X Encryption
Quick Positioning Q last line, GG the first line pagdown up and down: numerical positioning row
: Set number Open Line No.: Setonnu Cancel
: Setautoindent (AI) Auto indent
Search press the Select key, command format/Search name n Next, N previous
Search Replace:%s/Replace object/new character/g
Copy yy cut dd paste P,u undo, Ctrl+r Back Ctrl + V Select part of File
Third, the user
UID: User ID
File:r read,w witer,x exe
Dir:r ls,w rm/mv/mkdir/touth,x Ls–l
To set file permissions:
Assign Chown [-r] User files to pay user permissions
Assign Groups Group [-R] User group pay permission
Modify file Permissions:
Example: chmod g+w pwsswd plus permissions chmod g-w minus permissions
U,g,o (u+g+o=a): User,group and other
Third, the user login into the operation of common Files
-/ETC/PASSWD: Storing user information
-/etc/shadow: Storing password information
-/etc/group: Storing user group information
-/etc/gshadow: (No more)
Col1: User Name
Col2: Placeholder
COL3: User ID
COL4: User Group ID
COL5: Custom Information
Clo6: User Home Directory
/bin/base: Interoperable, use
/usr/sbin/nologin: Deny login (you want to make the system exist and don't want him to log into your system)
Both of the above can be changed to ETC/PASSWD
User management:
Useradd: Example Useradd user name
Usermod: Example Usermod–s/sbin/nologin user name
Userdel [-R]: example USERDEL–R user name
File permissions:
File: Less permissions
Dir:user Groupother
Comod u+t dir
Comod g+s dir Multiple user coordination work
Comod o+t dir Any user can use
Getfacl/file Viewing user rights