Linux Common basic commands

Source: Internet
Author: User
Tags save file set time unpack

first, the system directory structure

Conventional:

Bin (binaries) holds binary executable file

Sbin (Super User binaries) holds binary executable files, only root can access

etc (etcetera) storage System configuration file

USR (Unix shared resources) is used to store shared system resources

Home Store The root directory of user files

Root Super User Directory

Dev (devices) for storing device files

Lib (library) stores the shared libraries and kernel modules needed to run the program in the file system

MNT (Mount) system administrator installs the temporary file system installation point

Boot holds various files used for system boot

TMP (temporary) for storing various temporary files

VAR (variable) is used to store files that need to change data at run time

ii. Basic Commands 1. Directory Operations

Relative path and absolute path description:

Now, under the/home/dijia478/.

./a/b.txt and A/b.txt both represent relative paths, and the B.txt file under the A folder under the current directory

/home/dijia478/a/b.txt represents the absolute path, under the root directory under the home folder under the dijia478 folder under the A folder under the B.txt file

CD./A switch to the folder A in the current directory
CD.. Switch to the previous level directory
CD/switch to the system root directory
CD ~ Switch to user home directory
CD- switch to the previous directory

PWD Displays the absolute path to the current directory

2. View a list of files

ls/path/display all file or folder names for this directory
Ls-a display all file or folder names (including hidden)
LS-L displays all files or folders by list, abbreviated to LL

Ll-h Friendly display file size (shown as K,MB,GB)

3. Create and delete folders

mkdir App Create App folder
Mkdir–p app2/test Cascade Create AAP2 and Test folder

RmDir App Delete app folder (need to be empty folder)

4. File Operation

RM a.txt Delete a.txt file, delete requires user confirmation, y/n
Rm-f a.txt do not ask, delete the A.txt file directly
Rm-r a recursively delete a folder (with or without content)
RM-RF A does not ask for recursive deletion of a folder (use caution)
RM-RF * Delete all contents of current directory (preferably not used)
RM-RF/* No for no Die (Linux system is finished)

CP a.txt b.txt copy a.txt as B.txt file
CP A.txt. /Copy the A.txt file to the previous level directory

MV A.txt. /Move the A.txt file to the previous level directory
MV a.txt b.txt renaming a.txt file to B.txt

Touch a.txt Create an empty a.txt file
echo "Good Good study" > a.txt put the output on the left side of the ">" to the file on the right, overwriting if it exists, creating it if it does not exist.
via.txt Editing a file with a text editor , if it does not exist, create

5. File Packaging Archive and compression

TAR-CVF File.tar Dirpath filepath the dir folder and file files are packaged in the current directory as File.tar
TAR–XVF File.tar unpacking to the current directory

Gzip File.tar compress files or folders
Gzip–d file.tar.gz Extract files or folders

TAR-CZVF file.tar.gz Dirpath filepath the dir folder and file files are packaged and compressed into file.tar.gz in the current directory
TAR-XZVF file.tar.gz Unzip and unpack to the current directory
TAR-XZVF file.tar.gz-c/home/dijia478/Unzip and unpack to the/home/dijia478/directory

Common parameters:
-C: Create a new tar file
-V: Displays information about the running process
-F: Specify file name
-Z: Call the gzip compression command to compress
-T: View the contents of a compressed file
-X: Unpack the tar file

Zip Test.txt.zip Test.txt is also packaged and compressed
Unzip Test.txt.zip unpacking and unpacking

6. View text Files

Cat a.txt Display entire file content at once
More A.txt can be paged (page: space, turn back: B, exit: Q or CTRL + C)
Less a.txt not only can be paged, but also easy to search, turn back and other operations (page: space, flip: ↑, down: ↓, exit: Q or CTRL + C)

tail-10 A.txt View 10 lines at the end of a file
Tail-f User.log Real-time refresh shows the end of the file, this command is very important to observe the debug program running

head-20 a.txt View the file header 20 lines
Note: Ctrl + C end View

7. Search Find Command

grep ' haha './* print where all files in the current directory contain ' haha ' (supports regular expressions)
Grep-c ' haha './* Displays the number of rows matched to
Grep-r ' haha './* Sub-directories also traverse the search
Grep-l ' haha './* Displays only the file name of the hit
Grep-n ' haha './* Displays the line number of the hit
Grep-ld skip ' haha './* Displays the file name of the hit and does not search subdirectories

Parameter meaning:
-R Recursive Search sub-directory
-l lists only filenames with matching rows
-N Lists line numbers for matching rows
-D Skip does not search subfolders

Common grep used in combination with other commands to find the information we care about (pipeline)
Example:
Service--status-all | grep ' httpd ' finds ' httpd ' in all services of the current system
NETSTAT-NLTP | grep ' 22 ' looks for a service program that listens for ' 22 ' ports
ps–ef | grep java Lookup Java processes currently running in the system

Find/-name ' *.txt ' finds files ending in. txt (will traverse the current directory)
Find/-name ' install* ' Look for files or folders that begin with install
Find/-type f look up normal files
Find/-type L Lookup Connection file (shortcut)

8. Text Commands

> REDIRECT output, overwrite the original content;
>> redirect output, and additional functions;
CAT/ETC/PASSWD > A.txt directing the output of the password file to A.txt
CAT/ETC/PASSWD >> a.txt Output and append
Ifconfig > Ifconfig.txt Save IP information to file

Wc-l a.txt count Lines of text
Wc-w a.txt Statistics Text word number
Wc-m a.txt Statistics Text character number
Wc-c a.txt count Text bytes

VI Editor
VI filepath open file
Press the ESC key to switch to command-line mode
Switch to insert mode:
I inserted at the current position
I Insert at the beginning of the current
A is inserted after the current position
a inserts at the end of the current line
o insert a row after the current line
O Insert a row before the current line
dd Delete entire row
7 dd up delete 7 rows
U fallback (similar to CTRL + Z in Windows)
R Replacement
: (colon) toggle to the bottom row mode
: Q Exit
: Wq Save and exit (SHIFT + ZZ can also be saved)
: q! Do not save exit

9. Other common Commands

Date "+%y%m%d" displays time in format
Date-s "2020-12-20 10:56:00" set time

echo $JAVA _home output variable java_home value

WhoAmI querying the user name currently logged in
Which LS query $path path of LS command

mkdir Test && CD test
Only the command on the left of && returns True (command return value $?). = = 0) The command to the right of,&& will be executed.
As long as there is a command return False (command return value $?) = = 1), the subsequent command will not be executed.

ii. User Management commands 1. Add Users

Basic example:
Useradd user001
You must set a password to log in normally passwd 123456
Parameter manual:
-U Specify group ID (UID)
-g Specifies the group name (GID) that belongs to
-G Specify multiple groups, separated by commas "," (Groups)
-C User Description (comment)
-E Expiration Time (expire date)

2. Delete a user

Userdel user002 This deletion, the user's home directory is retained
Userdel-r user002 Delete the user's home directory while deleting the user

3. Modify User Properties

directive: Usermod
Parameters:
-L Modify user name (login) usermod-l a B (b change to a)
- G Modify group usermod-g sys Tom
-D Modify the user's host directory
- g Add multiple groups usermod-g sys,root Tom
-L Lock user account password (lock)
-u Unlock user account (Unlock)
Example:
usermod-l user002 user001 change user001 's login name to user002
usermod-g Root user002 change the group of user002 to the root group
usermod-g Hello1,hello2 user002 Add two groups to user002 Hello1,hello2
usermod-d/home/dijia478 user002 Change user002 's home directory to/home/dijia478
(to create the dijia478 directory in advance and copy the environment variable file)

4. User Group Management

User group related properties:
Each user belongs to at least one user group
(If you do not specify the owning group when creating a new user, it is automatically created and attributed to a group with the same name as the user name)
Each user group can contain multiple users
Users of the same user group have permissions shared by this group
User group Management Operations Command:
Groupadd Java Create user groups
Groupdel Hello2 Deleting a user group
Groupmod–n newname oldname Modify user group name
Groups user002 viewing the group to which it belongs

5. User and user group related profiles

User Configuration information storage location:
Files to save user information:/etc/passwd
File to save password:/etc/shadow

Examples of passwd files:
User002:x:500:500:user002:/home/user002:/bin/bash
passwd file The meaning of each field:
Account:password:UID:GID:GECOS:directory:shell

Examples of shadow files:
User002:$1$vrug41$uuxyzdp0i6s6wtupiegdq/:18617:0:99999:7:::
Shadow file The meaning of each field:

User name

User name of the login system

Password

Encrypt password

Last modification time

The number of days the user last modified the password from 1970-1-1

Minimum time interval

Minimum number of days between password changes two times

Maximum time interval

Password valid days

Warning Time

Number of days from system warning to password expiration

Account Idle Time

Account Idle Time

Expiry time

Number of days the password expires

Sign

Sign

User group configuration information storage location:
Save file for user group:/etc/group
File to save user Group password:/etc/gshadow (only used when setting up Group admins)

Linux common basic commands

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.