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-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Today, I will talk to you about the 60 commands that must be learned about linux. Many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

Linux must learn 60 commands: 1, the role of login is to log on to the system, its right to use is all users; 2, the function of the shutdown command is to shut down the computer, its right to use is the super user; 3, the function of the halt command is to shut down the system, and its right to use is the super user.

Linux provides a large number of commands, which can effectively complete a lot of work, such as disk operation, file access, directory operation, process management, file permission setting and so on. Therefore, working on a Linux system is inseparable from using the commands provided by the system. To really understand the Linux system

You must start with the Linux command, and you can further understand the Linux system through basic command learning.

The number of commands varies from Linux to Linux distribution, but there are more than 200 commands for the fewest Linux distributions. Here, the author divides the more important and most frequently used commands into the following six parts according to their role in the system.

◆ installation and login commands: login, shutdown, halt, reboot, install, mount, umount, chsh, exit, last

◆ file processing commands: file, mkdir, grep, dd, find, mv, ls, diff, cat, ln

◆ system management related commands: df, top, free, quota, at, lp, adduser, groupadd, kill, crontab

◆ network operation commands: ifconfig, ip, ping, netstat, telnet, ftp, route, rlogin, rcp, finger, mail, nslookup

◆ system security related commands: passwd, su, umask, chgrp, chmod, chown, chattr, sudo ps, who

◆ other commands: tar, unzip, gunzip, unarj, mtools, man, unendcode, uudecode.

This paper takes Mandrake Linux 9.1 (Kenrel 2.4.21) as an example to introduce the installation and login commands under Linux.

Immortality press: please use ctrl+f to find a part of the content or the use of a command on this page.

60 necessary commands for Linux (1)-installation and login commands

Login

1. Action

The role of login is to log in to the system, and its permissions are for all users.

two。 Format

Login [name] [- p] [- h host name]

3. Main parameters

-p: tells login to keep the current environment parameters.

-h: used to transfer user names between remote logins.

If you choose to log in to Linux in command-line mode, the first Linux command you see is login:.

The general interface looks like this:

Manddrake Linux release 9.1 (Bamboo) for i586

Renrel 2.4.21-0.13mdk on i686 / tty1

Localhost login:root

Password:

In the above code, the first line is the Linux release number, and the second line is the kernel version number and the login virtual console. We enter the login name on the third line, press the "Enter" key to enter the account password after Password, and then log in to the system. For security reasons, the characters will not be echoed on the screen and the cursor will not move when entering the account password.

After logging in, you will see the following interface (take superuser as an example):

[root@localhost root] #

Last login:Tue, Nov 18 10:00:55 on vc/1

Shown above is the virtual console logged in for the week, month, day, time, and use.

4. Application skills

Linux

Is a true multi-user operating system that allows multiple users to log in at the same time and allows a user to log in multiple times. This is because Linux, like many versions of Unix, provides a virtual console

The access method allows users to log in multiple times at the same time from the console (the console of the system is a monitor and keyboard directly connected to the system). Each virtual console can be seen as a separate workstation, workbench

Can be switched between. The switching of the virtual console can be achieved by pressing the Alt key and a function key, usually using F1-F6.

For example, after the user logs in, click "Alt+"

With the F2 key, the user can see the "login:" prompt above, indicating that the user has seen the second virtual console. Then simply press "Alt+"

A newly installed Linux system allows users to access the first six virtual consoles using the "Alt+F1" to "Alt+F6" keys. Virtual control

The most useful thing is that when a program goes wrong and causes a system deadlock, you can switch to another virtual console to work and close the program.

Shutdown

1. Action

The function of the shutdown command is to shut down the computer, and its permission is superuser.

two。 Format

Shutdown [- h] [- I] [- k] [- m] [- t]

3. Important parameters

-t: tell the init program how long it takes to shut down before changing to another run level.

K: it doesn't really turn off, it just sends a warning signal to every logger.

-h: turn off the power after shutting down.

-c:cancel current process cancels the currently executing shutdown program. So of course there is no time parameter for this option, but you can enter a message for interpretation, and this information will be sent to each user.

-F: force fsck when restarting the computer.

-time: set the time before shutdown.

-m: change the system to single-user mode.

-I: displays system information when shutting down.

4. Command description

Shutdown

Command can safely shut down the system. Some users will shut down the Linux system by directly cutting off the power supply, which is very dangerous. Because Linux is different from Windows, it runs in the background

Many processes, so forced shutdown may result in data loss of the process, leave the system in an unstable state, and even damage hardware devices (hard drives) in some systems. Use before the system shuts down

Shutdown command, the system administrator will notify all logged-in users that the system is about to shut down, and the login command will be frozen, that is, new users can no longer log in.

Halt

1. Action

The function of the halt command is to shut down the system, and its permission is superuser.

two。 Format

Halt [- n] [- w] [- d] [- f] [- I] [- p]

3. Description of main parameters

-n: prevents sync system calls, which are used after patching the root partition with fsck to prevent the kernel from overwriting the patched super block with older versions of the super block.

-w: it's not really a restart or shutdown, it's just a wtmp (/ var/log/wtmp) record.

-f: forced shutdown or restart instead of calling shutdown.

-I: turn off all network interfaces before shutting down (or rebooting).

-f: forced shutdown, do not call the command shutdown.

-p: turn off the power while shutting down the phone.

-d: shut down the system without leaving a record.

4. Command description

Halt

Is to call shutdown.

-h. When halt executes, it kills the application process, executes the sync (data stored in buffer is forced to write to the hard disk) system call, and the kernel is stopped after the file system write operation is complete. If the system

Run level 0 or 6 shuts down the system; otherwise, replace it with the shutdown directive (plus the-h argument).

Reboot

1. Action

The purpose of the reboot command is to restart the computer, and its permission is for the system administrator.

two。 Format

Reboot [- n] [- w] [- d] [- f] [- I]

3. Main parameters

-n: do not write the memory data back to the hard disk before rebooting.

W: it won't really reboot, just write the record to the / var/log/wtmp file.

-d: do not write records to the / var/log/wtmp file (the-n parameter contains-d).

-I: stop all network-related devices before rebooting.

Install

1. Action

The purpose of the install command is to install or upgrade software or backup data, and its permissions are for all users.

two。 Format

(1) install [option]... Source and destination

(2) install [option]... The source. Catalogue

(3) install-d [option]. Catalogue.

In

In the first two formats, copy to or copy multiple files to existing ones, and set the right at the same time

Limited mode and owner / group. In the third format, all specified directories and their home directories are created. The parameters that the long option must use are also necessary when using the short option.

3. Main parameters

-- backup [= CONTROL]: back up each existing destination file.

-b: similar to-- backup, but does not accept any parameters.

-c: (this option is not processed).

All parameters are treated as directories, and all home directories of the specified directory are created.

-D: all home directories before creation, and then will be copied to; useful in the first use format.

-GMAT talk group = group: set the group to which you belong, rather than the group to which the process currently belongs.

-mmam talk mode = mode: set your own permission mode (like chmod) instead of rwxr-xr-x.

Owner: set the owner by yourself (for superusers only).

-pmam talk about the visit / modification time of the file as the time attribute of the corresponding destination file.

-smam copyright strip: use the strip command to delete symbol table, which is only applicable to the first and second formats.

-Smam copyright suffix = suffix: the backup file is specified by yourself.

-vmam Meltel verbose: print the name when processing each file / directory.

-- help: display this help and leave.

-- version: displays the version information and leaves.

Mount

1. Action

The function of the mount command is to load the file system, and its permissions are superuser or allowed user in / etc/fstab.

two。 Format

Mount-a [- fv] [- t vfstype] [- n] [- rw] [- F] device dir

3. Main parameters

-h: displays auxiliary information.

-v: displays information, usually used with-f to debug.

-a: Mount all file systems defined in / etc/fstab.

-F: this command, usually used with-a, generates a stroke for each mount action to be executed. You can speed up loading when the system needs to mount a large number of NFS file systems.

-f: commonly used for debugging. It causes mount not to perform the actual mount action, but to simulate the entire mount process, usually used with-v.

-t vfstype: displays the type of file system being loaded.

-n: generally speaking, mount hangs up and writes a piece of data to / etc/mtab. If there is no writable file system in the system, you can use this option to cancel this action.

4. Application skills

In Linux

And Unix systems, all files are accessed as part of a large tree (with / as root). To access files on CD-ROM, you need to mount the CD-ROM device on a hanger in the file tree

Decorate. If the distribution installs the auto-mount package, this step can be done automatically. In Linux, if you want to use a storage device such as a hard disk or optical drive, you have to load it first, when the storage device is hung up.

You can access it as a directory. Hang up a device and use the mount command. When using the mount directive, you must first know the following three kinds of information: the file system type of the object to be loaded, the file system type to

The name of the device on which the object is loaded and the directory into which you want to load the device.

(1) File systems that can be recognized by Linux

The commonly used FAT 32 file system of ◆ Windows 95True 98: vfat

File system of ◆ Win NT/2000: ntfs

File system for ◆ OS/2: hpfs

File systems for ◆ Linux: ext2, ext3

File system for ◆ CD-ROM CD: iso9660.

Although vfat refers to a FAT 32 system, it is actually compatible with the file system type of FAT 16.

(2) determine the name of the equipment

In Linux

The device name is usually stored in / dev. The naming of these device names is regular, and the device name can be found out by "reasoning". For example, / dev/hda1 this

IDE device, hd is Hard Disk (hard drive), sd is SCSI Device,fd, Floppy Device (or Floppy)

Disk?). A stands for the first device, and usually the IDE interface can be connected to four IDE devices (such as four hard drives). So the ways to identify IDE hard drives are hda, hdb, hdc,

Hdd . The "1" in hda1 represents the first hard disk partition of hda

(partition), hda2 represents the second primary partition of hda, the first logical partition starts with hda5, and so on. In addition, you can check directly

/ var/log/messages file, where you can find the device code that has been recognized by the system after the computer is powered on.

(3) find the connection point

In decision

Before you mount the device, check to see if the computer has an empty directory of / mnt, which is specifically used as a mount point (Mount

Point). It is recommended to create several directories such as / mnt/cdrom, / mnt/floppy, / mnt/mo in / mnt, which can be used as dedicated mount points for directories. For example, such as

To mount the following five devices, the execution instructions may be as follows (assuming that they are all ext2 systems of Linux, change ext2 to vfat if it is Windows XX):

Floppy disk = > mount-t ext2 / dev/fd0 / mnt/floppy

Cdrom = = > mount-t iso9660 / dev/hdc / mnt/cdrom

SCSI cdrom = = > mount-t iso9660 / dev/sdb / mnt/scdrom

SCSI cdr = = > mount-t iso9660 / dev/sdc / mnt/scdr

However, most newer Linux distributions (including Red Flag Linux, medium soft Linux, Mandrake Linux, etc.) can mount the file system automatically, with the exception of Red Hat Linux.

Umount

1. Action

The purpose of the umount command is to unmount a file system with the permission of a superuser or a user allowed in / etc/fstab.

two。 Format

Unmount-a [- fFnrsvw] [- t vfstype] [- n] [- rw] [- F] device dir

3. instructions

Umount

The command is the inverse of the mount command, and its parameters and usage are the same as those of the mount command. After Linux mounts CD-ROM, CD-ROM is locked so that CD- cannot be used.

The Eject button on the ROM panel pops it up. However, when the CD is no longer needed, if / cdrom is already used as a symbolic link, use umount/cdrom to unmount it. Only if there are no users

The command succeeds only when the CD is in use. This command includes a terminal window with the current working directory as a directory on the CD.

Chsh

1. Action

The function of the chsh command is to change the user's shell settings, and its permission is for all users.

two。 Format

Chsh [- s] [- list] [--help] [- v] [username]

3. Main parameters

-l: displays all Shell types of the system.

-v: displays the Shell version number.

4. Application skills

It was introduced earlier that there are many kinds of Shell under Linux. The default is Bash. If you want to change the Shell type, you can use the chsh command. First enter the account password, and then enter the new Shell type, if the operation is correct, the system will display "Shell change". The interface is generally as follows:

Changing fihanging shell for cao

Password:

New shell [/ bin/bash]: / bin/tcsh

In the above code, [] is the currently used Shell. Ordinary users can only modify their own Shell, while superusers can modify the Shell of all users. To query which Shell the system provides, you can use the chsh-l command, as shown in figure 1.

Figure 1 types of Shell that can be used by the system

As you can see from figure 1, there are four kinds of Shell that can be used in the author's system: bash (default), csh, sh, and tcsh.

Exit

1. Action

The function of the exit command is to exit the system, and its permission is for all users.

two。 Format

Exit

3. Parameters.

The exit command has no parameters. After running, exit the system and enter the login interface.

Last

1. Action

The purpose of the last command is to display the recent login of a user or terminal, and its permission is for all users. By viewing the program's log through the last command, the administrator can know who has connected or attempted to connect to the system.

two。 Format

1ast [- n] [- f file] [- t tty] [- h node] [- I-IP] [- 1] [- y] [1D]

3. Main parameters

-n: specifies the number of output records.

-f file: specifies the file file as the log file for the query.

-t tty: only logins on the specified virtual console are displayed.

-h node: only the login on the specified node is displayed.

-I IP: displays only logins on the specified IP.

-1: use IP to display the remote address.

-y: displays the year, month and day of the record.

-ID: know the user name of the query.

-x: displays the history of system shutdown, user login, and logout.

Hands on practice

The above introduces the Linux installation and login commands, and here are a few examples to practice the commands just mentioned.

1. Run multiple commands at a time

Multiple commands can be executed on a command line, separated by semicolons, for example:

# last-x

The above code indicates that the computer is turned off after the history of system shutdown, user login, and logout is displayed.

two。 Using mount mount file system to access Windows system

Many Linux distributions now automatically load Vfat partitions to access the Windows system, while each version of Red Hat does not automatically load Vfat partitions, so manual manipulation is required.

Mount

You can connect the Windows partition to the / mnt directory by connecting the Windows partition to an empty folder in Linux as a "file" of Linux. Because of

Here, just accessing this folder is equivalent to accessing the partition. First, to create the winc folder under / mnt, enter the following command at the command prompt:

# mount-t vfat / dev/hda1 / mnt/winc

That is,

Means to hang the C partition of Windows to the / mnt/winc directory of Liunx. At this point, you can see the contents of disk C in Windows in the / mnt/winc directory. Make

The D and E disks of the Windows system can be accessed by a similar method. The general order in which the partition of Windows is displayed in the Linux system is as follows: hda1 is disk C, hda5 is disk D,

Hda6 is E disk. and so on. The above method shows that there is a big problem with the Windows system, that is, all Chinese file names or folder names in Windows are displayed as question marks.

"?" But English can be displayed normally. We can make it display in Chinese by adding some parameters. Also take the above operation as an example, enter the command at this time:

# mount-t vfat-o iocharset=cp936 / dev/hda1 / mnt/winc

Now it can display Chinese normally.

3. Use mount to mount the file system on the flash drive

Using flash drives under Linux is very easy. Linux has good support for USB devices. When the flash drive is inserted, the flash drive is recognized as an SCSI disk, usually entering the following command:

# mount / dev/sda1 / usb

You can add the file system on the flash drive.

A little knowledge

Linux command and Shell

So

Called Shell, is the command interpreter, it provides a programming interface, you can use programs to program. Learning Shell is very important for Linux beginners to understand the Linux system.

As the shell of the operating system, the Shell of the Linux system provides users with the interface to use the operating system. Shell is the general name of command language, command interpreter and programming language.

The interface program between Linux kernels. If you think of the Linux kernel as the center of a sphere, Shell is the outer layer around the kernel. When life is passed to Linux from Shell or other programs

The kernel will react accordingly. The role of Shell in Linux system and COMMAND.COM and Windows 95 under MS DOS

Explorer.exe is similar. Although Shell is not a part of the system core, it is only an extension of the system core, but it can call most of the functions of the system kernel. Therefore, it can be said that

Shell is the most important utility for Unux/Linux.

There are many types of Shell in Linux, of which Bourne is the most commonly used

Shell (sh), C Shell (csh) and Korn Shell (ksh). The default Shell for most Linux distributions is Bourne

Again Shell, which is an extension of Bourne Shell, or bash for short, is fully backward compatible with Bourne Shell and is available in Bourne

Many features have been added to Shell. Bash is placed in / bin/bash and can provide functions such as command completion, command editing, and command history tables. It also contains a lot of C.

Shell and Korn

The advantages of Shell are flexible and powerful programming interface as well as friendly user interface. Among the more than 200 commands in Linux system, 40 are internal commands of bash, mainly including

Exit, less, lp, kill, cd, pwd, fc, fg, etc.

60 commands that must be learned in Linux (2)-File processing commands

Linux

System information is stored in files, which are similar to ordinary official documents. Each file has its own name, content, storage address and other management information, such as the user of the file, the size of the file, and so on. The file can be

A letter, an address book, or the source statement of a program, the data of a program, and even executable programs and other non-text content.

Linux file system has a good structure, the system provides a lot of file processing programs. This paper mainly introduces the commonly used file processing commands.

File

1. The content of the function determines the file type, and the permission is for all users.

two。 Format

File through the probe text

File [options] file name

3. [options] main parameters

-v: displays version information after standard output and exits.

-z: detects compressed file types.

-L: allow matching connections.

-f name: reads the list of file names to analyze from the file namefile.

4. Simple explanation

Using the file command, you can know whether a file is a binary (ELF format) executable, an Shell Script file, or some other format. The file types that file can recognize are directories, Shell scripts, English text, binary executable files, C language source files, text files, and DOS executable files.

5. Application example

If we see a file grap without a suffix, we can use the following command:

$file grap

Grap: English text

At this point, the system shows that this is an English text file. It is important to note that the file command cannot detect multimedia file types, including graphics, audio, video, and so on.

Mkdir

1. Action

The purpose of the mkdir command is to create a subdirectory named dirname, which is similar to the md command under MS DOS and has permissions for all users.

two。 Format

Mkdir [options] directory name

3. [options] main parameters

-m,-- mode= mode: set permissions, similar to chmod.

-p,-- parents: create an upper-level directory if needed; if the directory already exists, it is not considered an error.

-v,-- verbose: information is displayed every time a new directory is created.

-- version: leave after the version information is displayed.

4. Application example

The permissions of the directory can be set when creating the directory, and the parameter used in this case is "- m". Assuming that the directory name you want to create is "tsk" so that all users have rwx (that is, read, write, and execute permissions), you can use the following command:

$mkdir-m 777 tsk

Grep

1. Action

The grep command can specify that specific content be searched in the file and standard output the lines containing that content. The full name of grep is Global Regular Expression Print, which represents the global regular expression version, and its permission is for all users.

two。 Format

Grep [options]

3. Main parameters

[options] main parameters:

-c: outputs only the count of matching rows.

-I: case-insensitive (for single characters only).

-h: the file name is not displayed when querying multiple files.

-l: when querying multiple files, only the file names that contain matching characters are output.

-n: displays matching lines and line numbers.

-s: does not display error messages that do not exist or have no matching text.

-v: displays all lines that do not contain matching text.

The main parameters of the pattern regular expression:

\: ignore the original meaning of special characters in regular expressions.

^: matches the start line of the regular expression.

$: matches the end line of the regular expression.

\: to the end of the line matching the regular expression.

[]: single character, such as [A], that is, A meets the requirements.

[-]: range, such as [Amurz], that is, A, B, C all the way up to Z meet the requirements.

. All single characters

*: there are characters, and the length can be 0.

Positive

Then expression is a very important concept in Linux/Unix system. A regular expression (also known as "regex" or "regexp") is a pattern that can describe a class of strings

(Pattern). If a string can be described by a regular expression, we say that the character matches the regular expression (Match). This and DOS users can use wildcards

"*" represents any character similar to it. On Linux systems, regular expressions are often used to find patterns for text, as well as to perform search-and-replace operations and other functions on text.

4. Application example

Check

Querying the DNS service is one of the daily tasks, which means maintaining a large number of IP addresses covering different networks. Sometimes there are more than 2000 IP addresses. If you want to check the nnn.nnn network address, but forget it

The rest of the second part only knows that there are two periods, such as nnn nn... To extract all the nnn.nnn IP addresses from it, use [0mur9]\ {3

\}\. [0Mutual 0\ {3\}\. The meaning is that any number appears three times, followed by a period, followed by a period.

$grep'[0Musi 9]\ {3\}\. [0mur0\ {3\}\ 'ipfile

In addition, the grep family also includes fgrep and egrep. Fgrep is a fix grep that allows you to find strings rather than a pattern; egrep is an extended grep that supports basic and extended regular expressions, but does not support the application of the\ Q pattern range and some of the more standardized patterns corresponding to it.

Dd

1. Action

The dd command is used to copy files and convert and format data based on parameters.

two。 Format

Dd [options]

3. [opitions] main parameters

Bs= bytes: force ibs= and obs=.

Cbs= bytes: specified for each conversion.

Conv= keyword: converts files based on how they are represented by comma-delimited keywords.

Number of count= blocks: only the specified input data is copied.

Ibs= bytes: read the specified bytes each time.

If= files: read content, not standard input data.

Obs= bytes: write the specified byte each time.

Of= file: writes data instead of displaying it in standard output.

Number of seek= blocks: skip the specified output data in obs first.

Number of skip= blocks: skip the specified input data in ibs first.

4. Application example

The dd command is often used to make a Linux boot disk. Find a bootable kernel so that its root device points to the correct root partition, and then use the dd command to write it to the floppy disk:

$rdev vmlinuz / dev/hda

$dd if=vmlinuz of=/dev/fd0

The above code shows that using the rdev command to point the root device in the bootable kernel vmlinuz to / dev/hda, please replace "hda" with your own root partition, and then use the dd command to write the kernel to the floppy disk.

Find

1. Action

The function of the find command is to search for files in the directory, and its permission is for all users.

two。 Format

Find [path] [options] [expression]

Path specifies the directory path, from which the system starts looking down the directory tree for files. It is a list of paths separated from each other by spaces. If you do not write path, it defaults to the current directory.

3. Main parameters

[options] parameters:

-depth: use the depth-level search process to find the contents of files first in a specified directory at a certain layer.

-maxdepth levels: indicates that at most the level subdirectory of the start directory can be found. Level is a non-negative number, and if level is 0, it means to look only in the current directory.

-mindepth levels: indicates that at least the level subdirectory of the start directory is found.

-mount: do not look in directories and files of other file systems (such as Msdos, Vfat, etc.).

-version: printed version.

[expression] is a matching expression, an expression accepted by the find command, and all operations of the find command are directed against the expression. It has a lot of parameters, and only some commonly used parameters are introduced here.

-name: wildcard characters * and? are supported.

-atime n: search for files that have been read in the past n days.

-ctime n: search for files that have been modified in the past n days.

-group grpoupname: search for all files whose group is grpoupname.

-user user name: search for all files that belong to a user name (ID or name).

-size n: search for files whose file size is n block.

-print: output the search results and print them.

4. Application skills

There are several ways for the find command to find files:

(1) search based on file name

For example, if we want to find a file with the file name lilo.conf, we can use the following command:

Find /-name lilo.conf

The "/" after the find command means to search the entire hard disk.

(2) quickly find files

Root

A practical problem with finding files by file name is that it takes quite a long time, especially when large Linux file systems and large hard disk files are placed in deep subdirectories. If we find out,

This file is stored in a directory, so just looking down in that directory can save a lot of time. For example, the smb.conf file, judging from its file suffix ".conf", is a match.

Set the file, then it should be in the / etc directory, at this point you can use the following command:

Find / etc-name smb.conf

In this way, you can shorten the time by using the Quick find File method.

(3) search method according to some file names

Sometimes we know that only one file contains the word abvd, so to find all the files in the system that contain these four characters, enter the following command:

Find /-name'* abvd*'

After entering this command, the Linux system will look in the / directory for all files containing the four characters of abvd (where * is a wildcard), such as abvdrmyz and other eligible files can be displayed.

(4) use hybrid search method to find files.

The find command can use a hybrid lookup method. For example, if we want to find a file in the / etc directory that is larger than 500000 bytes and is modified within 24 hours, we can use-and (and) to link the two lookup parameters together to form a hybrid lookup.

Find / etc-size + 500000c-and-mtime + 1

Mv

1. Action

The mv command is used to rename a file or directory, or to move a file from one directory to another, with permissions for all users. This command is like a combination of ren and move in the DOS command.

two。 Format

Mv [options] Source file or directory destination file or directory

3. [options] main parameters

-I: operate interactively. If the mv operation will result in an overwrite of an existing target file, the system asks whether to rewrite and asks the user to answer "y" or "n" to avoid mistakenly overwriting the file.

-f: interoperability is prohibited. The mv operation does not give any indication when it wants to overwrite an existing target file, and the I parameter will no longer work when this parameter is specified.

4. Application example

(1) move all files in / usr/cbu to the current directory (with "." Represents):

$mv / usr/cbu/ *.

(2) rename the file cjh.txt to wjz.txt:

$mv cjh.txt wjz.txt

Ls

1. Action

The ls command is used to display the contents of the directory, similar to the dir command under DOS, with permissions for all users.

two。 Format

Ls [options] [filename]

Main parameters of 3.options

-a,-- all: do not hide anything with "." The item at the beginning of the character.

-A,-- almost-all: list any items except "." and "..".

-- author: print out the author of each document.

-b,-- escape: represents unprintable characters in octal overflow sequences.

-- block-size= size: the block is in specified bytes.

-B,-- ignore-backups: does not list any items that end with the ~ character.

-f: no sorting,-aU parameter takes effect,-lst parameter is invalid.

-F,-- classify: add an indication of the file type (* / = @ | one of them).

-g:like-l, but do not list owner.

-G-- no-group:inhibit display of group information.

-I,-- inode: lists the inode number of each file.

-I,-- ignore= style: no items that match the Shell universal characters are printed.

-k: namely-- block-size=1K.

-l: lists information in a longer format.

-L,-- dereference: when the file information of a symbolic link is displayed, the object indicated by the symbolic link is displayed, not the information of the symbolic link itself.

-m: all items are separated by commas and fill the entire line width.

-n,-- numeric-uid-gid: similar to-l, but list UID and GID numbers.

-N,-- literal: lists unprocessed project names, such as no special handling of control characters.

-p,-- file-type: add an indication of the file type (/ = @ | one of them).

-Q,-- quote-name: enclose the project name in double quotes.

-r,-- reverse: in reverse order.

-R,-- recursive: lists all subdirectory layers at the same time.

-s,-- size: in order of block size.

4. Application example

Ls

Command is the most frequently used command in Linux system, and its parameters are also the most frequently used in Linux commands. There are several different colors when using the ls command, where blue indicates a directory and green indicates an executable

Line files, red indicates compressed files, light blue indicates linked files, bold black indicates symbolic links, and gray indicates files of other formats. The most common use of ls is ls- l, as shown in figure 1.

Figure 1 using the ls-l command

Article

The item type begins with a string of 10 characters. The first character represents the file type, which can be one of the following types:-(normal file), d (directory), l (symbolic link), b (block device text)

C (character device file). The next nine characters represent the access to the file, divided into three groups, each with 3 bits. The first group represents the permissions of the master, the second group represents the permissions of the users in the same group, and the third group represents the permissions of the users in the same group.

The permissions of his users. The three characters in each group represent read (r), write (w), and execute permissions (x) to the file, respectively. For directories, entry permissions. S means that when the file is executed, the UID of the file

Or the UID (user ID) or GID (group) assigned by GID to the execution process

ID). T means to set the flag bit (stay in memory and not be swapped out). If the file is a directory, the files in that directory can only be deleted by the superuser, the directory owner, or the file owner. If it is an executable text

The pointer to its body segment remains in memory after the file is executed. This way, when it is executed again, the system can load the file more quickly. This is followed by the file size, generation time, file or command name

Say.

Diff

1. Action

The diff command is used to compare two files and points out that the difference between the two is that it has permissions for all users.

two。 Format

Diff [options] Source file target file

3. [options] main parameters

-a: treat all files as text files.

-b: the difference caused by ignoring spaces.

-B: the difference caused by ignoring blank lines.

-c: use the outline output format.

-H: use heuristics to speed up the search for large files.

-I: ignore case changes.

-n-- rcs: output RCS format.

Cmp

1. Action

The cmp (abbreviation for "compare") command is used to briefly indicate whether there is a difference between the two files, and its permission is for all users.

two。 Format

Cmp [options] file name

3. [options] main parameters

-l: output bytes in decimal mode, and facilitate the output of different files in octal mode.

Cat

1. Action

The cat (abbreviation for "concatenate") command is used to connect and display information about one or more specified files, and its permissions are for all users.

two。 Format

Cat [options] File 1 File 2...

3. [options] main parameters

-n: number the number of lines of all output starting from the first line.

-b: similar to-n, except that blank lines are not numbered.

-s: when you encounter blank lines with more than two consecutive lines, replace them with blank lines on one line.

4. Application example

(1) one of the simplest uses of the cat command is to display the contents of a text file. For example, if we want to see the contents of the README file on the command line, we can use the command:

$cat README

(2)

Sometimes you need to process several files into a single file and save the results of this processing to a separate output file. The cat command accepts one or more files on its input and treats them as a separate file

Print to its output. For example, after numbering the contents of README and INSTALL files (no blank lines), append the contents to a new text file, File1:

$cat README INSTALL File1

(3) another important function of cat is the ability to number rows, as shown in figure 2. This function is convenient for the preparation of program documentation, as well as legal and scientific documentation, and the line number printed on the left makes it easy to reference a part of the document. these are very important in programming, scientific research, business reports and even legislative work.

Figure 2 numbering using the cat command / etc/named.conf file

The line numbering function has two parameters:-b (only non-blank lines can be numbered) and-n (all lines can be numbered):

$cat-b / etc/named.conf

Ln

1. Action

The ln command is used to create links between files, and its permissions are for all users.

two。 Format

Ln [options] Source file [link name]

3. Parameters.

-f: delete the source file when linking.

-d: allows system administrators to hard-link their own directories.

-s: soft link (Symbolic Link).

-b: back up files that will be overwritten or deleted when linked.

There are two kinds of links, one is called Hard Link, the other is called symbolic link (Symbolic Link). By default, the ln command produces hard links.

Hard

A connection is a connection made through an index node. In Linux's file system, files saved in disk partitions, regardless of type, are assigned a number called index node number (Inode)

Index). In Linux, it is possible to have multiple file names pointing to the same Inode. Generally speaking, this kind of connection is a hard connection. The purpose of a hard connection is to allow a file to have multiple valid pathnames, so that the user

You can establish a hard connection to important files to prevent "accidental deletion" function. The reason is as mentioned above, because there is more than one connection to the index node of the directory. Deleting only one connection does not affect the Inode itself and the

For other connections, only when the last connection is deleted will the connection between the data block of the file and the directory be released. In other words, the file will really be deleted.

Corresponding to the hard connection, there is another kind of connection in the Lnux system, which is called symbolic connection (Symbilc Link), also called soft connection. Soft-link files are a bit like Windows shortcuts. It is actually a kind of special file. In symbolic links, a file is actually a text file that contains information about the location of another file.

Hands on practice

Above we introduced the Linux file processing commands, here are a few examples, you can start to practice the commands just mentioned.

1. Use symbolic links to quickly access key directories

Symbol

The number link is a very practical function. Suppose there are some directories or files that need to be used frequently, but because of the file and directory structure of Linux, this file or directory is in a very deep subdirectory. such as,

Apache

The Web server documentation is in the / usr/local/httpd/htdocs of the system, and you don't want to enter such a long path from the home directory every time (in fact, this path is also

It's not easy to remember.

To solve this problem, you can create a symbolic link in the home directory so that when you need to enter that directory, you only need to go to that link.

To easily access the directory where the Web server (/ usr/local/httpd/htdocs) documents are located, you can use the following command in the home directory:

$ln-s / usr/local/httpd/htdocs gg

In this way, every time you enter the gg directory, you can access the documents of the Web server. In the future, if you no longer access the documents of the Web server, you can delete the gg, but the documents of the real Web server are not deleted.

two。 Use the dd command to import root.ram content in init.rd format into memory

Dd if=/dev/fd0 of=floppy.fd

Dd if=root.ram of=/dev/ram0 #

3.grep command system call

Grep is one of the most widely used commands in Linux/Unix and can be called internally by many Linux systems.

(1) if you want to query the directories in the directory list, the method is as follows:

$ls-l | grep '∧ d'

(2) if you query all files that do not contain a directory in a directory, the method is as follows:

$ls-l | grep '∧ [∧ d]'

(3) call grep with the find command, such as "Chinput" in all C source code, as follows:

$find / ZhXwin-name * .c-exec grep-Q-s Chinput {}\;-print

60 commands that Linux must learn (3)-system Management Command

Linux must learn system management commands

For the Linux system, no matter the CPU, memory, disk drive, keyboard, mouse, or users are all files, the command managed by the Linux system is the core of its normal operation. Once you are familiar with the commonly used file processing commands in Linux, this lecture introduces commands for managing the system and users.

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.

Super

When using the df command, level-level users 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. That is,

Said that for the superuser, the hard disk capacity he saw would be 110%. This arrangement is good for system management, and the system administrator can be normal when the capacity of the hard disk is close to 100%.

Work.

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] [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

In figure 1, the items shown 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 processes, currently running, pending

(Sleeping) and useless (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 usage of the swap zone, including the total swap partition, usage

, 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.

Linux

The operating system consists of 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 famous

Monitoring process of the Apache server.

The kill command works by sending a system operation signal to the kernel of the Linux system

And the process identification number of a program, and then the system 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 the

Stop 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 an error in one program causes a deadlock in the system, you can switch to another virtual console to work off.

This 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

In Linux

Sometimes it happens 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

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

Mozilla browser programs are locked, and you can use the kill command to abort all programs that contain Mozolla browsers. First use the top command to find out the PID of the program, but

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.

Crontab

The file format is "M H D m d"

Cmd ". Where M stands for minutes (059), H for hours (023), D for days (31s), m for months (112s), and d for days of the week (06pm 0 is the week).

God). 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-- $Id: crontab.c,v 2.13 1994-01-17 03:20:37 vixie Exp $)

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! The display result is shown in figure 3.

Figure 3 A timed, periodic system prompt

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

This

Actually entered the Shell of the Linux system, and wrote 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 01

"17:35" means that the system accepts the sixth at command and executes the command at "2004mur01 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, listening for requirements to connect with Internet service processes (such as rlogin, telnet, ftp, rsh), and extending the required service processes. By default

The daemon that inetd monitors are listed in / 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

SIGHUP (signal 1) sends a signal to the current inetd process, 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.

The system management commands introduced in this lecture are more important, especially the crontab command and quota command will be difficult to use, need to do some more practice. In addition, when using the kill command, you should pay attention to the parameter "- 9". It is best not to run some important programs during the exercise.

60 commands that must be learned in Linux (4)-60 commands that must be learned in Linux: network operation commands

Because of

Linux system is originated and developed on Internet. It is born with powerful network functions and rich network application software, especially the implementation of TCP/IP network protocol is particularly mature.

There are many network commands in Linux, some of which are like ping,

Ftp, telnet, route, netstat and so on can also be seen on other operating systems, but there are also some commands unique to Unix/Linux systems, such as ifconfig,

Finger, mail, etc. One of the characteristics of Linux network operation command is that there are many command parameters and functions, and one command can also realize the functions of other commands.

Ifconfig

1. Action

two。 Format

Ifconfig-interface [options] address

3. Main parameters

-interface: the specified network interface name, such as eth0 and eth2.

Up: activate the specified network interface card.

Down: shuts down the specified network interface.

Broadcast address: sets the broadcast address of the interface.

Pointopoint: enables the point-to-point approach.

Address: sets the IP address of the specified interface device.

Netmask address: sets the subnet mask for the interface.

4. Application description

Ifconfig is a command-line tool used to set up and configure network cards. In order to configure the network manually, this is a command that must be mastered. The advantage of using this command is that there is no need to restart the machine. To assign the eth0 interface IP address 207.164.186.2 and activate it immediately, use the following command:

# fconfig eth0 210.34.6.89 netmask 255.255.255.128 broadcast 210.34.6.127

The

If you run the ifconfig command without any parameters, this command will display all the active interfaces of the machine

information. The command with the "- a" parameter displays information about all interfaces, including those that are not active. Note that the network device parameters configured with the ifconfig command will be lost after the machine is restarted.

If you want to suspend the work of a network interface, you can use the down parameter:

# ifconfig eth0 down

Ip

1. Action

Ip is a powerful network configuration tool in iproute2 software package. It can replace some traditional network management tools, such as ifconfig, route and so on. This command is supported by almost all Linux distributions.

two。 Format

Ip [OPTIONS] OBJECT [COMMAND [ARGUMENTS]]

3. Main parameters

OPTIONS is the option to modify the ip behavior or change its output. All options start with the-character and are divided into long and short forms. Currently, ip supports the options shown in Table 1.

OBJECT is the object for managers to get information. The objects that ip knows so far are shown in Table 2.

Table 1 options supported by ip

-VMagneWhile version prints the version of ip and exits.

-smam quotes quotes statistics outputs more detailed information. If this option appears two or more times, the output information will be more detailed.

This option is followed by the type of protocol, including inet, inet6 or link, which emphasizes the type of protocol used. If there is not enough information to tell ip what kind of protocol to use, ip uses the default value of inet or any. Link is special in that it does not involve any network protocols.

-4 is the abbreviation of-family inet.

-6 is the abbreviation of-family inet6.

-0 is the abbreviation of-family link.

Each row of records is output on a single line, and the return line is replaced by characters. This option is used if you need to use tools such as wc, grep, and so on to process the output of ip.

Query the domain name resolution system and replace the host IP address with the obtained hostname

COMMAND

Sets the action to be performed on the specified object, depending on the type of object. In general, ip supports the addition (add), deletion (delete), and presentation (show or list) of objects. Some

Object does not support these operations, or there are other commands. For all objects, you can use the help command to get help. This command lists the syntax of the commands and parameters supported by the object. If not,

If there is an operation command for a specified object, ip uses the default command. In general, the default command is list, and if the object cannot be listed, the help command is executed.

ARGUMENTS

Are parameters of a command that depend on objects and commands. Ip supports two types of parameters: flag and parameter. Flag consists of a keyword; parameter consists of a

The keyword is composed of a numerical value. For convenience, each command has a default parameter that can be ignored. For example, the parameter dev is the default parameter for the ip link command, so ip link ls

Eth0 equals ip link ls dev eth0. We will describe the use of each command in more detail later, and the default parameters of the command will be marked with default.

4. Application example

Add the IP address 192.168.2.2 to the eth0 network card:

# ip addr add 192.168.1.1/24 dev eth0

Discard all datagrams whose source address belongs to the 192.168.2.0Universe 24 network:

# ip rule add from 192.168.2.0/24 prio 32777 reject

Ping

1. Action

Ping detects the network interface status of the host, and the permission is for all users.

two。 Format

Ping [- dfnqrRv] [- c] [- I] [- I] [- l] [- p] [- s] [- t] IP address

3. Main parameters

-d: use the SO_DEBUG feature of Socket.

-c: sets the number of times the request response is completed.

-f: limit testing.

-I: specifies the number of seconds between sending and receiving messages.

-I: the network interface sends out packets using the specified network interface.

-l: preload, setting the packet that is sent before the request information is sent.

-n: outputs only numeric values.

-p: sets the template style that fills the packet.

-Q: the instruction execution process is not displayed, except for the relevant information at the beginning and end.

-r: ignore the normal Routing Table and send the packet directly to the remote host.

-R: record the routing process.

-s: sets the size of the packet.

-t: sets the size of the survival value TTL.

-v: shows the execution of the instruction in detail.

Ping

The command is the most frequently used network instruction, which is usually used to detect whether the network is connected, and it uses the ICMP protocol. But sometimes there is a situation where we can view a web page in a browser, but we can't

Ping access, this is because some websites have installed firewalls for security reasons. Alternatively, you can try it on your own computer to make the system unresponsive to ping in the following ways:

# echo 1 > / proc/sys/net/ipv4/icmp_echo_ignore_all

Netstat

1. Action

Check the status of the entire Linux network.

two。 Format

Netstat [- acCeFghilMnNoprstuvVwx] [- A] [--ip]

3. Main parameters

-a--all: displays the Socket in all connections.

-A: list the IP-related addresses and network types in the network type connection.

-c--continuous: continuously lists the network status.

-C--cache: displays the cache information configured by the router.

-e--extend: displays other information related to the network.

-F--fib: displays the FIB.

-g--groups: displays the list of group members of the Multicast function.

-h--help: online help.

-i--interfaces: displays the web interface information form.

-l--listening: displays the Socket of the server under monitoring.

-M--masquerade: displays the camouflaged network connection.

-n--numeric: use the IP address directly, not through the domain name server.

-N--netlink--symbolic: displays the symbolic connection name of the network hardware peripheral.

-o--timers: displays the timer.

-p--programs: displays the program identification number and program name that are using Socket.

-r--route: displays the Routing Table.

-s--statistice: displays the statistical table of network work information.

-t--tcp: displays the connection status of the TCP transport protocol.

-u--udp: displays the connection status of the UDP transport protocol.

-v--verbose: displays the instruction execution process.

-V--version: displays version information.

-w--raw: displays the connection status of the RAW transport protocol.

-x--unix: same as specifying "- A unix" parameter.

-- ip--inet: same as specifying "- An inet" parameter.

4. Application example

Netstat

In addition, it also displays the system routing table, network interface status, and so on. It can be said that it is a

A comprehensive tool for viewing the status of the network. By default, netstat displays only the ports that are connected. If you want to display all ports in the listening state, use the-a parameter:

# netstat-a

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State

Tcp 0 0 *: 32768 *: * LISTEN

Tcp 0 0 *: 32769 *: * LISTEN

Tcp 0 0 *: nfs *: * LISTEN

Tcp 0 0 *: 32770 *: * LISTEN

Tcp 0 0 *: 868 *: * LISTEN

Tcp 0 0 *: 617 *: * LISTEN

Tcp 0 0 *: mysql *: * LISTEN

Tcp 0 0 *: netbios-ssn *: * LISTEN

Tcp 0 0 *: sunrpc *: * LISTEN

Tcp 00 *: 10000 *: * LISTEN

Tcp 0 0 *: http *: * LISTEN

.

As shown above, this host also provides HTTP, FTP, NFS, MySQL and other services.

Telnet

1. Action

Telnet means to start the terminal phase operation and log in to the remote host. Telnet is not only a Linux command, but also a protocol (remote login protocol).

two。 Format

Telnet [- 8acdEfFKLrx] [- b] [- e] [- k] [- l] [- n] [- S] [- X] [host name IP address]

3. Main parameters

-8: allows the use of 8-bit character data, including input and output.

-a: try to log in to the remote system automatically.

-b: specify the remote host name using an alias.

-c: do not read .telnetrc files in the user-specific directory.

-d: start debug mode.

-e: sets the detach character.

-E: filter out detached characters.

-f: this parameter has the same effect as specifying the "- F" parameter.

-F: when using Kerberos V5 authentication, add this parameter to upload the authentication data of the local host to the remote host.

-k: when using Kerberos authentication, add this parameter to make the remote host use the specified domain name instead of the host's domain name.

-K: do not automatically log in to the remote host.

-l: specifies the user name to log in to the remote host.

-L: allows you to output 8-bit character data.

-n: specifies the file record related information.

-r: use a user interface similar to rlogin instructions.

-S: service type, which sets the IP TOS information required for telnet connection.

-x: assume that the host has a feature that supports data encryption, use it.

-X: closes the specified authentication form.

4. Application description

Use

Users can log in remotely and communicate between remote computers using the telnet command. A user logs in on a remote computer over the network as if he were logged in to the local computer to execute a command. In order to pass

When telnet logs in to a remote computer, you must know the legal user name and password on the remote computer. Although some systems do provide login capabilities for remote users, the operation of guests should be restricted for security reasons.

Permissions, therefore, there are very few features that can be used in this case.

Telnet only provides terminal emulation for ordinary terminals, but does not support X-

Graphic environment such as Window. When allowing remote users to log in, the system usually places these users in a restricted Shell to prevent the system from being compromised by malicious or careless users. Users can also

Use telnet to log in to your computer from a remote site, check email, edit files, and run programs as if you were logging in locally.

Ftp

1. Action

The ftp command makes a remote file transfer. FTP is the standard file transfer protocol of ARPANet, and this network is the predecessor of Internet today, so ftp is both a protocol and a command.

two。 Format

Ftp [- dignv] [host name IP address]

3. Main parameters

-d: shows the execution process of the instruction in detail, which is convenient for debugging and analyzing the execution of the program.

-I: turn off the interactive mode without asking any questions.

-g: turn off the extension of the local host file name to support special characters.

-n: do not use automatic login.

-v: displays the execution process of the instruction.

4. Application description

Ftp

Command is the user interface of the standard file transfer protocol. It is a simple and effective way to transfer files between TCP/IP network computers. It allows users to transfer ASC Ⅱ files and binary files. In order to use ftp

To transfer files, the user must know the legal user name and password on the remote computer. This username / password combination is used to confirm the ftp session and to determine how the user accesses the file to be transferred.

In addition, the user needs to know the IP address of the name of the computer to which the ftp session takes place.

Users can connect to another computer by using the ftp client program; they can move up and down the directory and list the contents of the directory; they can copy files from the remote computer to the local computer; and they can transfer the files from the local computer to the remote system. There are 72 internal commands in ftp, and the main internal commands are listed below:

Ls: lists the current directory of remote machines.

Cd: change the working directory on the remote machine.

Lcd: change the working directory on the local machine.

Close: terminates the current ftp session.

Hash: a # sign is displayed each time the data in the data buffer is transferred.

Get (mget): transfers the specified file from the remote machine to the local machine.

Put (mput): transfers the specified file from the local machine to the remote machine.

Quit: disconnect from the remote machine and exit ftp.

Route

1. Action

Route means to manually generate, modify, and view routing tables.

two。 Format

# route [- add] [- net |-host] targetaddress [- netmask Nm] [dev] If]

# route [- delete] [- net |-host] targetaddress [gw Gw] [- netmask Nm] [dev] If]

3. Main parameters

-add: add routes.

-delete: delete the route.

-net: the route reaches a network, not a host.

-host: the route reaches a host.

-netmask Nm: specifies the subnet mask of the route.

Gw: specifies the gateway of the route.

[dev] If: forces the routing chain to specify an interface.

4. Application example

The route command is used to view and set the routing information of the Linux system in order to communicate with other networks. To achieve communication between two different subnets, you need a router connecting two networks, or a gateway located in both networks.

In Linux systems, routing is usually set up to solve the following problems: the Linux system has a gateway in a local area network, which allows the machine to access the Internet, so it is necessary to set the IP address of this machine to the default route of the Linux machine. Use the following command to add a default route:

Route add 0.0.0.0 192.168.1.1

Rlogin

1. Action

Rlogin is used for remote registration.

two。 Format

Rlogin [- 8EKLdx] [- e char] [- k realm] [- l username] host

3. Main parameters

-8: this option always allows 8-bit input data channels. This option allows formatted ANSI characters and other special codes to be sent. If this option is not used, the parity bit is removed unless the termination and startup characters are not at the remote end.

-E: stop treating any character as an escaped character. When used with the-8 option, it provides a fully transparent connection.

-K: turn off all Kerberos confirmations. Use this option only when connecting to a host that uses the Kerberos acknowledgement protocol.

-L: allows rlogin sessions to run in litout mode. For more information, refer to the tty online help.

-d: open socket debugging for TCP sockets that communicates with the remote host. For more information, refer to the online help for setsockopt.

-e: sets the escape character for the rlogin session. The default escape character is "~".

-k: request rlogin to obtain the Kerberos license of the remote host within the specified area, rather than the Kerberos license of the remote host within the remote host area determined by krb_realmofhost (3).

-x: turns on DES encryption for all data transmitted through the rlogin session. This affects response time and CPU utilization, but improves security.

4. instructions

If you have accounts on different systems in the network, or you can access other people's accounts on another system, you must first register in the system to access accounts in other systems. then register remotely to the system where the account is located through the network. Rlogin can be registered remotely to another system, and its parameter should be a system name.

Rcp

1. Action

Rcp stands for remote file copy and is used to copy files between computers, with permissions for all users.

two。 Format

Rcp [- px] [- k realm] file1 file2 rcp [- px] [- r] [- k realm] file

3. Main parameters

-r: recursively copy everything in the source directory to the destination directory. To use this option, the destination must be a directory.

-p: attempts to preserve the modification time and mode of the source file, ignoring umask.

-k: request rcp to obtain the Kerberos license of the remote host within the specified area, rather than the Kerberos license of the remote host within the remote host area determined by krb_relmofhost (3).

-x: turn on DES encryption for all data transferred.

Finger

1. Action

Finger is used to query the login account information on a host. It usually displays the user name, home directory, stagnation time, login time, login Shell and other information. The permission is for all users.

two。 Format

Finger [option] [user] [user @ host]

3. Main parameters

-s: displays user registration name, actual name, terminal name, write status, stagnation time, login time and other information.

-l: in addition to the information displayed with the-s option, it also displays information such as the user's home directory, login Shell, mail status, and the contents of .plan, .project, and .forward files under the user's home directory.

-p: same as the-l option except that .plan and .project files are not displayed.

4. Application example

Use finger on your computer:

[root@localhost root] # Finger

Login Name Tty Idle Login Time Office Office Phone

Root root tty1 2 Dec 15 11

Root root pts/0 1 Dec 15 11

Root root * pts/1 Dec 15 11

5. Application description

If you want to query the user information on the remote machine, you need to follow the user name with "@ hostname" in the format of [username @ hostname], but the network host to be queried needs the support of running the finger daemon.

Mail

1. Action

The function of mail is to send email, and the permission is for all users. In addition, mail is an email program.

two。 Format

Mail [- s subject] [- c address] [- b address]

Mail-f [mailbox] mail [- u user]

3. Main parameters

-b address: represents the anonymous recipient address list of the output information.

-c address: represents the list of CC () recipient addresses of the output information.

-f [mailbox]: reads messages from the mailbox specified by the inbox.

-s subject: specifies the body line of the output information.

[- u user]: the port specifies the optimized inbox to read mail.

Nslookup

1. Action

The function of the nslookup command is to query the IP address of a machine and its corresponding domain name. Use permissions for all users. It usually requires a domain name server to provide domain name services. If the user has set up a domain name server, you can use this command to view the domain name corresponding to the IP address of different hosts.

two。 Format

Nslookup [IP address / domain name]

3. Application example

(1) use the nslookup command on the local computer

$nslookup

Default Server: name.cao.com.cn

Address: 192.168.1.9

>

Enter the domain name of the IP address you want to query after the symbol ">" and enter. If you want to exit the command, type "exit" and press enter.

(2) use the nslookup command to test named

Enter the following command:

Nslookup

Then enter the switched nslookup environment. If named starts normally, nslookup displays the address and domain name of the current DNS server, otherwise named does not start properly.

Here are some basic DNS diagnostics.

Check forward DNS resolution and enter the hostname with the domain name at the nslookup prompt. For example, hp712.my.com,nslookup should be able to display the IP address corresponding to the hostname. Such as

If you enter hp712,nslookup only, the my.com domain name will be automatically added and the corresponding IP address will be answered according to the definition of / etc/resolv.conf.

◆ checks reverse DNS resolution and enters an IP address at the nslookup prompt, such as 192.22.33.20 IP address should be able to answer the hostname.

◆ check MX email address record enter at the nslookup prompt:

Set q=mx

Then enter a domain name, and enter my.com and mail.my.com,nslookup should be able to answer the corresponding mail server address, namely support.my.com and support2.my.com.

Hands on practice

1. Dangerous network commands

Mutual

With the development of networking, security has become an issue that cannot be ignored. Finger, ftp, rcp and telnet are all inherently insecure because they transmit passwords and data in clear text on the network.

The probe can intercept these passwords and data very easily. Moreover, the security verification methods of these service programs also have weaknesses and are vulnerable to "intermediate server" attacks. Here the author puts some unsafe lives

The orders are listed according to the risk level, as shown in Table 3.

Now ftp and telnet can be bound to port 22 instead of the SSH command.

Then the negotiation method is adopted and RSA encryption is used. After authentication is completed, all subsequent traffic uses IDEA

Encrypt it. The SSH (Secure Shell) program can log in to a remote host over the network and execute commands. Rcp, rlogin and other remote calling commands are also gradually replaced by VNC software.

In place of.

two。 Bind multiple IP addresses to a network card

Under Linux, you can easily bind multiple IP addresses to a network card using ifconfig. For example, the original IP address of the eth0 interface is 192.168.0. 254, you can execute the following command:

Ifconfig eth0:0 192.168.0.253 netmask 255.255.255.0

Ifconfig eth0:1 192.168.0.252 netmask 255.255.255.0

.

3. Modify the MAC address of the network card

First of all, you must turn off the network card device, as follows:

/ sbin/ifconfig eth0 down

Modify the MAC address with the following command:

/ sbin/ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE

Re-enable the network card:

/ sbin/ifconfig eht0 up

In this way, the MAC address of the network card is changed. The MAC address of each network card is unique, but it cannot be modified, as long as the uniqueness of the MAC address in the network is guaranteed.

4. Initial deployment of IPv6

IPv4

Technology has played a huge role in the development of the network, but with the passage of time, it is becoming more and more inadequate in terms of network address provision, service quality, security and so on. IPv6 is about to appear. Linux

IPv6 is the first of all operating systems to support IPv6. Generally, Linux distributions of Linux based on 2.4 kernels can directly use IPv6, but the main distributions do not have the IPv6 module loaded.

Block, which can be loaded manually using the command, requires the permissions of the superuser.

(1) load IPv6 module

Use the command to detect, where inet6 addr: fe80::5054:abff:fe34:5b09/64 is the IPv6 address of the eth0 Nic.

# modprobe IPv6

# ifconfig

Eth0 Link encap:Ethernet HWaddr 52:54:AB:34:5B:09

Inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0

Inet6 addr: fe80::5054:abff:fe34:5b09/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:0 errors:0 dropped:0 overruns:0 frame:0

TX packets:21 errors:0 dropped:0 overruns:0 carrier:0

Collisions:0 txqueuelen:100

RX bytes:0 (0.0b) TX bytes:1360 (1.3Kb)

Interrupt:5 Base address:0xec00

(2) use the ping command to check whether the IPv6 address of the network card is valid.

# ping6-I eth0-c 2 fe80::200:e8ff:fea0:2586

Unlike IPv4, you must specify a network card interface when using the ping6 command, otherwise the system does not know which network device to send the packet to. I indicates Interface, eth0 is the first network card,-c indicates loop, and 2 indicates ping6 operation twice. The result is shown in figure 1.

Figure 1 ping6 commands under the IPv6 network

(3) use the ip command to add an IP address to eth0 under IPv6

# ip-6 addr add 3ffe:ffff:0:f101::1/64 dev eth0

Use the ifconfig command to see if the second IPv6 address appears on the network card.

The main advantage of Linux network is that it can share resources and information, and users can access information remotely. Linux provides a set of powerful network commands to serve users. These tools can help users set up the network, check the network condition, log in to the remote computer, transfer files and execute remote commands.

The above introduces the more important network commands in Linux, but in fact, Linux still has many commands to learn. One of the characteristics of Linux network operation command is that there are many command parameters, which do not need to be remembered. The key is to understand the main purpose of the command and learn to use help information.

60 commands that Linux must learn (5)-Network Security commands 60 commands that Linux must learn: commands related to system security

Although Linux, like Windows NT/2000, is a multi-user system, there are many important differences between them. For many administrators who are accustomed to Windows system, how to ensure the security and reliability of Linux operating system will face many new challenges. This article will focus on commands for Linux system security.

Passwd

1. Action

The passwd command originally changed the login password of the account, and the permission is for all users.

two。 Format

Passwd [option] account name

3. Main parameters

-l: lock the named account name, which can only be used by users with super user privileges.

-u: unlock the account lock status and only users with super user privileges can use it.

-x,-- maximum=DAYS: the maximum password usage time (days), which can only be used by users with superuser privileges.

-n,-- minimum=DAYS: the minimum password usage time (days), which can only be used by users with superuser privileges.

-d: delete the user's password and only users with superuser privileges can use it.

-S: check the password authentication type of the specified user. Only users with superuser privileges can use it.

4. Application example

$passwd

Changing password for user cao.

Changing password for cao

(current) UNIX password:

New UNIX password:

Retype new UNIX password:

Passwd: all authentication tokens updated successfully.

As you can see from above, to use the passwd command, you need to enter the old password, and then enter the new password twice.

Su

1. Action

The role of su is to change to the identity of another user, except for a superuser, whose password needs to be typed.

two。 Format

Su [options]... [-] [USER [ARG]...]

3. Main parameters

-f,-- fast: no need to read startup files (such as csh.cshrc, etc.), only for csh or tcsh Shell.

-l,-- login: after adding this parameter, it is like logging back in to the user, most of the environment variables (such as HOME, SHELL, USER, etc.) are based on the user (USER), and the working directory will also change. If USER is not specified, the default is root.

-m,-p,-- preserve-environment: the environment variable is not changed when su is executed.

-c command: the user whose account number is changed to USER, and then change back to the original user after executing the command.

USER: for the user account to be changed, pass the new Shell parameter to ARG.

4. Application example

Change the account to superuser and restore the user after executing the df command. Su-c df root

Umask

1. Action

Umask sets the default mask values for user files and directories. If you put this command into the profile file, you can control the access permission of the subsequent files created by the user. It tells the system who is not allowed to access the file when it is created. Permissions are for all users.

two。 Format

Umask [- p] [- S] [mode]

3. Parameters.

-S: determine the current umask settings.

-p: modify umask settings.

[mode]: modify the value.

4. Description

Pass

The umask value of the unified Unix is 022, which prevents other users who also belong to the group and users of other groups from modifying the user's files. Since each user owns and belongs to its own private group, then

This "group protection mode" is no longer needed. Strict permission setting forms the basis of Linux security, and it is fatal to make mistakes in permissions. It is important to note that the umask command is used to set the process creation

The safest value for the read and write permissions of the built file is 0077, that is, turn off the read and write permissions of all processes except the process that created the file, expressed as-rw-. In

In ~ / .bash_profile, add a command umask 0077 to ensure that every time you start Shell, the umask permissions of the process can be set correctly.

5. Application example

Umask-S

Uprirwx, gendrx, gendrx, overnrx.

Umask-p 177

Umask-S

Upright rw, gendry, and so on

The above five lines of command first display the current status, and then change the umask value to 177. as a result, only the file owner has the permission to read and write the file, and other users cannot access the file. This is obviously a very safe setting.

Chgrp

1. Action

Chgrp means to modify the group to which one or more files or directories belong. The permission is superuser.

two。 Format

Chgrp [options]... Group file.

Or

Chgrp [options]... -- reference= reference file file.

Set the group to which each belongs.

3. Parameters.

-c,-- changes: like-- verbose, but the result is displayed only when there are changes.

-- dereference: affects the object indicated by the symbolic link, not the symbolic link itself.

-h,-- no-dereference: affects the symbolic link itself, not the destination indicated by the symbolic link (this option is only valid when the system supports changing the owner of the symbolic link).

-f,-- silent,-- quiet: remove most of the error messages.

-- reference= reference file: the group to which it belongs, not the specified one.

-R,-- recursive: recursively processes all files and subdirectories.

-v,-- verbose: processing any file will display information.

4. Application description

This command changes the user group to which the specified file belongs. Where group can be the user group ID or the group name of the user group in the / etc/group file. The file name is a list of files to be changed to the group separated by spaces, and wildcards are supported. If the user is not the owner or superuser of the file, you cannot change the group of the file.

5. Application example

Change the subordinate group of all files in / opt/local / book/ and its subdirectories to book, as follows:

$chgrp-R book / opt/local / book

Chmod

1. Action

The chmod command is very important to change the access to a file or directory, which users can use to control access to a file or directory, which is a superuser.

two。 Format

The chmod command is used in two ways. One is a character setting method that contains letters and operator expressions (relative permission setting), and the other is a numeric setting method containing numbers (absolute permission setting).

(1) character setting method

Chmod [who] [+ |-| =] [mode] file name

The ◆ Operand who can be any of the following letters or a combination of them

U: represents the user, that is, the owner of the file or directory.

G: represents the same group of users, that is, all users with the same group ID as the file owner.

O: represents other users.

A: represents all users, which is the system default.

◆ operation symbol

+: add a permission.

Revoke a permission.

=: give the given permission and cancel all other permissions, if any.

◆ can set the permissions of mode with any combination of the following letters

R: readable.

W: writable.

X: executable.

X: append the x attribute only if the target file is executable to some users or if the target file is a directory.

S: set the process owner or group ID as the file owner of the file when the file is executed. The user ID bit of the file is set by mode "Utility", and the group ID bit is set by "Groups".

T: save the text of the program to the switching device.

U: have the same permissions as the file owner.

G: have the same permissions as users who belong to the same group as the file.

O: have the same permissions as other users.

File name: a list of files to change permissions separated by spaces. Wildcards are supported.

Multiple permissions can be given on a command line, separated by commas.

(2) Digital setting method

The general form of digital setting method is: chmod [mode] file name

Numeric attributes should be in the format of 3 octets from 0 to 7, in the order of (u) (g) (o) file names, a list of files to change permissions separated by spaces, and wildcards are supported.

Number

The meaning of the permission expressed by the word is as follows: 0001 for the owner's execution permission, 0002 for the owner's write permission, 0004 for the owner's read permission, 0010 for the group's execution permission, and 0020 for the group's write permission.

Permissions; 0040 is the read permission of the group; 0100 is the execution permission of others; 0200 is the write permission of others; 0400 is the read permission of others; 1000 is the paste location bit; 2000 is false.

If the file is an executable file, the group ID is the location bit, otherwise the file locks the location bit; 4000 means that if the file is an executable file, the user ID is the location bit.

3. Example

If a system administrator writes a form (tem) for all users to fill in, then the user must be authorized to read and write to the file. You can use the command: # chmod 666tem

Go up

How is the 666 number calculated in the face code? 0002 is the owner's write permission, 0004 is the owner's read permission, 0020 is the group's write permission, and 0040 is the group's read permission.

0200 is the write permission of others and 0400 is the read permission of others. The sum of these six numbers is 666. the result is shown in figure 1.

Figure 1 using chmod digital method to set file permissions

As you can see from figure 1, the permission of the tem file is-rw-rw-rw-, that is, the user has read and write permissions to the file.

If you use the character permission setting, use the following command:

# chmod a = wx tem

Chown

1. Action

Change the owner and group of one or more files or directories. The permission is superuser.

two。 Format

Chown [options] user or group files

3. Main parameters

-- dereference: what is affected is the object indicated by the symbolic link, not the symbolic link itself.

-h,-- no-dereference: affects the symbolic link itself, not the destination indicated by the symbolic link (this option is only valid when the system supports changing the owner of the symbolic link).

-- from= current owner: currently the group will change the owner and group only if the owner and group of each file match those specified by the option. One of them can be omitted, and the omitted attribute does not need to match the original attribute.

-f,-- silent,-- quiet: remove most of the error messages.

-R,-- recursive: recursively processes all files and subdirectories.

-v,-- verbose: processing any file will display information.

4. Description

Chown changes the owner of the specified file to the specified user or group, the user can be the user name or the user ID; group can be the group name or the group ID; file is a list of files to change permissions separated by spaces, and wildcards are supported. System administrators often use the chown command to give users permission to use a file after it has been copied to another user's directory.

5. Application example

1. Change the owner of the file shiyan.c to wan

$chown wan shiyan.c

two。 Change the owner of the directory / hi and all its files and subdirectories to wan and the group to users.

$chown-R wan.users / hi

Chattr

1. Action

Modify the ext2 and ext3 file system properties (attribute) to use the privileged superuser.

two。 Format

Chattr [- RV] [- + = AacDdijsSu] [- v version] file or directory

3. Main parameters

-R: recursively processes all files and subdirectories.

-V: display the changes in detail and print out.

-: invalidation attribute.

+: activate the attribute.

=: specify the attribute.

A:Atime, tell the system not to change the last access time to this file.

S:Sync, once the application performs a write operation on this file, causes the system to write the modified results to disk immediately.

A:Append Only, the system only allows data to be appended to this file, and no process is allowed to overwrite or truncate the file. If the directory has this property, the system will only allow files to be created and modified in this directory, not to delete any files.

I:Immutable, the system does not allow any changes to this file. If the directory has this attribute, then any process can only modify the files under the directory and is not allowed to create and delete files.

D: check for errors in the compressed file.

D:No dump, the dump program will ignore this file when backing up the file system.

C:Compress, the system compresses this file transparently. When reading from this file, the unzipped data is returned; when writing data to this file, the data is first compressed before it is written to disk.

S:Secure Delete, let the system use 0 to populate the area where the file is located when deleting the file.

U:Undelete, when an application requests to delete the file, the system retains its data blocks so that the file can be deleted later.

4. Description

Chattr

Commands are very useful, some of which are supported by the Linux kernel version, and if the Linux kernel version is less than 2.2, then many functions cannot be implemented. Also-D check for errors in the compressed file

It needs more than 2.5.19 kernel to support the function. In addition, modifying properties through the chattr command can improve the security of the system, but it is not suitable for all directories. The chattr command cannot

Protect the /, / dev, / tmp, / var directories.

5. Application example

1. Restore the / root directory, that is, all files in the subdirectory

# chattr-R + u/root

two。 Use the chattr command to prevent a key file in the system from being modified

Under Linux, some configuration files (passwd, fatab) are not allowed to be modified. In order to prevent them from being deleted or modified by mistake, you can set the "unmodifiable bit (immutable)" of the file as follows:

# chattr + I / etc/fstab

Sudo

1. Action

Sudo is a command that is based on limiting the commands in the configuration file, is available to users for a limited time, and is logged to all users.

two。 Format

Sudo [- bhHpV] [- s] [- u] [instruction]

Sudo [- klv]

3. Main parameters

-b: execute the command in the background.

-h: displays help.

-H: set the HOME environment variable to the HOME environment variable for the new identity.

-k: end the validity period of the password, that is, you will need to enter the password next time.

-l: lists the commands that the current user can use.

-p: change the prompt symbol for asking for a password.

-s: executes the specified Shell.

-u: the specified user is the new identity, and defaults to root when not in use.

-v: extend the validity of the password for 5 minutes.

4. Description

Sudo

The command is configured in the / etc/sudoers file. When a user uses sudo, a password needs to be entered to verify the user's identity. The defined commands can be used for a later period of time, when using the configuration

When there are no commands in the file, there will be a record of the alarm. Sudo is a program that system administrators use to allow some users to run some or all of the system commands as root. One obvious use is to enhance the site

Security, if you need to do some daily work as a superuser every day, and often execute a few fixed commands that can only be executed as a superuser, then sudo is a good fit.

Ps

1. Action

Ps displays the dynamics of instant processes (process), and the permissions are for all users.

two。 Format

Ps [options] [--help]

3. Main parameters

Ps has so many parameters that only a few commonly used parameters are listed.

-A: list all processes.

-l: displays a long list.

-m: displays memory information.

-w: display widening can display more information.

-e: shows all processes.

A: displays all processes on the terminal, including those of other users.

-au: displays more detailed information.

-aux: displays all processes that include other users.

4. Description

To

To monitor and control the process, we must first understand the current process, that is, we need to look at the current process. The ps command is the most basic and very powerful process view command. Use this command to determine which

The process is running, the running state, whether the process ends, whether the process has zombies, which processes take up too many resources, and so on. Figure 2 shows a detailed explanation of the ps-aux command. Most of the information can be obtained by executing the life.

You can get it. The three most commonly used parameters are u, a, and x. The function of the ps command is explained in detail by combining these three parameters: ps aux

Figure 2 detailed explanation of the ps-aux command

In the second line of code in figure 2, USER represents the process owner; PID represents the process identifier;% CPU represents the CPU usage occupied;% MEM indicates the physical memory utilization; VSZ indicates the amount of virtual memory occupied; RSS is the physical memory value occupied by the process; and TTY is the secondary device number of the terminal.

STAT

Indicates the state of the process, where D is an uninterruptible rest (action Ipicuro); R is in execution; S is still; T pauses execution; Z does not exist but cannot be eliminated for the time being; W does not have enough memory to paging

Matching; high priority processes; N low priority processes; L has memory paged allocation and locked in the memory body (real-time systems or

I PUBO). START is the start time of the process. TIME is the time of execution. COMMAND is the instruction being executed.

4. Application example

In the maintenance of the system, there is often a surprising amount of memory usage, and we do not know which process takes up a large number of processes. In addition to using the top command to view memory usage, you can also use the following command:

Ps aux | sort + 5n

Who

1. Action

Who shows which users have logged in to the system, and the information displayed includes the user's ID, login terminal used, online time, lag time, CPU usage, and what they have done. Permissions are for all users.

two。 Format

Who-[husfV] [user]

3. Main parameters

-h: do not display the title column.

-u: do not display the user's actions / work.

-s: display in a short format.

-f: do not display the online location of the user.

-V: displays the version of the program.

4. Description

The

The command is mainly used to view the status of users currently online. If a user wants to establish instant messaging with other users, such as using the talk command, the first thing to make sure is that the user is actually online, otherwise

The talk process cannot be set up. As another example, the system administrator also uses the who command to monitor what each logged-in user is doing at this moment. The who command is very simple to use and can be accurate.

It has a good grasp of the situation of users, so it is widely used.

Hands on practice

1. Use the Linux command to detect system intruders

Ann

Installed Mandrake Linux and Red Hat

Users of Linux will know that the Linux system will have three different levels of firewalls (standard, high, and higher). When the Linux server is installed and some basic settings are made, the server should

It is safe to say, but there will also be hackers through a variety of ways to take advantage of the negligence of the system administrator to invade the system. How to find hackers quickly is very important. In general, you can use commands to find out whether a hacker has intruded, as shown in the table

one.

Table 1 query the command correspondence table of hacker intrusion phenomenon

For example, if a hacker sniffs a network, it must put the Nic interface in promiscuous mode and query using the following command:

# ifconfig-a

Eth0 Link encap:Ethernet HWaddr 00:00:E8:A0:25:86

Inet addr:192.168.1.7 Bcast:192.168.1.255 Mask:255.255.255.0

UP BROADCAST RUNNING PROMISCUOUS MTU:1500 Metric:1

.

From

You can see the concepts mentioned above in the output of this command. The 00:00:E8:A0:25:86 on the first line is the mac address, and 192.168.1.7 on the second line is the IP address

The fourth line is about the status of receiving data, which is being sniffed by hackers. Generally speaking, NICs have several states to receive data frames, such as Broadcast, Multicast,

Promiscuous et al. Broadcast refers to the receipt of all data frames of type broadcast messages; Multicast refers to the receipt of specific multicast messages; Promiscuous

The hybrid mode usually refers to the working mode in which all the destination hardware addresses in the message are received without any check.

two。 Limit the abuse of su commands

I

As we all know, superusers have the greatest power in Linux, and almost all hackers want to achieve this goal. Linux can increase restrictions on switching to superusers. Use PAM

(Pluggable Authentication

Modules) can prohibit anyone except in the wheel group from su into root, modify the / etc/pam.d/su file, and remove the mask logo #. Use

/ usr/sbin/usermod G10 bjecadm adds the bjecadm account to the group with a gid of 10, that is, the wheel group. The command is as follows:

/ etc/pam.d/su # use password authentication #

Auth sufficient / lib/security/pam_wheel.so debug

# restriction that only wheel group users can switch to root#

Auth required / lib/security/pam_wheel.so use_uid

Chmod-G10 bjecadm

In addition, whenever the user tries to enter the system user using the su command, the command will write a message in the / usr/adm/sulog file. If the file records a large number of invalid operations trying to enter root with su, it indicates that someone may have attempted to decipher the root password.

The Linux command has a powerful function. For Linux system administrators, it is often only necessary to combine a variety of security command skills to form a security line of defense. From the perspective of computer security, there is no absolutely secure computer system in the world, and the Linux system is no exception.

60 commands that Linux must learn (6)-other commands

60 commands that Linux must learn: other commands

In the previous lectures, we divided the Linux command into several parts according to its role in the system. However, there are some commands that are difficult to divide, but it is also important to learn them.

Tar

1. Action

The tar command is a reliable way to back up files on a Unix/Linux system, can work in almost any environment, and has the right to use it for all users.

two。 Format

Tar [primary option + secondary option] file or directory

3. Main parameters

When using this command, the primary option is required, which tells tar what to do, and the secondary option is secondary and optional.

Main options:

-c create a new archive file. Select this option if the user wants to back up a directory or some files.

-r append the file to be archived to the end of the file. For example, if the user has already backed up the file and found that there is another directory or some files that have forgotten to back up, you can use this option to append the forgotten directory or file to the backup file.

-t list the contents of the archive file to see which files have been backed up.

-u updates the file. That is, replace the original backup file with the new file, and if the file to be updated is not found in the backup file, append it to the end of the backup file.

-x release the file from the archive.

Secondary options:

-b this option is set for the tape drive, followed by a number to indicate the size of the block. the system default value is 20 (20 × 512 bytes).

-f use archives or devices, this option is usually required.

-k saves files that already exist. For example, if you restore a file, the same file will not be overwritten if you encounter the same file during the restore process.

-m when restoring files, set the modification time of all files to now.

-M creates multi-volume archives for storage on several disks.

-v report the file information processed by tar in detail. Without this option, tar does not report file information.

-w confirmation is required at every step.

-z use gzip to compress / unzip files. Add this option to compress files, but be sure to use this option to unzip files when restoring.

4. Application description

Tar is an acronym for Tape Archive (tape archiving) and was originally designed to package files on tape. If you have downloaded the source code of Linux, you may have encountered the tar file

Please note that don't forget that Linux is case sensitive. For example, tar commands should always be executed in lowercase. Command line switches can be uppercase, lowercase, or mixed case. For example,-t and-T perform different functions. File or directory names can be mixed with case and are case-sensitive just like commands and command-line switches.

5. Application example

Tar is a command-line tool with no graphical interface. Open a terminal window using Konsole, followed by a simple backup command (create a back.tar file in the / temp directory where everything in the / usr directory is included. ):

$tar cvf-/ usr > / temp/back.tar

In addition

In addition, the tar command supports the crontab command described in Lecture 3 above, and can be set up to run regularly based on time with the crontab tool. For example, back up the / usr directory at 6 o'clock every night

The primary drive of the first IDE interface of hda- (always on the first hard drive), simply add the following statement to the crontab of root:

$0006 * tar cvf / dev/hda1/usrfiles.tar-/ usr

In general, these directories need to be backed up:

◆ / etc contains all the core configuration files, including network configuration, system name, firewall rules, users, groups, and other global system items.

◆ / var contains information used by the system daemon (service), including DNS configuration, DHCP lease, mail buffer files, HTTP server files, dB2 instance configuration, and so on.

◆ / home contains the home directories of all default users, including personal settings, downloaded files, and other information that users do not want to lose.

The home directory of the ◆ / root root (root) user.

◆ / opt is where many non-system files are installed. The IBM software is installed here. OpenOffice, JDK, and other software are also installed here by default.

Some directories do not have to be backed up:

◆ / proc should never back up this directory. It is not a real file system, but a virtualized view of the running kernel and environment, including files such as / proc/kcore, which is a virtual view of the entire running memory. Backing up these files is a waste of resources.

◆ / dev contains a file representation of the hardware device. If you plan to restore to a blank system, you can back up / dev. However, if you plan to restore to an installed Linux system, then a backup / dev is not necessary.

Unzip

1. Action

Unzip

Commands are located in the / usr/bin directory, and they are associated with pkzip, pkunzip, and MS under MS DOS

The Winzip software in Windows has the same function, compressing files into .zip files to save hard disk space, and unpacking the compressed files with the unzip command when needed. The right to use the order

Limited to all users.

two。 Format

Unzip [- cflptuvz] [- agCjLMnoqsVX] [- P] [.zip file] [file] [- d] [- x]

3. Main parameters

-c: display the decompressed results on the screen and convert the characters appropriately.

-f: update existing files.

-l: displays the files contained in the compressed file.

-p: similar to the-c parameter, the result of the decompression is displayed on the screen, but no conversion is performed.

-t: check whether the compressed file is correct.

-u: similar to the-f parameter, but in addition to updating existing files, other files in the compressed file are also unzipped to a directory.

-v: displays detailed information when executing yes.

-z: only the remarks text of the compressed file is displayed.

-a: perform the necessary character conversion for the text file.

-b: do not convert characters to text files.

-C: file names in compressed files are case sensitive.

-j: the original directory path in the compressed file is not processed.

-L: change all file names in the compressed file to lowercase.

-M: send the output to the more program for processing.

-n: do not overwrite the original file when unzipping.

-o: there is no need to ask the user first. The original file is overwritten after unzip execution.

-P: use the password option of zip.

-Q: no information is displayed during execution.

-s: converts white space characters in the file name to underscore characters.

-V: keep the file version information of VMS.

-X: save the original UID/GID of the file when unzipping.

[.zip file]: specify a .zip zip file.

[file]: specifies which files in the .zip zip file are to be processed.

-d: specify the directory to store after the file is extracted.

-x: specifies which files in the .zip zip file should not be processed.

-Z unzip:-Z equals executing the zipinfo instruction. In Linux, a tool called zipinfo is also provided to view the details of zip compressed files. The latest version of unzip is 5.50.

Gunzip

1. Action

The function of the gunzip command is to extract the file, and the permission is for all users.

two。 Format

Gunzip [- acfhlLnNqrtvV] [- s] [file.]

Or

Gunzip [- acfhlLnNqrtvV] [- s] [directory]

3. Main parameters

-an or-- ascii: use ASCII text mode.

-c or-- stdout or-- to-stdout: output the decompressed file to a standard output device.

-f or-force: forcibly unzip the compressed file, regardless of whether the file name or hard connection exists, and whether the file is a symbolic link.

-h or-- help: online help.

-l or-- list: lists information about the compressed file.

-L or-- license: displays version and copyright information.

-n or-- no-name: if the compressed file contains the original file name and timestamp, it will be ignored and not processed.

-N or-- name: when unzipping, if the compressed file contains the original file name and timestamp, save it back to the unpacked file.

-Q or-- quiet: no warning message is displayed.

-r or-- recursive: recursive processing that processes all files and subdirectories under the specified directory.

-S or-- suffix: change the compressed suffix string.

-t or-- test: test whether the compressed file is correct.

-v or-- verbose: displays the instruction execution process.

-V or-- version: displays version information.

4. Description

Gunzip is a widely used unzipping program that is used to unzip files compressed by gzip, which have a default final extension of ".gz". In fact, gunzip is a hard connection to gzip, so whether it is compressed or decompressed, it can be done separately through the gzip instruction. The latest version of gunzip is 1.3.3.

Unarj

1. Action

Unarj unzips files in .arj format with permissions for all users.

two。 Format

Unarj [eltx] [.arj zip file]

3. Main parameters

E: extract the .arj file.

L: displays the files contained in the compressed file.

T: check whether the compressed file is correct.

X: keep the original path when unzipping.

4. Description

Files with the .arj extension are created by the ARJ utility for MS DOS and Windows. Because ARJ is a shareware program that does not have free access to the source code, so in the

Mtools

1. Action

Mtools

It is actually a collection of commands, a tool for the DOS file system, which can simulate many DOS commands and is very convenient to use. Permissions are for all users. The Linux system provides a set of

Mtools's portable tool allows users to easily read and write files and directories from standard DOS floppy disks. They are useful for exchanging files between DOS and Linux environments. Mtools's

It is very easy to use. If you want to copy all the files on the floppy disk to the hard disk, you can execute the following command:

Mcopy aRose. *

In other words, you only need to add the letter "m" before the corresponding DOS command, and you can complete the corresponding function. This software is generally available in Linux distributions, and you can check it with the following command.

Rpm-qa | grep mtools

If you don't have an installation, it doesn't matter. You can download it from the Internet (the latest version of http://mtools.linux.lu/)) to install it. The latest version of mtools currently available for download is

two。 Included command

Mcd directory name: change the directory under MS DOS.

Mcopy source file destination file: copies files between MS DOS and Unix.

Mdel file name: delete the file under MS DOS.

Mdir directory name: displays the directory under MS DOS.

Mformat drive letter: creates a MS DOS file system on a low-level formatted floppy disk.

Rnlabel drive letter: generates a volume label under MS DOS.

Mmd directory name: create a directory under MS DOS.

Mrd directory name: delete the directory under MS DOS.

Mren source file destination file: rename an existing MS DOS file.

Mtype file name: displays the contents of the MS DOS file.

Note that these commands are very similar to the corresponding MS DOS commands. In the mtools command, "/" and "\" can be mixed. Because the file list is a document under DOS, it is not case-sensitive, so "CDE" and "cde" are the same here.

3. Application example

(1) if you quickly format the floppy disk, you can use the command mformat:

Mformat A:

Mtools

It was originally developed to deal with DOS file systems, so it can only be used on partitions in FAT file format. It should be noted that if the FAT16/32 partition is mounted with the mount command, the

You cannot use mtools instructions to process files on these partitions. This is because once the FAT16/32 partition is hung in the Linux file directory, Linux treats it as a file system

Part of itself, if you want to operate on it, you must use the instruction set that comes with Linux itself.

(2) copy the file htca.c on the DOS disk to the current directory and verify it with the ls command.

$mcopy a:\ htca.c

$ls-l htca.c

-rw-r--r-- 1 xxq xxq 27136 Jan 1 01:80 htca.c

Man

1. Action

The man command is used to provide online help, with permissions for all users. A manual for online use is stored in the Linux system for users to find on the terminal. Using the man command, you can access the help information, which is very convenient and practical.

two。 Format

Man command name

Man [- acdfhkKtwW] [- m system] [- p string] [- C config_file] [- M path] [- P pager] [- S section_list] [section] name...

3. Parameters.

-C config_file: specifies the configuration file man.conf. The default value is / etc/man.conf.

-M path: specifies the search path of the online manual, if not specified, the setting of the environment variable MANPATH is used; if MANPATH is not used, the setting in / usr/lib/man.conf is used; if the MANPATH is an empty string, the default value is used.

-P pager: specify which pager.man to use first, then set according to the environment variable MANPAGER, and then the environment variable PAGER;man uses / usr/bin/less-is by default.

-S section_list man: a list of searched chapters (separated by colons). This option overrides the setting of the environment variable MANSECT.

-a man: the default is to stop searching after the first found manual is displayed, and using this option forces man to continue to display all name-compliant online manuals.

-c: continue to retype the online manual even with the latest cat page, this option is especially meaningful when the number of rows on the screen changes or when the typeset online manual is damaged.

-d: don't actually display the online manual, only debug messages.

-D: displays both the online manual and the debugging message.

-h: displays a help message and then ends the program.

-K: search all online manuals for the specified string. Please note that the response speed of this feature may be slow, and it will be helpful if you specify the section (zone).

-m system: an online manual that specifies another group according to the specified system name.

Man: is the abbreviation of manual. When you have difficulty entering a command, you can get this document immediately. For example, if you have difficulty using the ps command, you can enter man ps to get help, and the man page of ps (man page) is displayed.

Since the man page man page is viewed in the less program (you can easily scroll up and down the screen), all the options of less are available in man page.

The more important function keys in less are:

[Q] exit

[Enter] row by line of underground flip

[Space] turn the pages down

Turn the page

[/] followed by a string and [Enter] to find the string

[n] the next match found in the previous search.

4. Read the manual page

The man pages provide a lot of information in very little space, and here is a brief introduction to some of the contents found in most man pages. The Linux man page mainly consists of nine parts: user instructions, system calls, libraries, device descriptions, file formats, games, miscellaneous, system instructions, kernel, and man page snapshots as shown in figure 1.

Figure 1 Snapshot of the ps command man page

The layout of the Linux man page is shown in Table 1.

5. Application example

Linux

There are some basic and important commands in the commands, such as ps, find, cat, and ls. Here is an example of a comprehensive application, from which we can see that the position of man is crucial in Linux.

Yes. However, the information displayed by man is not ordinary text. If you redirect the text directly to a text file, you will find that the highlighted text in man becomes two, and regardless of it.

The tabs of numbers make printing and editing very inconvenient. However, you can get the ps command to print using the following statement.

# man ps | col-b | lpr

This command uses both output redirection and plumbing techniques to print the help information of the ps command directly. More Man files can be found in Linux Man.

Unencode

1. Action

The unencode command encodes a table of binary files into a text file with permissions for all users.

two。 Format

Uuencode [- hv] [source file] destination file

3. Main parameters

-h: lists the instruction usage format (help).

-v: lists version information.

4. Application description

The uuencode directive converts binary files into ASCII encodings that can be sent by e-mail. The data encoded by uuencode starts with begin and ends with end, and usually each line begins with "M". The middle part is the encoded file, which is larger than the source file.

Uudecode

1. Action

The uudecode command is used to restore the uuencode-encoded files. Uudecode will only restore the encoded data between the begin and end tags, and the program will skip the data outside the tags. It has permissions for all users.

two。 Format

Uuencode [- hv] [file1...]

3. Main parameters

-h: lists the instruction usage format (help).

-v: lists version information.

4. Application example

Restore several files at a time using the following command:

Uuencode file1.uud file2.uud file3.uud

Hands on practice

1. Send mail under the Linux command line

Although the Linux desktop application is developing rapidly, the command line (Shell) still has a strong vitality in Linux. If you can confirm that the email server supports the bytes of 8bit, you can directly use the following command:

Cat < attachment file name > | mail < email address >

The cat (cat is short for concatenate) command processes several files into a single file and saves the results of this processing to a separate output file, which we use to merge the text of the mail.

Write the name of the email, such as cjkmail, and then use the following command:

$uuencode < attachment file name > < attachment file name > > cjkmail

In this way, you can write the cjkmail file with a vi editor, write the body of the letter in front of it, and then send it.

After the other party receives the letter, copy out the contents of the letter that belong to cjkmail and save it as themail.uue. If the other party is under Windows, you can extract it with WinRAR or WinZip, so you can see the attachment.

If the other party also uses Linux, you can restore it with the undecode command:

$uudencode-o < attachment file name > themail.uue

two。 Realize the partition of tar

The author wants to compress a 378MB file into multiple 63MB files (the author's USB is 64MB), use the following command:

$tar czvf-dir | split-d-b 63m

Then merge the commands:

$cat x * > dir.tgz

The above example is actually done by a combination of three commands, namely, packaging with tar, splitting with split, and merging with cat. "tar czvf-dir" means to package the dir directory and output it to standard output (argv), so that it can be piped directly to split.

3. Execute a command continuously

Using the watch command, you can execute the command repeatedly. If you cooperate with ls, you can observe the changes in the size of a file.

$watch ls-l file.name

4. Export a file with the tar command

There is a tar format DVD file GLvPro6.4_linux.tar, because the file is very large (4.7GB), if all decompression is more troublesome, you can use the following command to export readme.txt to have a look.

Tar xvf GLvPro6.4_linux.tar readme.txt

In this way, readme.txt is exported separately.

5. When packaging a directory with tar, only a few subdirectories are backed up.

Tar cf-exclude home/cjh home/cao

In this way, only two subdirectories, cjh and cao, are backed up under the home directory.

After reading the above, do you have any further understanding of the 60 commands that linux must learn? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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