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

What are the common commands of Linux?

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly shows you "what are the common commands in Linux", the content is simple and clear, and I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "what are the common commands in Linux?"

Ls

One of the most frequently used commands.

Command format: ls [OPTION]... [FILE]... Simple input:

[root@iz2ze76ybn73dvwmdij06zz /] # ls bin dev home lib64 media opt proc run srv tmp var boot etc lib lost+found mnt patch root sbin sys usr www

Add option-l, which shows permissions, ownership, group, size, time, file name

[root@iz2ze76ybn73dvwmdij06zz /] # ls-l total dosage 68 lrwxrwxrwx 1 root root July 26 22:36 bin-> usr/bin dr-xr-xr-x. 5 root root 4096 August 26 22:39 boot drwxr-xr-x 19 root root 2960 April 11 12:59 dev drwxr-xr-x. 81 root root 4096 September 5 17:09 etc drwxr-xr-x. 2 root root 4096 April 11 12:59 home lrwxrwxrwx 1 root root 7 August 26 22:36 lib-> usr/lib lrwxrwxrwx 1 root root 9 August 26 22:36 lib64-> usr/lib64 drwx-. 2 root root 16384 October 15 2017 lost+found drwxr-xr-x. 2 root root 4096 April 11 12:59 media drwxr-xr-x. 2 root root 4096 April 11 12:59 mnt drwxr-xr-x. 3 root root 4096 August 26 22:40 opt drwxr-xr-x 2 root root 4096 August 26 23:00 patch dr-xr-xr-x 110 root root 0 April 11 12:59 proc dr-xr-x---. 12 root root 4096 September 11 20:59 root drwxr-xr-x 26 root root 760 September 7 21:50 run lrwxrwxrwx 1 root root 8 August 26 22:36 sbin-> usr/sbin drwxr-xr-x. 2 root root 4096 April 11 12:59 srv dr-xr-xr-x 13 root root 0 April 11 12:59 sys drwxrwxrwt. 9 root root 4096 September 15 03:19 tmp drwxr-xr-x. 13 root root 4096 August 26 22:36 usr drwxr-xr-x. 19 root root 4096 August 26 22:55 var drwxr-xr-x 6 root root 4096 August 26 22:39 www

Ls-a (all) linux'. (dot) the files at the beginning are hidden by default, and-a can query all files.

[root@iz2ze76ybn73dvwmdij06zz /] # ls-a. Bin etc lib64 mnt .pearrc run sys usr.. Boot home lost+found opt proc sbin .test var .autorelabel dev lib media patch root srv tmp www

Ls-F displays the folder at the end of "/".

[root@iz2ze76ybn73dvwmdij06zz /] # ls-F bin@ dev/ home/ lib64@ media/ opt/ proc/ run/ srv/ tmp/ var/ boot/ etc/ lib@ lost+found/ mnt/ patch/ root/ sbin@ sys/ usr/ www/

Ls-r flashback display, the default order is (a _ r _ b _ cm _ d) the positive order is shown in this way.

[root@iz2ze76ybn73dvwmdij06zz /] # ls-r www usr sys sbin root patch mnt lost+found lib etc boot var tmp srv run proc opt media lib64 home dev bin

Ls-R () Recursive display subdirectory

[root@iz2ze76ybn73dvwmdij06zz test] # ls-R.: data. / data: img. / data/img: car product user. / data/img/car:. / data/img/product:. / data/img/user:

Ls-lS is displayed in descending order by file size

[root@iz2ze76ybn73dvwmdij06zz /] # Total amount of ls-lS 72 drwx-. 2 root root 16384 October 15 2017 lost+found dr-xr-xr-x. 5 root root 4096 August 26 22:39 boot drwxr-xr-x. 81 root root 4096 September 5 17:09 etc drwxr-xr-x. 2 root root 4096 April 11 12:59 home drwxr-xr-x. 2 root root 4096 April 11 12:59 media drwxr-xr-x. 2 root root 4096 April 11 12:59 mnt drwxr-xr-x. 3 root root 4096 August 26 22:40 opt drwxr-xr-x 2 root root 4096 August 26 23:00 patch dr-xr-x---. 12 root root 4096 September 15 22:03 root drwxr-xr-x. 2 root root 4096 April 11 12:59 srv drwxr-xr-x 3 root root 4096 September 15 22:10 test drwxrwxrwt. 9 root root 4096 September 15 03:19 tmp drwxr-xr-x. 13 root root 4096 August 26 22:36 usr drwxr-xr-x. 19 root root 4096 August 26 22:55 var drwxr-xr-x 6 root root 4096 August 26 22:39 www drwxr-xr-x 19 root root 2960 April 11 12:59 dev drwxr-xr-x 26 root root 760 September 7 21:50 run lrwxrwxrwx 1 root root 9 August 26 22:36 lib64-> usr/lib64 lrwxrwxrwx 1 root root 8 August 26 22:36 sbin-> usr/sbin lrwxrwxrwx 1 root root 7 August 26 22:36 bin-> usr/bin lrwxrwxrwx 1 root root 7 August 26 22:36 lib-> usr/lib dr-xr-xr-x 110 root root 0 April 11 12:59 proc dr-xr-xr-x 13 root root 0 April 11 12:59 sys

Ls-g does not output owner (owner) information

[root@iz2ze76ybn73dvwmdij06zz /] # ls-g total dosage 72 lrwxrwxrwx 1 root July 26 22:36 bin-> usr/bin dr-xr-xr-x. 5 root 4096 August 26 22:39 boot-rw-r--r-- 1 root 0 September 15 22:20 c drwxr-xr-x 19 root 2960 April 11 12:59 dev drwxr-xr-x. 81 root 4096 September 5 17:09 etc drwxr-xr-x. 2 root 4096 April 11 12:59 home lrwxrwxrwx 1 root 7 August 26 22:36 lib-> usr/lib lrwxrwxrwx 1 root 9 August 26 22:36 lib64-> usr/lib64 drwx-. 2 root 16384 October 15 2017 lost+found drwxr-xr-x. 2 root 4096 April 11 12:59 media drwxr-xr-x. 2 root 4096 April 11 12:59 mnt drwxr-xr-x. 3 root 4096 August 26 22:40 opt drwxr-xr-x 2 root 4096 August 26 23:00 patch dr-xr-xr-x 110 root 0 April 11 12:59 proc dr-xr-x---. 12 root 4096 September 15 22:18 root drwxr-xr-x 26 root 760 September 7 21:50 run lrwxrwxrwx 1 root 8 August 26 22:36 sbin-> usr/sbin drwxr-xr-x. 2 root 4096 April 11 12:59 srv dr-xr-xr-x 13 root 0 April 11 12:59 sys drwxr-xr-x 3 root 4096 September 15 22:18 test drwxrwxrwt. 9 root 4096 September 15 03:19 tmp drwxr-xr-x. 13 root 4096 August 26 22:36 usr drwxr-xr-x. 19 root 4096 August 26 22:55 var drwxr-xr-x 6 root 4096 August 26 22:39 www

Ls-lG hides all group (belonging to group) information

[root@iz2ze76ybn73dvwmdij06zz /] # ls-lG total amount 72 lrwxrwxrwx 1 root July 26 22:36 bin-> usr/bin dr-xr-xr-x. 5 root 4096 August 26 22:39 boot-rw-r--r-- 1 root 0 September 15 22:20 c drwxr-xr-x 19 root 2960 April 11 12:59 dev drwxr-xr-x. 81 root 4096 September 5 17:09 etc drwxr-xr-x. 2 root 4096 April 11 12:59 home lrwxrwxrwx 1 root 7 August 26 22:36 lib-> usr/lib lrwxrwxrwx 1 root 9 August 26 22:36 lib64-> usr/lib64 drwx-. 2 root 16384 October 15 2017 lost+found drwxr-xr-x. 2 root 4096 April 11 12:59 media drwxr-xr-x. 2 root 4096 April 11 12:59 mnt drwxr-xr-x. 3 root 4096 August 26 22:40 opt drwxr-xr-x 2 root 4096 August 26 23:00 patch dr-xr-xr-x 110 root 0 April 11 12:59 proc dr-xr-x---. 12 root 4096 September 15 22:18 root drwxr-xr-x 26 root 760 September 7 21:50 run lrwxrwxrwx 1 root 8 August 26 22:36 sbin-> usr/sbin drwxr-xr-x. 2 root 4096 April 11 12:59 srv dr-xr-xr-x 13 root 0 April 11 12:59 sys drwxr-xr-x 3 root 4096 September 15 22:18 test drwxrwxrwt. 9 root 4096 September 15 03:19 tmp drwxr-xr-x. 13 root 4096 August 26 22:36 usr drwxr-xr-x. 19 root 4096 August 26 22:55 var drwxr-xr-x 6 root 4096 August 26 22:39 www 10.ls-li displays the index number of the file [root@iz2ze76ybn73dvwmdij06zz /] # ls-li

Ls-li displays the index number of the file

[root@iz2ze76ybn73dvwmdij06zz /] # ls-li total amount 72 7628 lrwxrwxrwx 1 root root July August 26 22:36 bin-> usr/bin 1179650 dr-xr-xr-x. 5 root root 4096 August 26 22:39 boot 4923-rw-r--r-- 1 root root 0 September 15 22:20 c 1026 drwxr-xr-x 19 root root 2960 April 11 12:59 dev 917505 drwxr-xr-x. 81 root root 4096 September 5 17:09 etc 655362 drwxr-xr-x. 2 root root 4096 April 11 12:59 home 17 lrwxrwxrwx 1 root root 7 August 26 22:36 lib-> usr/lib 13 lrwxrwxrwx 1 root root 9 August 26 22:36 lib64-> usr/lib64 11 drwx-. 2 root root 16384 October 15 2017 lost+found 786434 drwxr-xr-x. 2 root root 4096 April 11 12:59 media 131074 drwxr-xr-x. 2 root root 4096 April 11 12:59 mnt 393219 drwxr-xr-x. 3 root root 4096 August 26 22:40 opt 1966081 drwxr-xr-x 2 root root 4096 August 26 23:00 patch 1 dr-xr-xr-x 110 root root 0 April 11 12:59 proc 131073 dr-xr-x---. 12 root root 4096 September 15 22:18 root 218 drwxr-xr-x 26 root root 760 September 7 21:50 run 15 lrwxrwxrwx 1 root root 8 August 26 22:36 sbin-> usr/sbin 393220 drwxr-xr-x. 2 root root 4096 April 11 12:59 srv 1 dr-xr-xr-x 13 root root 0 April 11 12:59 sys 2097153 drwxr-xr-x 3 root root 4096 September 15 22:18 test 393217 drwxrwxrwt. 9 root root 4096 September 15 03:19 tmp 1048578 drwxr-xr-x. 13 root root 4096 August 26 22:36 usr 262145 drwxr-xr-x. 19 root root 4096 August 26 22:55 var 1441793 drwxr-xr-x 6 root root 4096 August 26 22:39 www

Ls-lt creates files an and b in reverse order of modification time

[root@iz2ze76ybn73dvwmdij06zz test] # ls-lt Total usage 0-rw-r--r-- 1 root root 0 September 15 22:18 b-rw-r--r-- 1 root root 0 September 15 22:18 a

Ls-version

[root@iz2ze76ybn73dvwmdij06zz test] # ls-- version ls (GNU coreutils) 8.22 Copyright (C) 2013 Free Software Foundation, Inc. License: GPLv3+:GNU General Public license version 3 or later. This software is free: you are free to modify and redistribute it. There is no other guarantee within the scope of the law. Written by Richard M. Stallman and David MacKenzie. Cat

Cat is also a relatively high frequency command. More officially, commands are used to link files and print them to standard output devices. This text output command can be used to view the contents of the file, create content, and so on. Here are some practical uses. Command format: cat [options]... [file].

Cat-n View and display line number

[root@iz2ze76ybn73dvwmdij06zz linuxdemo] # cat-n a 1 this is a txt 2 hello every body 3 hello world 4

Cat creates an empty file b

[root@iz2ze76ybn73dvwmdij06zz linuxdemo] # cat > b aa because off work > > EOF [root@iz2ze76ybn73dvwmdij06zz linuxdemo] # cat a today is a good day because off work

Cat displays the contents of multiple files at the same time (b write happy)

[root@iz2ze76ybn73dvwmdij06zz linuxdemo] # cat a > b [root@iz2ze76ybn73dvwmdij06zz linuxdemo] # cat b today is a good day because off work

Additional content can be seen that the content is appended after using a series of >

[root@iz2ze76ybn73dvwmdij06zz linuxdemo] # cat a > > b [root@iz2ze76ybn73dvwmdij06zz linuxdemo] # cat b today is a good day because off work today is a good day because off work

Cat-help (if you want to learn more, you can try it yourself)

[root@iz2ze76ybn73dvwmdij06zz linuxdemo] # cat-- help usage: cat [option]. [file]. Output [file] or standard input combination to standard output. -A,-- show-all equals-vET-b,-- number-nonblank for non-empty output lines-e equals-vE-E,-- show-ends displays "$"-n at the end of each line,-- number for all output line numbers-s -- squeeze-blank does not output multiple blank lines-t is equivalent to-vT-T,-- show-tabs displays tabbed characters as ^ I-u (ignored)-v,-- show-nonprinting uses ^ and M-references Except for LFD and TAB-- help displays this help and exits-- version displays version information and exits. If no file is specified, or if the file is "-", it is read from standard input. Example: cat f-g outputs the contents of f first, then the contents of standard input, and finally the contents of g. Cat copies the contents of standard input to standard output. GNU coreutils online help: please report translation errors in cat to get the complete documentation, run: info coreutils' cat invocation' user rights

Everyone knows that linux is a multi-tasking, multi-user operating system. Multiple users can perform different tasks in the operating system at the same time, and a user can also log in to multiple individuals. Generally speaking, root has the greatest permissions. The database we often use will generally use a mysql user, and we may use an www account for web pages. Everyone knows the story of deletion and running away, so some operation permissions need to be managed by special personnel. In order to study systematically, I think it is necessary to know its basic knowledge.

Linux role classification

Superuser: root (user id-- UID) 0 has the highest administrative rights.

Ordinary users:

System user UID:1-999 (rhel7 centos7) 1-499 (rhel6)

Local user UID:1000+ (rhel7 centos7) 500 + (rhel6)

UID: user ID, unique ID.

Linux group classification

Group:

Group classification:

Classify according to the function of the account:

Superuser group: root GID:0

Normal user groups:

System user group: GID 1 Murray 999

Local user group: GID 1000 +

Relationship between linux users and groups

A user belongs to a group or can belong to multiple groups, multiple users can be in one group, can be in multiple groups.

Related profiles for linux users and groups

1./etc/passwd: user and attribute information.

2./etc/group: group and attribute information.

3./etc/shadow: user password and attribute information.

4./etc/gshadow: group password and attribute information.

5./etc/default/useradd: sets the add user rule file.

6./etc/login.defs: set user account limits.

Linux user information file

The most important file in user management, which is open to all users, each line stores one user's information, and each attribute is separated by a colon.

Cat / etc/passwd root:x:0:0:root:/root:/bin/zsh bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

For example: root:x:0:0:root:/root:/bin/zsh

1. Login user name: root

two。 User password placeholder: X

3. User UID:0

4. User group GID:0

5. Description of user account: root

6. User home directory location: / root

7. User default shell:/bin/zsh (default is / bin/bash)

Linux password information file

Only root users have read access to this file, each line stores a user's record, and each attribute is separated by a colon.

Cat / etc/shadow root:$6 $LxE7qiaZ$ZZXf/aCO1Zqs1oOS9WDutUk9rFOq4MOoSG9IeXq2f5sduGrgfYvzOWHZmJZFGC.0Of1DjCna0M.oQZTY8r00/.:17769:0:99999:7::: bin:*:17110:0:99999:7::: daemon:*:17110:0:99999:7:::

For example: bin:*:17110:0:99999:7:::

1. Login user name: bin

two。 Encrypted password: * indicates that the password is locked

3. Date of last password change: 17110 represents the number of days that the password cannot be changed from 1970-1-1.

4. Password change period: 99999 means never to change, if it is another number, it indicates how many days from 1970-1-1 must change the password.

5. Maximum valid days for changing the password: represents the maximum number of days for the password to remain valid.

6. Password expiration warning: how many days before the password officially expires (- 1, never prompted)

7. How many days after the expiration of the password disabled users: can log in, single can not operate.

8. Date the user is banned: how many days after the account expires and cannot log in.

9. Reserved parameter

Linux group information file

The group information of the user group is stored here, one group record per line, and the attributes are separated by colons.

➜~ cat / etc/group root:x:0: bin:x:1: daemon:x:2: sys:x:3: adm:x:4: tty:x:5: disk:x:6: lp:x:7: mem:x:8: kmem:x:9:

For example: root:x:0:

1. Group name: root

two。 Group password placeholder: X

3. Group GID: 0

Install package management basics

I believe that most people should be like me, start with windows, then in the windows platform installation package is all too familiar, such as .exe, is not too common, generally installed in windows mysql, I believe .msi has also seen. Most servers are linux, so let's learn the basics of the linux installation package. The tools used by systems in different distributions are also different. At present, most corporate servers are based on centos, so there will be more examples of centos in the future.

Based on redhat

Yum

Zypper

Rpm

Based on centos

Yum

Rpm

Rpm

Full name: Redhat Package Manager

Download URL: http://rpmfind.net

Let's first take a look at the naming format of the package, taking rpm-5.4.10-10.i586.rpm as an example.

Rpm: package name

5: major version number

4: minor version number

10: revision number

I586: cpu architecture platform

Rpm: package suffix

Yum

Solve the dependency problem of software package installation, download the software package automatically, based on cUnix architecture. The repo file is the configuration file of the yum source, which defines the information of the software repository. Why it is said to be the rpm s architecture, the original head of the software (header) will record the dependency information of the modified software, so you can analyze the content of the header, you can know its related dependencies, and record this information. Then the server provides these rpm packages, then analyzes the dependencies of the packages, and stores the records in a directory on the server. When installing the software, the client downloads its record dependency file and analyzes it, and finally downloads it at one time.

The Foundation of process Management

Generally speaking, programs are divided into two categories, one is system program, the other is application program. When a program is run, it can be said to be a process, which takes up memory space, and when you kill and enter the city, resources will be released.

Type of process

User process: the user's own program, the user can control his opening and closing.

Interactive process: a process that interacts with a user.

Batch process: a collection of processes that start other processes sequentially.

Daemon: a process that runs all the time. Crond.

Properties of the process

Process ID: (pid) A unique numeric indication that distinguishes different processes.

Processes have parent processes and child processes.

The user ID (uid) who started the process and the user's subordinate group.

Three states of the process:

Run-R

Dormancy-S

Zombies-Z

Priority of the process: value range (- 20). The smaller the value, the higher the priority. The default is 0.

The terminal to which the process is linked.

Resource consumption by the process.

The relationship between parent and child processes

The relationship between father and son, the father manages the son. When the parent process terminates, the child process must terminate, but when the child process terminates, the parent process does not necessarily terminate.

Process management tool

Ps: view the progress.

Top: you can view the dynamic information of the process.

Kill: kill process.

Pstree: view the process tree.

Pgrep: search the process.

Lsof: view the files opened by the process.

Process management practice

Ps

Statically displays information about the current process.

Command: ps

Syntax: ps parameter

Common parameters:

A shows the progress of all users

R shows running processes

L long format output

U displays the process in the order of user name and startup time

F displays the process in a tree format

X shows the process without controlling the terminal

Operation: BSD format to display the process

➜~ ps aux USER PID% CPU% MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 43364 3596? Ss November 03 0:01 / usr/lib/syst root 2 0.000? S November 03 0:00 [kthreadd] root 3 0.0 0.0 00? S November 03 0:00 [ksoftirqd/0] root 5 0.00.0 00? S

< 11月03 0:00 [kworker/0:0H root 7 0.0 0.0 0 0 ? S 11月03 0:00 [migration/0] root 8 0.0 0.0 0 0 ? S 11月03 0:00 [rcu_bh] root 9 0.0 0.0 0 0 ? S 11月03 0:05 [rcu_sched] root 10 0.0 0.0 0 0 ? S 11月03 0:00 [watchdog/0] root 11 0.0 0.0 0 0 ? S 11月03 0:00 [watchdog/1] root 12 0.0 0.0 0 0 ? S 11月03 0:00 [migration/1] root 13 0.0 0.0 0 0 ? S 11月03 0:00 [ksoftirqd/1] root 15 0.0 0.0 0 0 ? S< 11月03 0:00 [kworker/1:0H 标准格式显示进程unix风格 ~ ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 11月03 ? 00:00:01 /usr/lib/systemd/systemd --syste root 2 0 0 11月03 ? 00:00:00 [kthreadd] root 3 2 0 11月03 ? 00:00:00 [ksoftirqd/0] root 5 2 0 11月03 ? 00:00:00 [kworker/0:0H] root 7 2 0 11月03 ? 00:00:00 [migration/0] root 8 2 0 11月03 ? 00:00:00 [rcu_bh] root 9 2 0 11月03 ? 00:00:05 [rcu_sched] root 10 2 0 11月03 ? 00:00:00 [watchdog/0] root 11 2 0 11月03 ? 00:00:00 [watchdog/1] root 12 2 0 11月03 ? 00:00:00 [migration/1] root 13 2 0 11月03 ? 00:00:00 [ksoftirqd/1] root 15 2 0 11月03 ? 00:00:00 [kworker/1:0H] root 17 2 0 11月03 ? 00:00:00 [kdevtmpfs] root 18 2 0 11月03 ? 00:00:00 [netns] root 19 2 0 11月03 ? 00:00:00 [khungtaskd] root 20 2 0 11月03 ? 00:00:00 [writeback] root 21 2 0 11月03 ? 00:00:00 [kintegrityd] 属性详解: USER: 进程的属主 PID: 进程的ID %CPU: 进程占cpu百分比 %MEM: 进程占内存的百分比 VSZ: 进程占用虚拟内存大小 RSS: 固定内存使用数量 STAT 进程状态 R 正在运行可中在队列中可过行的; S 处于休眠状态; T 停止或被追踪; Z 僵尸进程; N 优先级较低的进程 L 有些页被锁进内存; s 进程的领导者(在它之下有子进程) START 启动进程的时间; TIME 进程消耗CPU的时间; COMMAND 命令的名称和参数; 按照指定属性排序: 按照cpu从小到大排序。 ➜ ~ ps aux --sort %cpu USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 43364 3596 ? Ss 11月03 0:01 /usr/lib/syst root 2 0.0 0.0 0 0 ? S 11月03 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S 11月03 0:00 [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S< 11月03 0:00 [kworker/0:0H root 7 0.0 0.0 0 0 ? S 11月03 0:00 [migration/0] root 8 0.0 0.0 0 0 ? S 11月03 0:00 [rcu_bh] root 9 0.0 0.0 0 0 ? S 11月03 0:05 [rcu_sched] root 10 0.0 0.0 0 0 ? S 11月03 0:00 [watchdog/0] root 11 0.0 0.0 0 0 ? S 11月03 0:00 [watchdog/1] 按照cpu从大到小排序。 ➜ ~ ps aux --sort -%cpu USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 21342 0.3 0.4 137184 17112 ? Ssl 03:24 1:16 /usr/local/aegi root 1 0.0 0.0 43364 3596 ? Ss 11月03 0:01 /usr/lib/syst root 2 0.0 0.0 0 0 ? S 11月03 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S 11月03 0:00 [ksoftirqd/0] root 5 0.0 0.0 0 0 ? S< 11月03 0:00 [kworker/0:0H root 7 0.0 0.0 0 0 ? S 11月03 0:00 [migration/0] root 8 0.0 0.0 0 0 ? S 11月03 0:00 [rcu_bh] root 9 0.0 0.0 0 0 ? S 11月03 0:05 [rcu_sched] root 10 0.0 0.0 0 0 ? S 11月03 0:00 [watchdog/0] root 11 0.0 0.0 0 0 ? S 11月03 0:00 [watchdog/1] root 12 0.0 0.0 0 0 ? S 11月03 0:00 [migration/1] root 13 0.0 0.0 0 0 ? S 11月03 0:00 [ksoftirqd/1] top 与ps相反的是top命令可以查看进程的动态信息。 命令: top 语法: top 参数 常用参数: 操作: ➜ ~ top top - 11:38:42 up 13:15, 2 users, load average: 0.01, 0.03, 0.05 Tasks: 98 total, 1 running, 97 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.2 us, 0.0 sy, 0.0 ni, 99.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 3881688 total, 229264 free, 543932 used, 3108492 buff/cache KiB Swap: 1049596 total, 1049596 free, 0 used. 3026944 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 20 0 43364 3596 2340 S 0.0 0.1 0:01.79 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:00.14 ksoftirqd/0 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:+ 7 root rt 0 0 0 0 S 0.0 0.0 0:00.33 migration/0 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh 9 root 20 0 0 0 0 S 0.0 0.0 0:05.73 rcu_sched 属性解释: 前五行是数据的整理统计信息。 第一行: 11:38:42 当前时间 up 13:15 系统运行时间,格式为时:分 2 user 当前登陆用户数量 load average: 0.01, 0.03, 0.05 系统负载,任务队列平均长度 1分钟,5分钟,15分钟前到现在的平均值。 第二三行: 98 total 进程总数量 1 running 正在运行的进程数量 97 sleeping 睡眠的进程数量 0 stopped 停止的进程数量 0 zombie 僵尸进程数量 %Cpu(s): 0.2 us 系统用户进程使用cpu百分比 0.0 sy 内核进程占用cpu百分比 0.0 ni 用户进程空间内改变过优先级的进程占用cpu百分比 99.8 id 空闲cpu百分比 0.0 wa 等待输入输出的cpu时间百分比 0.0 hi 硬件cpu中断占用百分比 0.0 si 软中断占用百分比 0.0 st 虚拟机占用百分比 第四五行: Mem : (单位K) 3881688 total 物理内存总量 229264 free 空闲内存总量 543932 used 使用的物理内存总量 3108492 buff/cache 内核缓存的内存量 Swap: (单位K) 1049596 total 交换区总量 1049596 free 空闲交换区总量 0 used 使用的交换区总量 3026944 avail Mem 可利用的内存量 标题行: PID: 进程id USER: 进程所有者用户名 PR: 优先级 NI: 进程优先级,nice值,负值 ->

High priority, positive value-> low priority

VIRT: total virtual memory virt=swap + res

RES: actual memory usage

SHR: shared memory size

S: process statu

D: uninterruptible sleep state r: run s: sleep t: track z: zombie process

% CPU:% cpu time elapsed since last update

% MEM: percentage of physical memory used by processes

Total time spent using cpu by the TIME+: process (in 100 seconds)

COMMAND: command line

Kill

Command: kill

Syntax:

Kill [- s signal |-p] [- Q sigval] [- a] [- -] pid... Kill-l [signal]

Common parameters:

-l list all signal names

-s specifies the signal to be sent (default)

-u specified user

Action: list all signal names

➜~ kill-l HUP INT QUIT ILL TRAP ABRT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH POLL PWR SYS

Compulsory termination

➜~ kill-9 23423

Termination

➜~ kill-15 22323

Kill all processes of the specified user

➜~ kill-u superh

Proc directory

This directory contains information about the kernel and the running status of the process.

➜/ proc ls 1 21320 21628 240 392 7 diskstats loadavg swaps 10 21342 21976 242 42 722 dma locks sys 10353 21465 21977 243 44 7561 driver mdstat sysrq-trigger 10509 21613 21978 244 442 8 execdomains meminfo sysvipc 107 21614 22 249 45 803 fb misc timer_list 11 21615 220 26 46 8179 filesystems modules timer_stats 11010 21616 22285 261 466 8307 fs mounts tty 11102 21617 22287 262 467 8327 interrupts mtrr uptime 12 21618 22361 267 469 9 iomem net version 13 21619 22363 268 476 acpi ioports pagetypeinfo vmallocinfo 14461 21620 22396 3 477 buddyinfo irq partitions Vmstat 15 21621 22467 31 485 bus kallsyms sched_debug zoneinfo 17 21622 225 3198 5 cgroups kcore schedstat 18 21623 229 32 505 cmdline keys scsi 19 21624 23 33 506 consoles key-users self 2 21625 23884 336 5217 cpuinfo kmsg slabinfo 20 21626 23885 34 5515 crypto kpagecount softirqs 21 21627 24 357 65 devices kpageflags stat

Each label above is the directory name named after the pid of our current process.

Free

Check the memory used and free by the system.

Command: free

Syntax: free parameter

Common parameters:

-b,-- bytes byte is displayed in units.

-k,-- kilo k is displayed in units

-m,-- mega m is displayed in units

-g,-- giga g is displayed in units

Action:

➜~ free-m total used free shared buff/cache available Mem: 3790 536 210 2 3043 2950 Swap: 1024 0 1024

The unit is displayed in g.

➜~ free-h total used free shared buff/cache available Mem: 3.7g 538M 207M 2.4m 3.0G 2.9g Swap: 1.0G 0B 1.0G file search

When doing things related to operation and maintenance, we have to check files of one kind or another. Generally speaking, we may check, for example, where the file with the name xxx.conf is, where the log is, or the location of some executable file.

Overview

Which: view the location of the execution file.

Whereis: view the executable location and related files.

Locate: work with database caching to quickly view the location of files.

Grep: filter matches, it is a file search tool.

Find: you can view files based on conditions.

Which

Command: which

Syntax: which parameter query target

Common commands: generally used without parameters

-- all,-a shows all matching paths

Action:

➜~ which pwd / usr/bin/pwd

Whereis

Command: whereis

Syntax: whereis parameter query target

Common commands:

Generally used without parameters.

-b search only binaries

-B defines the binary file lookup path

-m search only man manual

-M defines the man manual lookup path

-s only search the source code

-S defines the source code lookup path

Action:

➜~ whereis ls ls: / usr/bin/ls / usr/share/man/man1/ls.1.gz

Locate

Command: locate

Syntax: locate file name

Common parameters: none

Operation: locate and find command functions are similar, but the search efficiency is higher, because locate looks for the database and find looks for directory files.

Database:

➜~ ls / var/lib/mlocate/mlocate.db / var/lib/mlocate/mlocate.db

Related profile:

➜~ ls / etc/updatedb.conf / etc/updatedb.conf

Related scheduled tasks:

➜~ ls / etc/cron.daily/mlocate / etc/cron.daily/mlocate

For example:

➜~ touch shafa➜ ~ locate shafa ➜~ updatedb➜ ~ locate shafa / root/shafa

Note: if we look up the new files on the same day, we need to updatedb manually.

Grep

Command: grep

Syntax: grep parameter target value file

Common parameters:

-v inversion

-I ignore case

Print line number at the same time as-n output

^ * begins with *

* $ends with *

^ $blank line

Action:

Check / etc/passwd has the line of root

➜~ grep root / etc/passwd root:x:0:0:root:/root:/bin/zsh operator:x:11:0:operator:/root:/sbin/nologin

Check / etc/passwd lines without root (more content, forbidden to display a few lines)

➜~ grep-v root / etc/passwd bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync

Check / etc/passwd the line with www and display the line number

➜~ grep-n www / etc/passwd 23:www:x:1000:1000::/home/www:/sbin/nologin

Find

Command: find

Syntax: find path parameter output

Common parameters:

Path: for example, with. To represent the current directory and / to represent the system root directory. -print: displays "\ n" as delimiter, line feed-print0: used with xargs, with "\ 0" as delimiter

Find common command options:

-name looks for files by file name. "name"

-perm looks for files according to file permissions. 666 777, etc.

-when depth looks for files, it first looks for the files in the current directory, and then looks in its subdirectories

-user finds the file according to the owner of the file

-atime-ctime (in days)

-mmin-cmin-amin (in minutes)

-size n [c] finds files with n blocks of file length, with c indicating that the file length is in bytes

-follow if the find command encounters a symbolic link file, it tracks to the file that the link points to.

Action:

Check the current directory under test. Beginning of the file

➜~ find. -name "test*". / test.txt. / autojump/tests. / test.1

Check the current directory under test. At the beginning of the file, the output results are displayed on a new line (default)

➜~ find. -name "test*"-print. / test.txt. / autojump/tests. / test.1

Check the current directory under test. For the file at the beginning, the output is not displayed on a new line

➜~ find. -name "test*"-print0. / test.txt./autojump/tests./test.1

Execute the appropriate command on what you are looking for

Default execution action:-print

Common actions:

-exec this parameter can be followed by a custom shell command

Action:

Query the file at the end of .txt and query its more properties with ls

➜test find. -name "* .txt"-exec ls-l {}\;-rw-r--r-- 1 root root 0 November 4 14:56. / xq1.txt-rw-r--r-- 1 root root 0 14:56. / xq.txt-rw-r--r-- 1 root root 0 November 4 14:56. / xq2.txt

Query the file at the end of .txt and become the file at the end of .bak

➜test find. -name "* .txt"-exec mv {} {}. Bak\; ➜test ls xq1.txt.bak xq2.txt.bak xq.txt.bak

Logical query:

-an and-o or + above-below

Action: check the file at the end of .sh or .q.

➜test find. -name "* .sh"-o-name "* .Q". / book.q. / stop.sh. / start.sh

Look at the file that ends .sh and begins with s.

➜test find. -name "* .sh"-a-name "s*". / stop.sh. / start.sh

View after inserting content in the file.

Total ➜test ll dosage 12K-rw-r--r-- 1 root root 9 November 4 15:10 book.q-rw-r--r-- 1 root root 13 November 4 15:10 start.sh-rw-r--r-- 1 root root 4 November 4 15:10 stop.sh-rw-r--r-- 1 root root 0 November 4 14:56 xq1.txt.bak-rw-r--r-- 1 root root 0 November 4 14 : 56 xq2.txt.bak-rw-r--r-- 1 root root 0 November 4 14:56 xq.txt.bak

View files with / etc greater than 40k and less than 50k

➜test find / etc/-size + 40k-a-size-50k / etc/selinux/targeted/active/modules/100/sysadm/hll / etc/selinux/targeted/contexts/files/file_contexts.homedirs.bin are all the contents of this article entitled "what are the Common commands in Linux"? thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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