Basic Operations Summary 丨 Linux

Source: Internet
Author: User
Tags bz2 chmod clear screen gz file readable set time disk usage file permissions

This document incrementally updates the cumulative

1. Wildcard characters:
Parameters meaning
* Represents any number of characters in a file name, or it can have no

LS te* find files that start with Te
LS *html find the file ending with HTML

Parameters meaning
? Represents any character in a file name, there must be 1, no

Ls?. C only find the first character arbitrarily, the suffix is. c file
LS A.? Only 3 characters are found, the first 2 characters are a., the last character arbitrary file

Parameters meaning
[] ["and"] "encloses a group of characters, which means that any one of the group of characters can be matched, and"-"is used to represent the range of characters.

[ABC] matches any of a, B, c
[A-f] matches any character in the range from a to F
LS [a-f]* find a file that starts with any one of the characters from a to F range
LS a-f find file named A-f, when "-" outside the square brackets lose the role of wildcards

Parameters meaning
\ If you want to use wildcards as normal characters, you can precede them with escape characters. "?” and "*" in square brackets without the use of escape characters have lost the role of wildcards, no longer need to escape.

LS \a finds files with file name \A

2. cd
Parameters meaning
. Switch to current directory
.. Switch to upper-level directory
~ Switch to the current user's home directory (/home/user directory)
- Switch between paths in the last two times
3. ls
Parameters meaning
-A Show hidden files with '. ' The file that starts with is a hidden file
-L List Display style

When the contents of a directory are displayed in a list, the first character represents something
D: Folder
-: Normal file
C: Hardware character device
B: Hardware block device
S: Piping file
I: Soft Link file

Parameters meaning
-H To display a reasonable size unit with the-l use

Ls-alh or Ls-lha
Multiple parameter options can be combined to write, with no order of precedence

4. Output redirection >/>>

Linux allows command execution results to be redirected to a file that should be displayed on the terminal and saved to the specified file

The so-called redirection is actually modifying the default output direction

The ' > ' output redirect overwrites the original content, empties the target file, and then adds the content
The output redirection of ' >> ' will append the output to the end of the file, and add content directly to the original content, without emptying the original content.

5. Split Screen display: more

When you look at the content, when the information is too long to be displayed on one screen, a quick scrolling screen appears, which makes the user unable to see the contents of the file.
At this point, you can use the more command, only one page at a time, press the SPACEBAR to display the next page, press the Q key to exit the display, press the H key to get help

6. Pipe Break: |

Pipe: The output of one command can be piped as input to another command
Pipeline we can understand the real life of the pipe, the pipe of a plug into the other side to take out
Here "| "The left and right are divided into two ends, and the other side is a thing (write)
Ls-alh | More

7. Clear the screen: clear

Clear function for clearing the display on the terminal (similar to the DOS CLS Clear screen feature), also available shortcut keys: Ctrl + L ("L" as the letter)

8. pwd

Displays the absolute path of the current operation

9. mkdir

You can create a new directory by using the mkdir command. parameter-P can be recursively created directory
Note that the name of the new directory cannot be the same as the existing directory or file in the current directory, and the directory creator must have write access to the current directory

Ten. RmDir

You can use the rmdir command to delete a directory.
Must leave this directory, and this directory must be an empty directory, or the prompt to delete failed

One. RM

You can delete files or directories from RM.
Use the RM command with caution, because files cannot be recovered after deletion, so in order to prevent files from being mistakenly deleted, you can use the-I parameter after RM to confirm the files to be deleted individually

Parameters meaning
-I. For interactive execution
-F Forced deletion, ignoring nonexistent files without prompting
-R Remove content from directory recursively, this parameter must be added when deleting a non-empty folder
Tree: Displaying the directory structure as a table of contents

Tree [directory Name]

. ln establishes a linked file

1. Soft connection

Ln-s source File New link file name
Link files are like shortcuts under Windows, soft links do not occupy disk space, source files are deleted, soft links fail
(The soft connection is actually pointing to the source file name this address, when the ' RM source filename ', after the source file address is deleted, the soft connection will not find the source file name pointed to the content of the files)

2. Hard Links
ln source File New link file name
For each new hard link, it is like assigning an address to the file content; hard links can only link ordinary files, not directories
(The source file name is actually an address, pointing to the corresponding file content)
(The ' RM file name ' Operation actually removes the file name "address" that points to the contents of the files, and does not directly delete the contents of the file, just so that you can no longer find the file name corresponding to the content)

Cat

View the contents of the file (preferably one screen to display, too much more)
Or merge multiple file contents (with redirect ' > ')
Cat 1.txt 2.txt > 3.txt (1.txt and 2.txt order affects pre-and post-merged content)

Cat-a File View special format for files created with DOS (Windows)

. grep

The grep command in a Linux system is a powerful text search tool
GREP allows pattern lookups on text files, and grep prints all rows that contain patterns if a matching pattern is found.
The general format of grep is:
grep [-option] ' Search content string ' file name
Common Options Description:

Options meaning
-V Display all lines that do not contain matching text (equivalent negation)
-N Display matching lines and line numbers
-I. Ignore case

When entering a search string in the grep command, it is best to enclose it in quotation marks or double quotation marks. For example: grep ' a ' 1.txt

grep search content string can be regular expression
A regular expression is a logical formula for a string operation, which is a "rule string" that is used to express a filter logic for a string, using predefined specific characters and combinations of these specific characters.

grep Common Regular Expressions:
| parameters | Meaning | example |
|-|-|-|
|^a| the beginning of the line, searching for lines starting with a |grep-n ' ^a ' 1.txt|
|ke$| the end of the line, searching for the line ending with Ke |grep-n ' ke$ ' 1.txt|
| [ss]igna[ll]| Matches one of the series of characters in [] matches the word signaL, SignaL, SignaL, SignaL line |grep-n ' [Ss]igna[ll] ' 1.txt|
|. Match a non-newline character match between E and E has any one character, can match eee,eae,eve, but does not match ee,eaae|grep-n ' E.E ' 1.txt|

--help.

LS--help: You can see the help information that comes with the Linux command

A. Man

(Manual manual) is a handbook provided by Linux, which contains most of the commands, function usage instructions
The manual is divided into chapters (sections), which can be used to specify different chapters to browse using man.
Cases:
Man LS (in fact, we don't have to specify the first few chapters to see it)
Man 2 printf (use Chapter number: view)
The meanings of each section in man are as follows:

    1. Standard commands (normal command)
    2. System calls (systems calls, such as Open,write)
    3. Library functions (libraries functions, such as Printf,fopen)
    4. Special devices (description of the device file, various devices under/dev)
    5. File formats (files format, such as passwd)
    6. Games and toys (gaming and entertainment)
    7. Miscellaneous (Miscellaneous, conventions and agreements, such as Linux file systems, network protocols, ASCII codes; environ global variables)
    8. Administrative Commands (administrator commands, such as Ifconfig)

The man is searched in the order of the chapter number of the manual (1-8 above).
The man set the following function keys:

function keys function
Space key Show the next screen of the man page
Enter key One row of the scroll manual page
B Roll back one screen
F Roll forward one screen
Q Exit Man command
H List all function keys
/word Search Word string

. tab

At the same time as the first few letters of the command, pressing the TAB key, the system will automatically help us complete the command

History

Show History commands
After the system has executed some commands, you can press the up and down keys to look at the previous command, the history of the executed commands listed

. find

The Find command is very powerful and is often used to search for eligible files in a specific directory, or to search for files that are owned by a particular user.
Common usage:

Command meaning
Find./-name test.sh Find all files named test.sh in the current directory
Find./-name ' *.sh ' Find all files with the suffix. Sh in the current directory
Find./-name "[a-z]*" Find all files in the current directory that begin with uppercase letters
Find/tmp-size 2M Find files that are equal to 2M in the/tmp directory
Find/tmp-size +2m Find files larger than 2M in the/tmp directory
Find/tmp-size-2m Find files less than 2M in the/tmp directory
Find./-size +4k-size-5m Find files larger than 4k and less than 5M in the current directory
Find./-perm 0777 Find a file or directory with permission 777 under the current directory
. CP

The function of the CP command is to copy the given file or directory to another file or directory, equivalent to the Copy command under DOS.

Common Options Description:
| options | meaning |
|-|-|
|-a| This option is typically used when copying a directory, preserving links, file attributes, and recursively copying directories, simply keeping the file's original properties |
|-f| Directly overwrite the existing target file without prompting |
|-i| interactive replication, which prompts the user to confirm before overwriting the target file |
|-r| If the given source file is a directory and its files, the CP will recursively replicate all subdirectories and files in that directory, and the destination file must be a directory name |
|-v| Show Copy Progress |

A B is a folder
CP A B copies the A folder as a whole to the B folder
CP a/* B assigns all content under the A folder to the B folder

. MV

Users can use the MV command to move files or directories, or to rename files or directories

Common Options Description:
| options | meaning |
|-|-|
|-f| Disable interactive operation and do not give hints if overwrite is available |
|-i| Confirm the interactive operation, if the MV operation will result in overwriting the existing target file, the system will ask whether to rewrite and ask the user to answer to avoid overwriting the file by mistake |
|-v| Show Move Progress |

Which.

To see where the command is located, and if it is found, the location of the command is displayed
which LS

Tar

Just doing packing, and not compressing

Data in the computer often needs to be backed up, and tar is the most commonly used backup tool in Unix/linux, which archives a series of files into a large file or unlocks the file to recover the data.

Tar using format:
tar [parameters] packaged file name
The tar command is special, and its arguments can be preceded by "-", or "-" can be used.

Common parameters:
| parameter | meaning |
|-|-|
|-c| Generate the archive file, create a package file that (create: This is what I think) |
|-v| List the detailed process of archive files, show progress |
|-f| Specify the file name, and F must be a. tar file, so you have to put the option last |
|-t| List files included in the archive |
|-x| Unlocking a Profile |
Note: Except F needs to be placed at the end of the parameter, the order of the other parameters is arbitrary

Package all files and subfolders in the current directory as archive files, uncompressed

Unpack the packaged archive, not unzip it

Tar the command itself is not compressed, it is just a packaged command, but adding an option in the tar command (-Z) can call gzip to implement a compression function, so that a first package after the compression process.

Compression usage:
Tar Cvzf package and compress the compressed package name. tar.gz file ...
Parameter meaning
-Z Specifies the format of the compressed package: xxx.tar.gz

Decompression usage:
Tar zxvf compress package name. tar.gz

Unzip to the current path by default
Add-C (note is Capital letter C) Specify the directory to extract to

25. File compression/Decompression of gzip

The tar is used in conjunction with the GZIP command to package and compress files.
Tar is only responsible for packaging files, but does not compress, with gzip compressed tar packaged files, its extension is generally used xxxx.tar.gz
Gzip uses the following format:
gzip [options] compressed files. Tar
Common options:
Option meaning
-D Decompression
-R compresses all subdirectories

Compress the Test.rar file, and the resulting compressed filename is added by default after the tar file name is compressed. GZ

Compress tar-packaged files with gzip, specify the file name after compression

Unzip the tar.gz file, extract the tar file, and no unpacking

26. File Compression/Decompression bzip2

Tar is used in conjunction with the BZIP2 command to implement file packaging, compression (usage and gzip).
Tar is only responsible for packaging files, but does not compress, with bzip2 compressed tar packaged files, its extension is generally used xxxx.tar.gz2.
Adding an option to the tar command (-J) can call bzip2 to implement a compression function that implements a pre-packaged compression process.

Compression usage: TAR-JCVF compress the package name. tar.gz file ...
Tar jcvf bk.tar.bz2 *.c

Decompression usage: TAR-JXVF Compress package name. tar.gz
Tar jxvf bk.tar.bz2

Add-C (note is capital letter C) to specify the directory to extract to, this is the same as TAR-ZXVF xxx.tar.gz-c./test

27. File Compression/Decompression Zip/unzip

The destination file for the ZIP archive does not need to specify an extension, the default extension is zip

Compressed file: Zip [-r] Destination compressed file name (without specifying extension) source files

Extract files: unzip-d After extracting directory files to be compressed

. WHO

Who command to view user information for all currently logged-on systems

Common options:
| Options | meaning |
| - | - |
| -M or Am I | Displays only the user name, logon terminal, and logon hours of the WHO command |
|-q or--count| Show only the user's login account and the number of logged-in users |
|-u or--heading| Show Column Headings |

WhoAmI.

WhoAmI This command user to view the user name of the current system's current account.
System user information can be viewed through cat/etc/passwd.
Because system administrators often need to log on to the system with multiple identities, such as typically using a normal user login system, and then switch to the root identity of the SU command to manage the legacy. At this point, you can use WhoAmI to view the current user's identity

Ifconfig.

View IP address (windows:ipconfig)
Ifconfig

Modify IP
Ifconfig Ens33 192.168.1.100

Uninstalling the NIC
Ifconfig ens33 Down

Load Network card
Ifconfig ens33 up

. Ping

Ping ipaddr Test network connectivity

ssh

Telnet
SSH User name @ host IP

. exit
    • If it is a graphical interface, exit the current terminal
    • If you are using SSH telnet, log out of the login account
    • If it is the logged-in user after the switch, exit to return to the previous login account
Useradd.

To add a user account in Unix/linux, you can use the Useradd or AddUser command.
Because the adduser command is a link to the Useradd command, the two commands are used in exactly the same format
useradd [parameters] New user account

Parameters meaning
-D Manually specify the home directory (not created) when the user logs on to the system, and if you do not use this parameter, and only use the-m parameter, the default system automatically establishes the directory with the same name as the user name in the/O directory
-M Automatically create a home directory
-G Specify Group name
    • Linux each user must have a home directory, the home directory is the first login system, the user's default current directory (/home/users)
    • Each user must have a home directory, so when creating a user with Useradd, be sure to assign a home directory to the user
    • The user's home directory is usually placed in the root directory of the home directory, the user's home directory and user name is the same
    • If you do not specify a group name when creating a user, the system automatically creates a group name that is the same as the user name
Command meaning
useradd-d/HOME/ABC abc-m Create an ABC user, if the/HOME/ABC directory does not exist, automatically create/home/abc this directory, while the user belongs to the ABC Group
useradd-d/home/a a-m-G test Create a user name called a, home directory in/home/a, if the home directory/home/a does not exist, automatically create the home directory, while the user belongs to the test group
cat/etc/passwd View System Current user name
Userdel.

Delete User

Command meaning
Userdel ABC (user name) Delete the ABC user, but do not automatically delete the user's home directory
USERDEL-R ABC (user name) Delete a user while deleting the user's home directory
36. User groups

View user groups
Method One: Cat/etc/group
Method Two: Groupmod + three times Tab key

New group Account Groupmod
Groupadd Group account Name

Delete Group account Groupdel
Groupdel Group account Name

To modify the group that the user belongs to Usermod
Usermod-g New user group name 1 user name

Append the user to the new group while preserving the original group, now the user belongs to both the old group and the new group
Usermod-a-G New user group name 2 user name

See which groups the user is in
Groups user Name

37. Switch User su

The user name that SU needs to switch
Su-the user name that needs to be switched, and when the user is switched, it also actively jumps to the user's home directory

Command meaning
Su Switch to root user
Su Root Switch to root user
Su- Switch to the root user while switching directories to/root
Su-root Switch to the root user while switching directories to/root
Su Ordinary user Switch to normal user
Su-Ordinary users Switch to normal user while switching to the directory where the normal user is located
. sudo

Added when you need to have Super administrator privileges, and sudo is prepended to the corresponding command, followed by a space separating
sudo passwd wei switch to User Wei
Sudo-s switch directly to the root user

Add sudo permissions to the normal user you create

Newly created user, the default cannot sudo, need to do a bit of action
sudo usermod-a-G ADM user name append user to ADM Group
sudo usermod-a-g sudo user name append user to sudo group

passwd.

Set User password
In Unix/linux, a superuser can use the passwd command to set or modify a user's password for a normal user
Users can also use the command directly to modify their own passwords without having to use the user name after the command
sudo passwd Wei

40. Modify file (folder) permissions chmod

There are 2 ways to modify file permissions: Alphabet and Digital methods

1. Alphabet Law
chmod u/g/o/a +/-/= rwx file

x
parameters meaning
U user represents the owner of the file
G Group indicates that the owner of the file belongs to the same group, which is the user group
o Other means other people
a al L means all three of them are
+ Add permissions
- Revoke permissions
= set permissions, default no permissions not set
R read means readable, and for a directory, if there is no r permission, it means that the contents of this directory cannot be viewed by LS
W write means writable, for a directory, without W permission, it means that new files cannot be created under the directory
Excute means executable, for a directory, if there is no X permission, then it is not possible to enter this directory by CD

chmod u+x file.txt Add executable permissions to the file owner
Chomod g-w file.txt minus writable permissions for the same group
chmod o+w file.txt Add writable permissions to other people
chmod u=rw,g=x,o=r file.txt permission settings for owners, groups, and others at the same time
chmod u=,g=,o= file.txt Remove all permissions from the owner, the same group, and everyone else

2. Digital Law

Letters Number Correspondence
R Read permission, number code is "4"
W Write permission, the number code is "2"
X Execute permission, number code is "1"
- does not have any permission, the number code is "0"

The combination of rwx can be equivalent to the number
chmod u=rw,g=x,o=r file.txt equivalent to chmod u=7,g=5,o=4 file.txt

can also not add u,g,o; Set permissions directly with numbers
chmod 751 File:
7 This delegate: File owner: Read, write, execute permissions
5 This delegate: Same group of users: Read, execute permissions
1 This delegate: Other users: Permissions to execute

If you want to recursively add the same permissions to all directories, you need to add the parameter "- R "
Example: chmod 777 test/-R All files in the recursive test directory plus 777 permissions

41. Modify the file owner identity Chown

Chown New owner name File.txt

42. Modify the file belongs to group Chgrp

CHGRP New group name File.txt

43. View the current calendar cal

Used to view the current calendar

44. Display or set time date

Set the time
Date [MMDDHHMM[[CC]YY][.SS]]

Parameters meaning
Mm Month
Dd Day
hh Hours
Mm Minutes
Cc The first two bits of the year, century
Yy The latter two of the years
Ss Seconds

Date 010203042016.55

Show time
Date ' +%y,%m,%d,%h,%m,%s '

Parameters meaning
%y,%y %y:2018;%y:18 a year;
%m Month
%d Day
%H When
%M Score of
%s Seconds

Note case

45. View process Information PS

A process is a program with a certain independent function, which is the basic unit of dynamic execution of the operating system.
PS command to view the detailed status of the process

Common options are as follows:
| parameter | meaning |
|-|-|
|-a| shows all processes on the terminal, including the processes of other users |
|-u| Show detailed status of the process |
|-x| shows no control of the terminal process |
|-w| display widening to show more information |
|-r| only the running processes are displayed |

46. Dynamic display of Process top

The top command is used to dynamically display the running process.
The top command is able to update the display information at a specified time interval after it is run.
You can specify a time interval for displaying information updates by adding-D when using the top command.

After the top command has been executed, you can press the key to sort the displayed results.
| key | meaning |
|-|-|
| m| Sort by Memory usage |
| p| Sort by CPU Share |
| T| based on the length of process run Time |
| U| can filter processes based on the user name entered later |
| The k| can kill the process based on the PID entered later |
|q| Exit |
|h| Get Help |

47. Terminate the process Kill

Kill command, the process that kills the specified process number needs to be used with PS.
Use format:
Kill [-signal] pid
The signal value is from 0 to 15, where 9 is absolute termination and can handle processes where the general signal cannot be terminated.

Kill 9133
9133 the process number that corresponds to the application

Some processes cannot be killed directly, this time we need to add a parameter "9", "9" to represent the forced end

48. Shutdown Restart: shutdown/reboot/init
Command meaning
Reboot Restarting the operating system
Shutdown–r now Restart the operating system, shutdown will give other users prompt
Shutdown-h now Immediately shuts down, where now is equivalent to a state of 0 time
Shutdown-h 20:25 The system will shut down at 20:25 today.
Shutdown-h +10 The system shuts down automatically after 10 minutes.
Init 0 Shutdown
Init 6 Restart
49. Check the file system disk space DF

The DF command detects disk space usage and availability for the file system, and can show all file system usage of nodes and disk blocks

Parameters meaning
-A Show disk usage for all file systems
-M Display in 1024-byte units
-T Displays disk space usage for each specified file system
-T Display file system
50. Detecting the disk space occupied by the catalog Du

The du command is used to count the size of the disk space that the directory or file occupies, and the command performs the same as DF, where du is more focused on disk usage.

The usage format of the DU command is as follows:
Du [options] directory or file name

Parameters meaning
-A Recursively displays blocks of data in files and subdirectories in the specified directory
-H Display in a more readable manner
-S Displays data blocks occupied by the specified file or directory
-B Display disk usage in bytes
-L Calculates all file sizes and computes multiple times for hard-linked files

Basic Operations Summary 丨 Linux

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.