This short life we all lose eventually

You might as well be bold, love someone, climb a mountain, follow a dream


Understand the concept of Linux, if there is any error, welcome to correct, see you in the comments. This article is for learning use only.

After entering the terminal and entering A long command, you can use CTRL + A to go back to the beginning or CTRL + E to go back to the end

roaming

Log in to view and switch directories

cd

One of the most commonly used commands can be understood as the change Directory acronym

【 Common commands 】

  • cd: indicates the home directory, which is equivalent tocd ~
  • cd ..: indicates to return to the upper-level directory,.. Also directory, usels -alTo view
  • cd -: == Indicates that the last directory is changed ==
  • cd /: indicates the root directory
  • cd [dir]: [] indicates that the directory is in the dir directory

ls

One of the most commonly used commands can be understood as a list abbreviation

【 Common commands 】

  • ls -alt: Lists all files in chronological order

【 Common parameters 】

  • -a: Displays all files and directories, including hidden ones
  • -l: Displays the detailed list
  • -h: suitable for human reading
  • -t: Sorts files by the time when they were last modified
  • -i: Displays the file’s inode (inode is an identifier of the file’s contents)


Text manipulation

It usually involves modifying some configuration files and searching some logs

grep

A regular expression is searched globally and printed to the screen. This command is usually used in combination with other commands

【 Common commands 】

  • Grep "key" [file]: Searches for the key line in the file. -n Displays the line number

【 Common parameters 】

  • -i: Ignore case,grep -i "127" /etc/hosts
  • -n: Displays the line number,grep -n "127" /etc/hosts

wc

Word count is an acronym used to count words, lines, characters, bytes, etc.

【 Common commands 】

  • Wc-l [file]: Indicates the number of lines in a file
  • ls -al | grep ^- | wc -l: == Counts the number of all common files in the current directory ==

【 Common parameters 】

  • -l: Count only rows,wc -l name.txt
  • -w: Count only words,wc -w name.txt
  • -c: Counts only the number of bytes,wc -c name.txt
  • -m: Counts only characters,wc -m name.txt

vim

Vim editor, can edit view files

【 Common commands 】

  • Vim [file]: Open file

Press: To enter the bottom line mode, press Esc to exit and return to the command mode. In the command mode, press I or S or A to enter the editing mode

Vim Configuration personal: ~/. Vimrc Global: /etc/vimrc Common set number: enable line numberCopy the code

Edit mode

Normal editing operationsCopy the code

Command mode

  • x: delete
  • ggFirst line:
  • G: jumps to # line after #G
  • ctrl+f: Turn the screen forward
  • ctrl+b: Flip a screen back
  • dd: Deletes the line where the cursor is located
  • yyYy copy the entire line
  • u#u Undoes the most recent changes
  • p: paste

The bottom line pattern

  • q: Quit plus! Forced exit without saving
  • wq: Save exit plus! Forced save exit
  • esc: Exit the bottom line
  • /pattern: Searches for pattern downward
  • ? pattern: Search pattern up
  • n: Find next (in the same direction as the command)
  • N: Find next (opposite to command)
  • S/What to find/What to replace /ig: I ignores case and g global

operations

Disk, network, etc

df

The df command is used for the usage of disk space that has been mounted. The full name of the command is disk free.

  • df -h: View the mounted disk space

【 Common parameters 】

  • -h: Human display, easy to read

du

The du command is used to view the disk capacity occupied by partitions or directories. The full name of the command is disk Usage.

【 Common commands 】

  • Du - sm directory: Displays the disk capacity occupied by partitions or directories

【 Common parameters 】

  • -h: Human display, easy to read
  • -s: Displays only the total number
  • -m: Displays the file size in MB

Other Common Commands

Not classified, but also commonly used

top

Gets a dynamic list of processes.

ps

Displays processes in the current system

【 Common commands 】

  • ps -ef | grep java-efList all processes and look for processes with == Java ==

kill

Used to kill a process

【 Common commands 】

  • kill -9 [pid]-9 Forcibly kills the process. The ID of the PID process can be obtained by ps

pwd

Displays the current directory

date

View the current system time

【 Common commands 】

  • date -s "20200808 19:12:12": Sets the system time

clock

Viewing hardware Time

【 Common commands 】

  • clock --set --date '2017-08-16 17:17:00': Sets the hardware time
  • clock --hctosys: System time synchronizes hardware time

chmod

Set the access permission for a file

【 Common commands 】

  • Chmod 755 [file]: grants all have all, others only read and execute

-rwxrwxrwx Readable, writable, and executable – RWXRWXRWX Three groups of security levels Owner permission, owner group permission, and other user permission == For directory files, readable indicates that you can read the list of files in the directory. Writable: can add, delete, and rename files in a directory. Executable means access to the directory. = =

mkdir

Create a directory make directory

【 Common commands 】

  • Mkdir [directory]Create a directory
  • mkdir -p a/b/c/d: Creates a nested directory

ln

Create links, such as deep directories, by creating links that can be placed on a desktop or other convenient location

【 Common commands 】

  • ln -s name.txt name_link: Create a soft link named name_link pointing to name.txt
  • ln name.txt name_hardlink: Create a hardlink named name_hardlink pointing to name.txt

Tips soft links are equivalent to Windows shortcuts; Hard link is equivalent to a new file name pointing to the same data block; The inode of the file name and the original file are the same as the Linux file store, divided into inode and data, inode stores the related attributes of the file, data stores the file data. Soft link > means to create a link to the file;

touch

Create an empty file

【 Common commands 】

  • touch file: Creates a file

/etc/motd

Prompt to enter terminal, short for Message of the day. It’s a file, modifiable.


Subsequent updates