Common Linux Commands

The current user switches to the root user

su
Copy the code

Switching common Users

Su user nameCopy the code

Mkdir Creates folders recursively

mkdir -p /home/keith/demo/hello
Copy the code

Cp Copy command

cp -r /home/.bashrc /keith/ # recursively copy /home/.bashrc to/Keith /
Copy the code

Tar Compression and decompression command

tar -czvf /home/.bashrc # Compress /home/.bashrc file
tar -xzvf /home/.bashrc Unzip /home/.bashrc
Copy the code

Grep text search command

grep -n hello a.txt # search for the hello string in a.t_t and display the line number
Copy the code

Find File search command

Linux terminal shortcuts

Move the cursor quickly to the end of the line: Ctrl + A Move the cursor quickly to the end of the line: Ctrl + E move the cursor to the left: Ctrl + B move the cursor to the right: Ctrl + F delete the previous character: Ctrl + H delete the previous word: Ctrl + W delete the entire line: Ctrl + u

Vim editor

Displays the line number of the Vim editor:

:set nu
:set nonu # Do not display editor line number
Copy the code

To specify the line number: : |, for example, to line 927

: 927 |Copy the code

Look for a character, such as external_url

/external_url
Copy the code

Common operations in common mode

dd # remove
yy # copy
p # paste
u # Undo the previous step

gi Quickly skip to the last edit and enter insert mode
gg Move to the beginning of the file
G Move to the last line of the file
ctrl + o # Quick return

h # Move left
j # Move down
k # Move up
l Move to the right

0 # move to the beginning of the line
$ # Move to end of line

# word is a word separated by a non-null character and word is a word separated by a whitespace character
w/W # Move to the next word/ word beginning,
e/E # Move to the next word/WORLD end
b/B # Back to the beginning of last word/ word
Copy the code

Vim window operations

Open multiple files simultaneously using vim: vim file1 file2… In normal mode, enter :ls to switch files in the buffer. The following methods are available:

  • Use :b n to jump to the NTH buffer

  • Jump to the previous buffer: :bpre

  • Jump to the next buffer: :bnext

  • Jump to the first buffer: :bfirst

  • Jump to the last buffer: : Blast

  • Jump to buffer: : b name with b name

Open multiple Windows simultaneously: Split horizontally: Ctrl + W + S or: SP Split vertically: Ctrl + W + V or :vs

  • Toggle between Windows: Ctrl + W

  • Switch to the left window: Ctrl + W + H

  • Switch to the lower window: Ctrl + W + J

  • Switch to the top window: Ctrl + W + K

  • Switch to the right window: Ctrl + W + L

Set the size of the window:

  • To make the window bigger: Ctrl + w + =

  • To make the window smaller: Ctrl + w + –

There are commands about firewalls

Viewing the Firewall Status

systemctl status firewalld.service
Copy the code

Enabling the Firewall

systemctl start firewalld.service
Copy the code

Disabling the firewall

systemctl stop firewalld.service
Copy the code

Disabling the Firewall

systemctl disable firewalld.service
Copy the code

The SSH remote login function is enabled for Centos

Reference: https://www.cnblogs.com/travis-li/p/12550370.html

  • Ensure that Centos install openssh server, installed in the terminal input yum list | grep openssh server. –

If it is not installed, run yum install openssh-server

  • Open the sshd_config file in /etc/ssh, remove the PasswordAuthentication # and change it to yes; Remove Port #; Remove the # from PermitLocalCommand and change it to yes

  • To start the SSD service, enter service SSHD start

SSH start command: service SSH start SSH stop command: service SSHD stop SSH restart command: service SSHD restart SSH view command: service SSHD statusCopy the code
  • Check whether the SSHD service is open: ps – e | grep SSHD

How can I set the permission of the root user to a common user in Linux

  • Switch to the superuser :su

  • Open the /etc/sudoers file

vim /etc/sudoers
Copy the code
  • Find the root ALL=(ALL) ALL row and insert a new row below that saying Keith ALL=(ALL) ALL, assuming that Keith is the user to whom root is to be enabled

  • Input: wq! exit

  • Exit superuser exit