Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction to Linux and the most commonly used commands (easy to learn, but can solve more than 95% of problems)

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Linux is currently the most widely used server operating system, based on Unix, open source free, due to the stability and security of the system, high market share, almost become the best system environment for program code to run. Linux can not only run the program code we write for a long time, but also be installed in a variety of computer hardware devices, such as mobile phones, routers and so on. The bottom layer of the Android program runs on the linux system.

I. the directory structure of linux

Bin (binaries) stores binary executable files sbin (super user binaries) stores binary executable files Only root can access etc (etcetera) to store system configuration files usr (unix shared resources) to store shared system resources home root directory to store user files dev (devices) to store device files lib (library) to store shared libraries needed to run programs in the file system and kernel module mnt (mount) system administrator installation point for temporary file system boot storage Various files used when booting the system tmp (temporary) are used to store various temporary files var (variable) are used to store files that need to change data at run time

Second, linux common commands

Command format:

Command-option parameters (options and parameters can be empty)

For example: ls-la / usr

2.1 operating files and directories

The command parameter example shows that cdcd / home switch directory pwdpwd displays the current working directory touchtouch 1.txt creates empty files mkdirmkdir testdir creates a new directory-pmkidr-p dir1/dir2/dir3/ creates a multi-level directory, if the parent directory does not exist, the parent directory cpcp 1.txt copies files or directories-rcp-r dir1/ recursive processing Copy files under the specified directory together with subdirectories mvmv dir1 dir2 mobile files or directories, files or directories renamed rmrm 1.txt delete files

-r

-f

Rm-rf dir1

R delete all files in this directory at the same time

F force deletion of files or directories

Rmdirrmdir dir1 delete empty directory catcat 1.txt display text file content moremore 1.txt

Pagination displays the contents of the text file, which can be flipped back and forth, spaces backward, b forward

Lessless 1.txt

Pagination displays the contents of the text file, which can be flipped back and forth, spaces backward, b forward, and supports bottom line mode (described later)

Headhead 1.txt view the beginning of the text, default ten lines-[num] head-20 1.txt view text start part specify the number of lines tailtail 1.txt view text end part, default ten lines-[num] tail-20 1.txt view text end part specify the number of lines-ftail-f 1.txt loop to read the file and dynamically display it on the screen File attribute tracking-Ftail-F 1.txt cycle scrolls to read the file and dynamically displays it on the screen, and the file name tracks wcwc 1.txt

Count the number of lines, words and characters of the text

-m

Wc-m 1.txt characters-wwc-w 1.txt text words-lwc-l 1.txt text lines find-namefind /-name 1.txt finds the specified file in the specified directory in the file system grepgrep aaa 1.txt finds the line containing the specified content in the specified file, for example: look in 1.txt for all lines containing aaa lnln 1.txt 1_bak.txt to establish a link file

S

Ln-s 1.txt 1_bak.txt establishes symbolic connections to source files instead of hard links

2.2 examples of command parameters commonly used in the system illustrate top top

The command parameter example shows that toptop

Displays the processes that consume the most resources in the current system

Datedate shows that the current time of the system ps is seldom used alone, with parameters such as ps- ef or ps-aux-e /-Aps-e according to the requirements.

Show all processes, environment variables

-fps-ef full format display-aps-a

Show all processes for all users (including other users)

-ups-au

Displays the process in the order of user name and startup time

-xps-aux displays processes without control terminals kill-9kill-9 pid forcibly kills a process dfdf displays file system disk space usage-hdf-h displays in a human-readable manner, du such as Kb,Mb,GB

Displays the sum of the disk space used by the specified directory and its subdirectories

-sdu-s * displays the sum of the specified directories. * all-hdu-sh in the current directory is displayed in a human-readable manner. Freefree such as Kb,Mb,GB shows the current memory and swap space usage ifconfigifconfig network card network configuration Commonly used to view the current IP address ifconfig eth0 192.168.12.22 temporarily modify the system IP (failure after restart) pingping baidu.com test network connectivity hostnamehostname check hostname shutdown-rshutdown-r shut down first, then restart-hshutdown-h shutdown does not restart halthalt

Turn off the power after shutdown, which is equivalent to shutdown-h

Rebootreboot

Reboot is equivalent to shutdown-r

2.3 Compression and decompression

The command parameter example shows that the file or folder after gzipgzip 1.txt compression-dgzip-d 1.txt.gz decompress the compressed file-[num] gzip-9 1.txt

Adjusts the speed of compression with the specified number num,-1 or-fast for the fastest compression method (low compression ratio), and-9 or-- best for the slowest compression method (high compression ratio). The system default is 6

Tar-ctar-cvf 1.tar 1.txt establishes a parameter instruction for a compressed file, for example, to compress 1.txt to 1.tar, or to specify multiple files or folders-xtar-xvf 1.tar 1.txt parameter instruction to unzip a compressed file-z

Tar-zcvf 1.tar.gz 1.txt

Tar-zxvf 1.tar.gz 1.txt

Whether you need to use gzip, use gzip to compress or extract-v compression to display the file-f use the file name, immediately after f to receive the file name

The command parameter example shows that the file or folder after gzip gzip 1.txt compression-dgzip-d 1.txt.gz decompress the compressed file-[num] gzip-9 1.txt

Adjusts the speed of compression with the specified number num,-1 or-fast for the fastest compression method (low compression ratio), and-9 or-- best for the slowest compression method (high compression ratio). The system default is 6

Tar-ctar-cvf 1.tar 1.txt establishes a parameter instruction for a compressed file, for example, to compress 1.txt to 1.tar, or to specify multiple files or folders-xtar-xvf 1.tar 1.txt parameter instruction to unzip a compressed file-z

Tar-zcvf 1.tar.gz 1.txt

Tar-zxvf 1.tar.gz 1.txt

Whether you need to use gzip, use gzip to compress or extract-v compression to display the file-f use the file name, immediately after f to receive the file name

2.4 File permission operation

Interpretation of the description format of linux File permissions

R readable permission, w writeable permission, x executable permission (can also be expressed in binary 111 110 100-> 764)

Bit 1: file type (d directory,-normal file, l linked file)

Bits 2-4: user permissions, indicated by u (user)

Bit 5-7: group permissions, indicated by g (group)

Bits 8-10: other user rights, indicated by o (other)

Bit 2-10: indicates all permissions, represented by a (all)

An example of command parameters shows that chmodchmod Usingr 1.txt

Modify the permissions of a file or directory

U represents current users, g represents users in the same group, o represents other users, and a represents all users

R for readable, w for writable, x for executable

Example: modify the 1.txt file to add executable permissions to the current user

-Rchmod-Ruttr dir1 permissions to modify all files in a specified directory and its subdirectories three digits chmod 764 1.sh

Specify the permissions of the file directly

7: means readable, writable and executable, 4 / 2 / 1

6: means readable and writable, 4x2

...

Chownchown user1:group1 1.txt

Modify the users and groups of the file

For example, the user of the 1.txt file is specified as user1 and the group is group1

-Rchown-R user1:group1 1.txt

Modify the users and groups of all files and subdirectories under the directory

Permissions are represented by numbers (ringing 4 ~ 4 ~ 2 ~ 2 ~ 1 ~ 1 ~ ~ 0)

Third, linux system commonly used shortcut keys and symbol commands

An example of command parameters shows that ctrl + c stops the process ctrl + l clear screen ctrl + r search history command ctrl + Q exit tab automatic completion > echo "" > 1.txt

Write the output of the previous command to the following text

Empty the text and write to

> > echo "lala" > > 1.txt

Write the output of the previous command to the following text

Do not empty the text, append it to the end of the text

| | cat 1.txt | grep 'hello' |

Pipe command, the output of the previous command is used as input, and then the operation is performed

Example: print a line with hello string in 1.txt

* wildcard, which refers to all

IV. Vim Editor

Vi / vim is the most commonly used text editor on Linux and is very powerful. There are only commands, no menus. The following figure shows the switching diagrams of the various modes of the vi command.

4.1 modify text

I

Insert in front of the cursor

I

Insert at the beginning of the current line of the cursor

A

Insert after the cursor

A

Insert at the end of the current line of the cursor

O

Inserts a new line at the next line of the current line of the cursor

O

Insert a new line on the previous line of the current line of the cursor

Wq saves and exits

4.2 location command

Set nu displays line number: set nonu cancels line number gg jumps to the first line G jumps to the last line: n jumps to the nth line

4.3 replace and cancel commands

Uundo, cancel the previous operation Ctrl + r

Redo, before returning to undo

R

Replace the character where the cursor is located

R

Replace from where the cursor is located and press Esc to end

4.3 Delete command

X Delete the character where the cursor is located nx the n characters after deleting the cursor dd deletes the line where the cursor is located. Ndd deletes n lines dG deletes all content from the line to the end of the cursor D deletes the content from the cursor to the end of the line: 5 delete 7d delete the line in the specified range

4.4 commonly used shortcut keys

Shift+ zz saves and exits, same as ": wq" v enters character visual mode V enters line visual mode Ctrl + v enters block visual mode

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report