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 60 commands that Linux must learn?

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

In this issue, the editor will bring you about the 60 commands that must be learned in Linux. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

In Linux, everything is a file, and Linux system management is the core of normal operation. The editor will explain to you the 60 commands that must be met in Linux system management.

* df*

1. Action

The df command is used to check the disk footprint of the file system, with permissions for all users.

two。 Format

Df [options]

3. Main parameters

-s: only the total number of blocks occupied is given for each Names parameter.

-a: recursively displays the number of data blocks occupied by each file in the specified directory and in each subdirectory. If neither-s nor-an is specified, only the number of disk blocks occupied by each directory and its subdirectories in the Names is displayed.

-k: lists disk space usage in 1024 bytes.

-x: directories skipped on different file systems are not counted.

-l: calculate all file sizes and multiple times for hard-linked files.

-I: displays inode information instead of block usage.

-h: print out the file system size in an easy-to-understand format, such as 136KB, 254MB, 21GB.

-P: use the POSIX output format.

-T: displays the file system type.

4. Description

The df command is widely used to generate file system usage statistics, which can display information about all file systems in the system, including total capacity, available free space, current mount points, and so on.

When using the df command, a super-privileged user will find that the capacity of a partition exceeds 100%. This is because the Linux system reserves 10 per cent of the space for superusers, which is at their disposal. In other words, for a superuser, the capacity of the hard drive he sees will be 110%. This arrangement is good for system management, and the system administrator can work normally when the capacity of the hard disk is close to 100%.

5. Application example

Linux supports many file systems, including JFS, ReiserFS, ext, ext2, ext3, ISO9660, XFS, Minx, vfat, MSDOS, and so on. You can also get information about the file system when you use the df-T command to view disk space:

# df-T

File system type capacity used available used mount point

/ dev/hda7 reiserfs 5.2G 1.6G 3.7G 30% /

/ dev/hda1 vfat 2.4G 1.6G 827M 66% / windows/C

/ dev/hda5 vfat 3.0G 1.7G 1.3G 57% / windows/D

/ dev/hda9 vfat 3.0G 2.4G 566m 82% / windows/E

/ dev/hda10 NTFS 3.2G 573M 2.6G 18% / windows/F

/ dev/hda11 vfat 1.6G 1.5G 23m 99% / windows/G

From the above, you can see not only the capacity and usage of disk space, but also the file system type and mount point of the partition.

* top*

1. Action

The top command is used to display the progress of the program in execution, and the permission is for all users.

two。 Format

Top [-] [d delay] [Q] [c] [S] [s] [I] [n]

3. Main parameters

D: specifies the interval between updates, measured in seconds.

Q: there are no delayed updates. If the user has a superuser, the top command will be executed in the highest priority.

C: displays the full path and name of the process.

S: cumulative mode, which accumulates the CPU time of subtrips that have been completed or disappeared.

S: safe mode.

I: do not show any idle (Idle) or useless (Zombie) itinerary.

N: displays the number of updates, and will exit top after completion.

4. Description

Top command is one of the main commands of Linux system management, through which a lot of information can be obtained. Here we combine figure 1 to illustrate the information it gives.

Figure 1 display of the top command

In figure 1, the items represented in the first line are the current time, the system startup time, the number of current system login users, and the average load. The second line shows all started, currently running, Sleeping, and Zombie processes. The third line shows the current usage of CPU, including the percentage occupied by the system, the percentage of users using it, and the percentage of idle (Idle). The fourth line shows the physical memory usage, including the total available memory, used memory, free memory, and memory occupied by buffers. The fifth line shows the swap partition usage, including the total swap partition, used, idle, and the size used for caching. The sixth line shows the most items, and a detailed explanation is listed below.

PID (Process ID): the process identification number.

USER: the user name of the process owner.

PR: the priority of the process.

NI: the priority value of the process.

VIRT: the virtual memory value occupied by the process.

RES: the physical memory value occupied by the process.

SHR: the shared memory value used by the process.

S: the state of the process, where S indicates hibernation, R indicates running, Z indicates dead state, and N indicates that the process priority value is negative.

% CPU: the CPU usage occupied by this process.

% MEM: the percentage of physical memory and total memory consumed by the process.

TIME+: the total CPU time spent by the process since it was started.

Command: the name of the startup command that the process starts. If this line is not displayed, the process will have a complete command line.

During the use of the top command, you can also use some interactive commands to complete the functions of other parameters. These commands are started by shortcut keys.

Refresh immediately.

P: sort by CPU usage size.

T: sort according to time and cumulative time.

Q: exit the top command.

M: toggles the display of memory information.

T: toggles the display of process and CPU status information.

C: toggles the display command name and the full command line.

M: sort by the amount of memory used.

W: writes the current settings to the ~ / .toprc file. This is the recommended way to write top configuration files.

As you can see, the top command is a very powerful tool for monitoring the system, especially for system administrators. However, its disadvantage is that it consumes a lot of system resources.

5. Application example

Use the top command to monitor specified users, and the default is to monitor the processes of all users. If you want to see the situation of the specified user, press the "U" key in the terminal, and then enter the user name, and the system will switch to the process running interface of the specified user, as shown in figure 2.

Figure 2 using the top command to monitor the specified user

* free*

1. Action

The free command is used to show memory usage, with permissions for all users.

two。 Format

Free [- b |-k |-m] [- o] [- s delay] [- t] [- V]

3. Main parameters

-b-k-m: displays memory usage in bytes (KB, MB), respectively.

-s delay: displays the number of seconds per second to show memory usage.

-t: displays the memory sum column.

-o: the buffer adjustment column is not displayed.

4. Application example

The free command is the main command used to view memory usage. Compared with the top command, it has the advantage of being easy to use and consuming only a small amount of system resources. With the-S parameter, you can use the free command to continuously monitor how much memory is used, so that it can be used as a convenient real-time monitor.

# free-b-S5

After using this command, the terminal will continuously report memory usage (in bytes), updated every 5 seconds.

* quota*

1. Action

The quota command is used to display disk usage and restrictions, with privileges superuser.

two。 Format

Quota [- g] [- u] [- v] [- p] username group name

3. Parameters.

-g: displays the disk usage limit for the group to which the user belongs.

-u: displays the user's disk usage limit.

-v: displays the allocation of file systems with no allocated space.

-p: displays simplified information.

4. Application example

Disk quota is very important in enterprise applications, and ordinary users should learn to understand their own disk usage. To query your own disk quota, use the following command (in the following example, the user account is caojh):

# quota caojh

Disk quotas for user caojh (uid 502):

Filesystem blocks quota limit grace files quota limit grace

/ dev/hda3 58 200000 400000 41 500 1000

The above shows the caojh account with ID number 502, the number of files is set to 500 million, and the hard disk space limit is set to 200MB~400MB. Once disk quotas are about to be used up, you need to delete some junk files or request additional quotas from your system administrator.

* at*

1. Action

The at command is used to execute a specified sequence of commands at a specified time.

two。 Format

At [- V] [- Q x] [- f file] [- m] time

3. Main parameters

-V: displays standard error output.

-Q: many queue outputs.

-f: read the job from the file.

-m: send an email to the user after the job is executed.

Time: sets the time when the job is executed. The time format has strict requirements and consists of offsets of hours, minutes, dates, and times, where the format of the date is MM.DD.YY,MM is minutes, DD is date, and YY is year. The offset is in the format of time + offset in minutes, hours, and days.

4. Application example

# at-f data 15:30 + 2 days

The above command instructs the system to execute the job specified in the file data at 17:30 two days later.

* lp*

1. Action

Lp is the command to print files, and the permission is for all users.

two。 Format

Lp [- c] [- d] [- m] [- number] [- title] [- p]

3. Main parameters

-c: copy the file before printing.

-d: print queue files.

-m: send an email to the user after printing.

-number: number of printed copies.

-title: print the title.

-p: sets the priority of printing, up to 100.

4. Application example

(1) use lp command to print multiple files

# lp 2 3 4

Request id is 11 (3 file (s))

Where 2, 3, and 4 are file names, respectively; "request id is 11 (3 file (s))" indicates that this is the 11th print command, printing the three files in turn.

(2) set printing priority

# lp lp-d LaserJet-p 90 / etc/aliases

By adding "- p 90", the priority of the print job is 90. It will print before print jobs with a priority lower than 90, including jobs that have no priority set, and the default priority is 50

* useradd*

1. Action

The useradd command is used to set up a user account and create a starting directory for the user, and the permission is superuser.

two。 Format

Useradd [- d home] [- s shell] [- c comment] [- m [- k template]] [- f inactive] [- e expire] [- p passwd] [- r] name

3. Main parameters

-c: add the comment text, which is saved in the remarks column of passwd.

-d: specify the starting directory when the user logs in.

-D: change the default value.

-e: specifies the validity period of the account, which is permanent by default.

-f: specify how many days after the password expires to close the account.

-g: specify the group to which the user belongs.

-G: specifies the additional group to which the user belongs.

-m: automatically establish the login directory of the user.

-M: do not automatically create a user's login directory.

-n: cancels the establishment of a group with the user name.

-r: set up a system account.

-s: specifies the shell to be used by the user after logging in.

-u: specify the user ID number.

4. Description

Useradd can be used to set up a user account, which is the same as the adduser command. After the account is set up, use passwd to set the password of the account. The account created with the useradd command is actually saved in the / etc/passwd text file.

5. Application example

Set up a new user account and set up ID:

# useradd caojh-u 544

It should be noted that the ID value should be greater than 500 as far as possible to avoid conflict. Because some special users will be established after Linux installation, values between 0 and 499 are generally reserved for system accounts such as bin and mail.

* groupadd*

1. Action

The groupadd command is used to add a new group to the system.

two。 Format

Groupadd [- g gid] [- o]] [- r] [- f] groupname

3. Main parameters

-g gid: specify the group ID number.

-o: group ID number is allowed. It doesn't have to be unique.

-r: join the group ID, which is lower than the 499 system account.

-f: the development program exits when you join an existing group.

4. Application example

Create a new group and set up the group ID to join the system:

# groupadd-g 344 cjh

At this point, a project with group ID (GID) 344 is generated in the / etc/passwd file.

* kill*

1. Action

The kill command is used to abort a process.

two。 Format

Kill [- s signal |-p] [- a] pid...

Kill-l [signal]

3. Parameters.

-s: specifies the signal to be sent.

-p: analog transmission signal.

-l: specifies the name list of the signal.

Pid: the ID number of the process to be aborted.

Signal: indicates a signal.

4. Description

Process is a very important concept in Linux system. Linux is a multitasking operating system on which multiple processes are often running at the same time. We don't care how these processes are allocated, or how the kernel manages the allocated time slices, what we care about is how to control these processes so that they can serve users well.

The Linux operating system includes three different types of processes, each with its own characteristics and attributes. An interactive process is a process started by a Shell. Interactive processes can be run either in the foreground or in the background. The batch process has no connection with the terminal and is a process sequence. Monitor the process (also known as the system daemon) that the Linux system starts when it starts and runs in the background. For example, httpd is the monitoring process of the famous Apache server.

The kill command works by sending a system operation signal and the process identification number of a program to the kernel of the Linux system, and then the kernel can operate on the process specified by the process identification number. For example, in the top command, we see that the system is running many processes, and sometimes we need to use kill to abort certain processes to improve system resources. When explaining the installation and login commands, it was mentioned that the function of multiple virtual consoles of the system is that when a program goes wrong and causes the system deadlock, you can switch to another virtual console to close the program. The command used at this point is kill, because kill is something that most Shell internal commands can call directly.

5. Application example

(1) forcibly abort (often kill) a process with identification number 324:

# kill-9 324

(2) unlock the Linux system

It sometimes happens in Linux that a program crashes and is in a deadlock state. At this point, there is generally no need to restart the computer, just stop (or close) the problematic program. When kill is in the X-Window interface, the main programs (except for crashed programs) are generally started normally. At this point, open a terminal and abort the problematic program there. For example, if a Mozilla browser program is locked, you can use the kill command to abort all programs that contain Mozolla browsers. First use the top command to check the program's PID, and then use the kill command to stop the program:

# kill-SIGKILL XXX

Where XXX is the process identification number of the program that contains the Mozolla browser.

(3) use the command to reclaim memory

We know that memory is very important to the system, and recycling memory can improve system resources. The kill command can stop some "deviant" programs in time or have no corresponding programs for a long time. For example, to find a Zombie process using the top command, you can use the following command:

# kill-9 XXX

Where XXX is a useless process identification number.

Then use the following command:

# free

At this point, you will find that the amount of available memory has increased.

(4) killall command

Linux also provides a killall command that can directly use the name of the process instead of the process identification number, for example:

# killall-HUP inetd

* crontab*

1. Action

The crontab configuration file can be modified using the crontab command, which is then executed by the cron utility at the appropriate time, with permissions for all users.

two。 Format

Crontab [- u user] file

Crontab [- u user] {- l |-r |-e}

3. Main parameters

-e: execute a text editor to set the schedule. The internal text editor is vi.

-r: delete the current schedule.

-l: list the current schedule.

The format of crontab file is "M H D md cmd". Where M stands for minutes (0,59), H for hours (0,23), D for days (1mm 31), m for months (1pm 12), and d for days of the week (0,6pm 0 is Sunday). Cmd represents the program to be run, which is sent to sh for execution. This Shell has only three environment variables: USER, HOME, and SHELL.

4. Description

Compared with the at command, the crontab command is suitable for tasks with fixed cycles.

5. Application example

Set up a regular, regular system prompt:

[cao @ www cao] # crontab-e

A vi editor opens.

If you enter the following: 35 17 * * 5 wall "Tomorrow is Saturday I will go CS", then save and exit. At this point, a cao file will be produced in the / var/spool/cron/ directory, as follows:

# DO NOT EDIT THIS FILE-edit the master and reinstall.

# (/ tmp/crontab.2707 installed on Thu Jan 1 22:01:51 2004)

# (Cron version--

)

35 17 * * 5 wall "Tomorrow is Saturday I will play CS"

In this way, the system will pop up a terminal at 17: 35 every Friday, reminding you that you can play CS on Saturday!

* hands-on practice *

1. Use kill and top commands together to observe the changes in system performance

First start a terminal to run the top command, and then start a terminal to use the kill command, as shown in figure 4.

Figure 4 observe the effect of kill command on top terminal

At this point, use the kill command described above to abort some programs:

# kill SIGKILL XXX

Then look at the changes of the top command terminal, including memory capacity, CPU utilization, system load and so on. Note that some processes cannot be stopped, but you can try it when you learn the Linux command to see how the system reacts.

two。 Use the at and halt commands to shut down the computer regularly

First, set the shutdown time to 17:35, and enter the following code:

# at 17:35

Warning: commands will be executed using (in order) a) $SHELL b) login shell c) / bin/sh

At > halt `- I-p

At >

Job 6 at 2004 Mustang 01 17:35

At this point, you have actually entered the Shell of the Linux system, and write the simplest program: halt-I-p. The text ending symbol in the above Shell indicates that press the "Ctrl+D" key combination to close the command and submit the task to exit the Shell. "Job 6 at 2004 Shell 01 17:35" means that the system accepts the sixth at command and executes the command at "2004 UV 01 Muk 01 17:35": stop all network-related devices first, shut down the system and then turn off the power.

3. Using crontab command to scan virus at a fixed time every day

A simple crontab command operation has been introduced earlier, so let's look at some of the more important operations.

(1) create a file whose name is set by yourself, assuming caoproject:

# crontab-e

(2) the contents of the document are as follows:

05 09 * antivir

Save and exit after editing with vi. Antivir is a software that checks and kills Linux viruses, and of course it is installed in the system when needed.

(3) use the crontab command to add to the task list:

# crontab caoproject

In this way, all users in the system will automatically scan for viruses at 09:05 every day.

4. Use kill to make the modified configuration file take effect immediately

Windows users generally know that important profile changes often require a restart of the computer for the changes to take effect. Because of the modular design, Linux can configure the service in real time according to the needs. This paper introduces some operation skills by taking the network service inetd as an example.

Inetd is a listening daemon that listens for requirements to connect with Internet service processes (such as rlogin, telnet, ftp, rsh) and extends the required service processes. By default, these daemon that inetd listens to are listed in the / etc / inetd.conf file. By editing the / etc/inetd.conf file, you can change the option for inetd to start the server daemon, and then drive inetd to signal the current inetd process as SIGHUP (signal 1), causing inetd to reread the file. This process is implemented by the kill command.

After modifying inetd.conf with vi or another editor, first use the following command:

# ps-ef | grep inetd

The above code indicates the process number (PID) of the query inetd.conf, which is assumed to be 1426, and then use the following command:

# kill-1426 inetd

Then the configuration file takes effect.

These are the 60 Linux commands that Xiaobian shares with you. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are 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

Development

Wechat

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

12
Report