List of commonly used Linux commands | VMware virtual machine network connection | Terminal configuration

Note: Using Ubuntu 20 version 64-bit 

1. About the Internet

If the network connection is not good, change the network adapter, switch bridge mode and NAT mode to each other, and then restart the virtual machine.

 

2. Open the terminal

How to open the terminal:

    ①Right-click on the desktop, [Open in Terminal]

    ②Shortcut key Ctrl + Alt + T

 3. Terminal configuration (font, color, background, etc.)

 4. Directory structure

The Linux directory structure is an inverted tree, as shown in the figure below

 

Common directory descriptions: 

/bin stores commonly used commands (i.e. binary executable programs) (key points)

/etc stores system configuration files (key points)

/home The home directory of all ordinary users

/root the home directory of the administrator user

/usr stores system applications and documents

/proc virtual file system directory, which stores memory mapping in process units (key points)

/dev stores device files (key points)

/mnt temporary mount point

/lib stores library files

/boot system kernel and startup-related files (key points)

/tmp stores various temporary files and is a location accessible to all users.

/var stores files that often change during system operation, such as system logs

 Home Directory:

column1 column2

/home/stu1 /home/stu2, abbreviation~

/home/stu is equivalent to ~

5. Absolute path and relative path 

(1)Absolute path name

The absolute path name is formed along the hierarchical tree, starting from the root directory /, and concatenating all directory names that reach the corresponding file. The directory names are separated by / characters.

/home/stu/dir218 absolute path

/home/stu/desktop absolute path

(2) Relative path

Is the relative path from the current directory to the specified location;

.represents the current directory

..Represents the parent directory of this directory (upper level directory)

cd .. /dir218 relative path

6. Commonly used basic commands

pwd: displays the absolute path of the current location

cd path: switch the current working location, the parameter after cd indicates the location to switch to (absolute path/relative path can be used)

cd .Return to current location

cd ..return to the previous level

cd - Switch to the last location, switch back and forth between two locations

cd ~ goes directly to the current user's home directory

ls: displays the contents of the current directory at the current location by default

ls path: display the contents of the specified directory

ls -l (abbreviated as ll)

ls -a (show hidden files)

ls displays non-hidden files, sorted by file name

ls -a (abbreviation of --all) displays all files, including hidden files ( files starting with . )

ls -A (abbreviation of --almost-all) displays all files, including hidden files, but does not include the two files representing the current directory and the upper-level directory .

clear: clear the screen (equivalent to turning pages)

mkdir filename: Create a directory (folder)

touch filename: Create a normal file

(1)man: help manual

1 represents command 2 represents system call 3 represents library function

man printf: query command printf man 3 printf: query library function printf

(2)touch: Create ordinary files

(3)mkdir: Create directory file

(4))rm file name: delete file

rmdir directory name: delete empty directories

rm -r directory name: delete non-empty directories (delete all files and subdirectories in the specified directory one by one)

(5)cp copy files

Copy ordinary files: cp source file path + file name path

Copy directory files: cp -r source file path + directory name path** (requires adding -r)**

Copy + rename: cp source file path + file name path + new file name

(6)mv: cut file

Move ordinary files: path of mv source file + path of file name

Move directory file: mv source file path + file name path** (no need to add -r)**

Cut + rename: mv source file path + file name path + new file name

Rename: mv source file path + file name source file path + new file name

(7)su switches users

①. Command to switch to administrator: sudo su

Exit:exit

Convert to administrator: sudo su (Note: After the operation is completed after converting to administrator, you must exit to exit the administrator to prevent irreversible consequences of modifying the file)

②. Command to switch to other users: su username

Exit:exit

(8)find: search for files

find[path][options][expression]

path: Specify the directory path. The system will search for files downwards along the directory tree from here. If the path is not written, it will default to the current path.

options: parameter find -version: print version number

expression: match expression

find search path-name file name (search by file name)

find search path -cmin -n (search for files modified in the past n minutes)

find search path -ctime -n (search for files modified in the past n days)

find search path -atime -n (search for files read in the past n days)

find search path -size -n (search for files whose size is n blocks)

For example, full search: find / -name lilo.conf

(9)grep: Filter out lines containing the specified string in the file

grep "string" filename

For example:

1. Query the specified "string" line in a single file (see the figure below)

2. Query the specified "string" line in multiple files (* means query in all files in the current directory)

  

 (10) |: Pipeline command, using the output of the previous command as the input of the next command

 For example: ls /bin |grep sh

 

(11)wc: Count the number of words (-w), the number of characters (-c), and the number of lines (-l) in the file

wc -w filename

wc -c filename

wc -l filename

(12)) Shutdown and restart

shutdown -h now: Shut down immediately

halt: shut down

init 0: shutdown

shutdown -r now: Restart immediately

reboot:restart

init 6: Restart

(13))runlevel

Check the system running level, you can use init to dynamically switch between levels 0-6;

0: Shut down

1:Single user mode

2:Multiple users without network service

3: Complete multi-user text interface

4. Undefined or customized

5: Graphical interface

6: Restart

Note that the user visual interface displayed by Linux by default is a graphical interface unless the user jumps to the text interface.

 7.File type

Everything on Linux is a file;

Linux does not distinguish file types by file extensions. There is a column in the file attributes specifically to record file types;

File type: Ordinary file (indicated by -):    .c .cpp .h .pdf .xls

Directory file: folder (represented by d)

Pipe file: a file used for inter-process communication (represented by p)

Link file: equivalent to a shortcut on Windows (represented by l)

Device files: character device file (c), block device file (b), socket (s)

ls -l: displays detailed information about the files at the current location (ll)

 

 8.File viewing command

(1)cat

1) cat file name: View file content

2) Merge files: cat a.txt b.txt > c.txt

3) Write data to the file: cat > file name (ctrl+d ends input)

(2)more file name

Display more file contents (carriage return, space to turn pages)

(3) less file name

After reading the content, it will not be displayed on the screen (up and down keys, page turning keys)

(4)head

Display the contents of the first n lines of the file: head -num file name (default is 10 lines)

(5)tail

Display the last n lines of the file: tail -num file name (default is 10 lines)

9. File compression and decompression commands

(1) tar: package or unpack

tar cvf xxx.tar (packed name) All file names that need to be packaged

(2)gzip compression or decompression

Compression: gzip package name

For example: gzip mytar.tar

Unzip: gzip -d xxx.tar.gz

For example: gzip -d my.tar.gz

(3) tar one-step decompression

tar zxf xxx.tar.gz

tar zxf xxx.tgz

10.File editing commands

(1) Introduction to vim

vim is an upgraded version of vi. The one you use vi to automatically connect to is vim. You should not use vi in ​​particular, and the arrow keys cannot be used;

vim’s official website https://www.vim.org/

(2) Install vim

Installation command: sudo apt install vim

Solution to the problem:

(1) "Unable to obtain lock" appears

"sudo rm file name deleted multiple times

vim locked: ctrl+s

vim unlock: ctrl+q

(2) apt update: Refresh the software source

(3)Three modes of vim

vim is divided into three modes: command mode, insert mode (edit mode), and last line mode

⚠The user has just started vi/vim and entered the command line mode by default. Typing on the keyboard in this state will be recognized by vim as a command instead of entering characters.

 

(1) Convert command mode to insert mode:

a: Start editing after entering the current cursor

A: Go to the end of the line where the current cursor is and start editing.

i: Go to the current cursor position and start editing

I: Go to the beginning of the line where the cursor is currently located and start editing.

o: Go to the line next to the current cursor and start editing.

O: Go to the line above the current cursor for editing

(2) Convert command line mode to last line mode

: Setting the text or saving the work

/ Perform a full-text downward search for the string string

? Search the text upward for the string string

(4)vim/vi common commands

n dd: Delete n lines starting from the cursor downwards

n yy: Copy n lines starting from the cursor downwards

p paste

u Undo the last operation

ctrl+r restores the last undo operation

r replace a character

shift+6: Move the cursor to the beginning of the current line

shift+4: Move the cursor to the end of the current line

shift+g: Move the cursor to the last line of text

gg: Move the cursor to the first line

n shift +g: Move the cursor to the nth line

dn shift +g: delete the content from the cursor to line n

yn shift +g: Copy the cursor to the content of line n

d+G: Delete content from the cursor to the end

d deletes a line from the cursor position

l Move the cursor backward

j Move cursor down

k Move cursor up

h Move cursor left

(5) Operation in last line mode

:w save text

:q Quit editing

:wq save and exit

:q! Force quit (exit without saving)

:w (path) filename (save as)

:set nu displays line number

:set nonu cancel line number

:set hlsearch Set highlight search

:set nohlsearch Cancel highlighted search

:n,ms/oldstring/newstring replaces the first oldstring from line n to line m

:n,ms/oldstring/newstring/g Replace all oldstring from line n to line m

/string search down

?string search upward

(6)Configuration file

1) What is a configuration file?

Configuration files are settings for configuring parameters and initial values ​​for some computer programs

2) Change the path of the configuration file:

vi /etc/vim/vimrc

3) How to set up the configuration file:

sudo vi /etc/vim/vimrc

Then write the configuration options to the end of the file

set no

set nuset tabstop=4 press tab to indent 4 spaces

set softtabstop=4

set shiftwidth=4

set expandtab

set smartindent automatic indentation

Guess you like

Origin blog.csdn.net/weixin_53472334/article/details/130030250