Common linux commands

Source: Internet
Author: User

Common linux commands
Linux directory structure:

 

 

 

1. Main Directories

Main Directory:/root,/home/username super user's home directory and user directory

You can execute Common commands:/bin,/usr/bin,/usr/local/bin.

System commands:/sbin,/usr/sbin,/usr/local/sbinroot

Other installation points (Mount Points):/media,/mnt when we need to access a certain resource (such as a USB flash drive) media system, mnt users do it themselves

Configuration:/etc

Temporary Files:/tmp,/var/tmp tend to be root users

Kernel boot:/boot

Service data (business data):/var

System Information:/proc,/sys a micro File System (cpuinfoCUP information, meminfo memory) cat/proc/cupinfo

Shared File:/bin,/usr/bin,/usr/local/bin

2. Commands

Internal and external (Command help man command) (command -- help) (usr/share/doc) red hat goole it

Pwd: view your own directory

-L: Option

Mkdir: create a directory (n ...) If you want to create spaces such as a \ B

Rmdir: delete a directory

Touch: create a file

Rm: delete an object

Ls-d */: display all directories

Ls-R: display all directories R Recursion

Cp:/directory/file ..... Target/directory/

./: Current Directory

-F: the root user does not need to ask for the operation.

Mv: renaming and moving, for example, mv file newfile

Cat: view files

Root operation: rm-fr * Delete all files in all directories in the current directory

Ii. File editing (vim)

1. Command mode: browsed, pasted, and changed (mi files)

2. edit mode: insert

3. Extended Mode: Esc exit mode: w save after modification: q Exit: wq save quit: q! To force exit, you can edit two files at the same time. Use: n to switch to another file: N to return to the first file: x to save the disk and exit: X to encrypt the file.

Quickly locate the last row of Q, and the first line of gg pagdown pages up and down: Numeric row

: Set number open row number: setonnu cancel

: Setautoindent (ai) Auto indent

Search Press select key, command format/search name n next, N previous

Search replacement: % s/replacement object/new character/g

Copy yy cut dd paste p, u undo, ctrl + r return ctrl + v Select part of the file

 

Common linux commands

I have been studying the linux system in the past few days. I plan to deploy the next project on the server of the linux system to improve the security (Windows 2003 is not enough ), after understanding and careful consideration, all parties have decided to use the CentOs version of the linux system. This version is suitable for use as a server version and is relatively stable. CentOs 6.4 has just been installed on the virtual machine.

Linux commands are used to manage Linux systems. For a Linux system, whether it is a central processor, memory, disk drive, keyboard, mouse, or user, it is a file. The Linux system management command is the core of its normal operation, similar to the previous doscommand. There are two types of linux commands in the system: built-in Shell commands and Linux commands.

Generally, the server version does not require graphical interfaces to be installed, and only the command line is used for management. Therefore, it is necessary to master the necessary linux commands, below I will record some common commands (which will be updated continuously in future use)

Shutdown-h now shutdown-r now restart reboot now restart su-if the current user is normal, enter this command to switch to the administrator user (root ), if you want to switch to another user, enter the su-user name, for example, su-shenlianglogout, to log out from the current user (if it is on a GUI terminal, enter the exit command to exit the current user) cd switch directory. For example, cd/indicates switching to the linux root directory !! (/) Indicates the root directory. pwd indicates the path in which the user is running the command (this command is used in many cases. If you do not know the current folder in the command line, enter the command pwd.

Used to create and delete users

Useradd username [Add a user] For example: useradd shenliangpasswd username [Change Password for the specified username] For example: passwd shenlianguserdel username [delete a user, however, this user's subfolders in the home file are retained. For example, userdel shenlianguserdel-r username: delete a user and delete the subfolders of the user in the home folder. For example: userdel-r shenliang

Some operations on folders and files (the most frequently used)

Ls [List Files And Directories] such as ls/home (list all files and directories under home) ls-l [List Files And Directories In a long list] such: ls-l/homels-a [list hidden files and directories] For example: ls-a/homemkdir [create directory] For example: mkdir testrmdir [Delete empty directory] For example: rmdir test (only empty directories can be deleted. If there are other files in this directory, this command is invalid) touch [Create an empty file] such as touch Test. javacp [Copy command] such as cp/home/Test. java/(set Test. copy the java file to the root directory.) cp-r dir1 dir2 [-r indicates recursion. Copy the folder represented by dir1 and the files in it to the dir2 path.] For example: cp-r/home/test/(copy the test folder under home to the root directory) mv [Move file and change file name] For example: mv/home/Test. java/(indicates. java file to the root directory) mv/Test. java/Hello. java. change the java file name to Hello. java) rm [delete files and directories] such as rm/Test. java (Test. java delete) [Note: if the file is a folder, it cannot be deleted] rm-rf * [(-r indicates recursion, f indicates forced deletion) delete all content, including directories and folders. For example, rm-rf/home/test (Force Delete the test folder under home) ln [Create a symbolic link, similar to the shortcut in windows (root permission or corresponding user permission is required). The ln-s source target is as follows: ln-s/etc/inittab (this will create an inittab Link under the root directory, which points to the inittab file under the etc directory) more [display file content, with paging] less [display file content, with paging] if a file contains a lot of content, you can use the more command to paging it, such as: more/etc/prelink. conf (to prelink under etc. conf file content is displayed by page) | [pipeline command] [This command is used in many linux systems] (| this command is used to deliver the result of the previous command to | the subsequent command for processing) for example: ls/etc | more (| the previous command shows all files and directories in the etc folder. | the subsequent command is displayed on pages, therefore, this command is used to display all files and directories under the etc directory by page. grep [query content in the text] is used in many ways, such: grep "shenliang"/home/Test.txt (query the line of text information containing shenliang in the Test.txt file) if you need to display the number of lines of the text to be queried, use: grep-n "shenliang"/home/test.txt(query the number of lines in the shenliang file in test.txt and change all text) find [search for files and directories] such as find/home-name Test. java (the name is Test in the home folder or in all subfolders in home. java files) The redirection Command [>>>,<] such as: ls-l/etc> a.txt prepare file will overwrite the previous information) ls-al/etc> aa.txt (Add the following information of etcto The End Of The aa.txt file) Input aaa <bbb [cat, vi] information from the file (cat command can only view files, the vi command can view and modify files. For some key files, we generally use the cat command to view them. For example, cat/etc/profile (only view the content of the file) vi/etc/profile (view and modify the content in the file)

 

Write content to the file: overwrite (the original content in the file is overwritten) echo "111111111">. echo "111111111"> java.txt

 

Iii. Users

Uid: User ID

File: r read, w witer, x exe

Dir: r ls, w rm/mv/mkdir/touth, x ls-l

Set file permissions:

Assign chown [-r] user file to pay user permissions

Assign group [-r] User group Permissions

Modify file permissions:

Example: chmod g + w pwsswd plus permission chmod g-w minus permission

U, g, o (u + g + o = a): user, group and other

3. Common files used for user login and access operations

-/Etc/passwd: stores user information

-/Etc/shadow: stores password information.

-/Etc/group: stores user group information

-/Etc/gshadow: (No)

 

Col1: User Name

Col2: placeholder

Col3: User ID

Col4: User Group id

Col5: custom information

Clo6: user's home directory

/Bin/base: Interactive and usable

/Usr/sbin/nologin: refused to log on (you want to make the system exist and don't want it to log on to your system)

The above two types can be changed to etc/passwd.

User Management:

Useradd: useradd Username

Usermod: usermod-s/sbin/nologin username.

Userdel [-r]: userdel-r username.

File Permission:

File: fewer Permissions

Dir: user groupother

Comod u + t dir

Comod g + s dir multi-user coordination

Comod o + t dir can be used by any user

Getfacl/file: view User Permissions


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.