60 Linux commands you must learn

coldplay.xixi
coldplay.xixiOriginal
2020-08-01 15:14:1916493browse

60 commands you must learn in Linux: 1. The function of login is to log in to the system, and its permission is for all users; 2. The function of the shutdown command is to shut down the computer, and its permission is for the super user; 3. The function of the halt command is to shut down the system, and its permission is the super user.

60 Linux commands you must learn

Linux provides a large number of commands, which can be used to effectively complete a large number of tasks, such as disk operations, file access, directory operations, process management, file Permission settings, etc. Therefore, working on a Linux system is inseparable from using the commands provided by the system. If you want to truly understand the Linux system,

you must start by learning Linux commands. You can further understand the Linux system through basic command learning.

The number of commands in different Linux distributions is different, but the minimum number of commands in Linux distributions is more than 200. Here, the author divides the more important and most frequently used commands into the following six parts according to their role in the system and introduces them one by one.

◆ 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 article 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 the content of a certain part or the usage of a certain command on this page.

Related learning recommendations: linux video tutorial

60 commands you must learn in Linux (1)-Installation and login commands

login

1. Function

The function of login is to log in to the system, and its usage rights are for all users.

2. Format

login [name][-p][-h host name]

3.Main parameters

-p: Notify login Keep the current environment parameters.

-h: Used to transfer username to remote login.

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

The general interface is 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 version number, the second line is the kernel version number and the login virtual console, we are in the third line Enter the login name, press the "Enter" key and enter the account password after Password to 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 (taking the super user as an example):

[root@localhost root]

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

The above shows the login day, month, day, time and virtual console used.

4. Application skills

Linux

is a true multi-user operating system that can accept multiple user logins at the same time, and also allows one user to log in multiple times. This is because Linux, like many versions of Unix, provides access to virtual consoles, allowing users to access the virtual console from the console at the same time (the system's console is a monitor and keyboard directly connected to the system) Make multiple logins. Each virtual console can be regarded as an independent workstation, and workstations can be switched between

. Switching between virtual consoles can be achieved by pressing the Alt key and a function key, usually F1-F6.

For example, after the user logs in, press the "Alt

F2" key, the user can see the "login:" prompt that appears above, indicating that the user has seen the second virtual control tower. Then just press the "Alt

F1" key to get back to the first virtual console. A newly installed Linux system allows users to access the first six virtual consoles using the "Alt F1" through "Alt F6" keys. The most useful thing about virtual console

is that when a program error causes the system to deadlock, you can switch to other virtual consoles to work and close the program.

shutdown

1. Function

The function of the shutdown command is to shut down the computer, and its usage rights are super users.

2.Format

shutdown [-h][-i][-k][-m][-t]

3.Important parameters

-t: Tell the init program how long to shut down before changing to other run levels.

-k: It does not actually shut down, but only sends a warning signal to each login.

-h: Turn off the power after shutdown.

-c: cancel current process Cancel the shutdown program currently being executed. So of course this option has no time parameter, but you can enter a message to explain it, and this message will be sent to each user.

-F: Force fsck when restarting the computer.

-time: Set the time before shutting down.

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

-i: Display 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, there are many processes running in the background, so forced shutdown may cause data loss of the process, put the system in an unstable state, and even damage hardware devices (hard disks) in some systems. ). If you use the

shutdown command before shutting down the system, the system administrator will notify all logged-in users that the system will be shut down, and the login command will be frozen, that is, new users will no longer be able to log in.

halt

1. Function

The function of the halt command is to shut down the system, and its usage authority is the super user.

2.Format

halt [-n] [-w] [-d] [-f] [-i] [-p]

3. Main parameters Description

-n: Prevent sync system call, which is used after patching the root partition with fsck to prevent the kernel from overwriting the patched super block with an older version of the super block.

-w: It is not a real restart or shutdown, it just writes wtmp (/var/log/wtmp) records.

-f: Shutdown is not called, but forced shutdown or restart.

-i: Before shutting down (or restarting), turn off all network interfaces.

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

-p: When shutting down, perform the action of turning off the power.

-d: Shut down the system but leave no records.

4. Command description

halt

is to call shutdown

-h. When halt is executed, the application process is killed and the sync (forcibly writing the data stored in the buffer to the hard disk) system call is executed. After the file system write operation is completed, the kernel will be stopped. If the

running level of the system is 0 or 6, shut down the system; otherwise, use the shutdown command (plus the -h parameter) instead.

reboot

1. Function

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

2. Format

reboot [-n] [-w] [-d] [-f] [-i]

3. Main parameters

-n: Do not write memory data back to the hard disk before restarting.

-w: It does not actually restart the computer, it just writes the records to the /var/log/wtmp file.

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

-i: Stop all network-related devices before restarting.

install

1. Function

The install command is used to install or upgrade software or back up data. Its usage rights are for all users.

2. Format

(1)install [option]... source destination

(2)install [option]... source... directory

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

In the first two formats, multiple files will be copied to or To existing ones, set the permission mode and owner/group at the same time. In the third format, all specified directories and their home directories are created. The parameters that are required for long options are also required when using short options.

3. Main parameters

——backup[=CONTROL]: Backup each existing destination file.

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

-c: (This option is not processed).

-d,--directory: All parameters are treated as directories, and all main directories of the specified directory will be created.

-D: All home directories before creation and then copied to ; useful in the first usage format.

-g,--group=group: Set the group to which the process belongs, instead of the group to which the process currently belongs.

-m,--mode=mode: Set the permission mode by yourself (like chmod), instead of rwxr-xr-x.

-o,--owner=owner: Set the owner by yourself (only applicable to super users).

-p,--preserve-timestamps: Use the access/modification time of the file as the time attribute of the corresponding destination file.

-s,--strip: Use the strip command to delete the symbol table, which is only applicable to the first and second usage formats.

-S,--suffix=suffix: specify the backup file by yourself.

-v,--verbose: Print the name of each file/directory when processing it.

--help: Display this help message and exit.

--version: Display version information and leave.

mount

1. Function

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

2. Format

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

3. Main Parameter

-h: Display auxiliary information.

-v: Display information, usually used with -f for debugging.

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

-F: This command is usually used together with -a. It will generate a trip for each mount action to be executed. It can speed up loading when the system needs to mount a large number of NFS file systems.

-f: Usually used for debugging. It will cause mount not to perform the actual mounting action, but to simulate the entire mounting process. It is usually used with -v.

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

-n: Generally speaking, after mount is mounted, a piece of data will be written in /etc/mtab. If there is no writable file system in the system, you can use this option to cancel this action.

4. Application Tips

On Linux

and Unix systems, all files are accessed as part of a large tree (rooted with /). To access files on a CD-ROM, the CD-ROM device needs to be mounted at a certain mount point in the file tree. If the distribution has an automount package installed, this step can be performed automatically. In Linux, if you want to use a storage device such as a hard disk or optical drive, you must first load it. After the storage device is mounted,

you can access it as a directory. Mount a device using the mount command. When using the mount command, you must first know at least the following three types of information: the file system type of the object to be loaded, the device name of the object to be loaded, and the directory to which the device is to be loaded.

(1) File system recognized by Linux

◆ FAT 32 file system commonly used in Windows 95/98: vfat;

◆ Win NT/2000 file system: ntfs;

◆ File system for OS/2: hpfs;

◆ File system for Linux: ext2, ext3;

◆ File for CD-ROM disc System: iso9660.

Although vfat refers to the FAT 32 system, in fact it is also compatible with the FAT 16 file system type.

(2) Determine the name of the device

In Linux

, the device name usually exists in /dev. The naming of these device names has rules, and the device names can be found out through "inference". For example, /dev/hda1 is the

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

Disk?). a represents the first device. Usually the IDE interface can connect to 4 IDE devices (such as 4 hard drives). So the methods to identify IDE hard drives are hda, hdb, hdc,

hdd. The "1" in hda1 represents the first hard disk partition

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

/var/log/messages file. In this file, you can find the device code that the system has recognized after the computer is turned on.

(3) Find the mounting point

Before deciding to mount the device, first check whether the computer has an empty directory of /mnt. This directory It is a directory specifically used as a mount point (Mount

Point). It is recommended to create several /mnt/cdrom, /mnt/floppy, /mnt/mo and other directories in /mnt as special mount points for the directories. For example, if

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

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 Currently, most newer Linux distributions (including Red Flag Linux, ChinaSoft Linux, Mandrake Linux, etc.) can automatically mount file systems, with the exception of Red Hat Linux.

umount

1. Function

The umount command is used to unmount a file system, and its usage permissions are super users or users allowed in /etc/fstab.

2. Format

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

3. Use Note: The

umount

command is the reverse operation of the mount command. Its parameters and usage are the same as the mount command. After Linux mounts the CD-ROM, it will lock the CD-ROM so that it cannot be ejected using the Eject button on the CD-

panel. However, when the disc is no longer needed, if you have /cdrom as a symbolic link, use umount /cdrom to unmount it. This command will succeed only if no user

is using the disc. This command involves opening a terminal window with the current working directory as a directory on the disc.

chsh

1. Function

The chsh command is used to change the user shell settings, and its usage rights are for all users.

2. Format

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

3.Main parameters

-l: Display all shell types in the system.

-v: Displays the Shell version number.

4. Application skills

As mentioned before, there are many kinds of Shells under Linux. Generally, 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

above In the code, [ ] indicates the currently used Shell. Ordinary users can only modify their own Shells, while super users can modify the Shells of all users. To query which shells are provided by the system, you can use the chsh -l command, as shown in Figure 1.

Figure 1 Shell types that can be used in the system

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

exit

1. Function

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

2.Format

exit

3.Parameters

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

last

1. Function

The function of the last command is to display the recent login status of users or terminals, and its usage permissions are for all users. By viewing the log of the program through the last command, the administrator can learn who has or attempted to connect to the system.

2. Format

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

3. Main parameters

-n: Specify the number of output records.

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

-t tty: Only display login status on the specified virtual console.

-h node: Only display the login status on the specified node.

-i IP: Only display the login status on the specified IP.

-1: Use IP to display the remote address.

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

-ID: Know the user name of the query.

-x: Display the history of system shutdown, user login and exit.

Hands-on practice

The Linux installation and login commands are introduced above. Here are a few examples to practice the commands just mentioned.

1. Run multiple commands at one time

You can execute multiple commands in one command line, just separate each command with a semicolon, for example:

# last -x; halt

The above code means to shut down the computer after displaying the history of system shutdown, user login and exit.

2. Use mount to mount the file system to access the Windows system

Many Linux distributions can now automatically load the Vfat partition to access the Windows system, while all versions of Red Hat do not automatically load the Vfat partition. , so manual operations are still required.

mount

You can mount the Windows partition as a "file" in Linux to an empty folder in Linux, thereby linking the Windows partition to the /mnt directory. Therefore, simply accessing this folder is equivalent to accessing the partition. First, create the winc folder under /mnt and enter the following command at the command prompt:

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

that is,

means to mount the C partition of Windows to the /mnt/winc directory of Liunx. At this time, you can see the contents of the C drive in Windows in the /mnt/winc directory. Use a similar method to access the D and E drives of the Windows system. The general order of Windows partitions displayed on a Linux system is as follows: hda1 is the C drive, hda5 is the D drive,

hda6 is the E drive... and so on. There is a big problem with using the above method to check the Windows system, that is, all Chinese file names or folder names in Windows are all displayed as question marks

"?", while English can be displayed normally. We can make it display Chinese by adding some parameters. Taking 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 disk

It is very simple to use the flash disk under Linux. Linux has good support for USB devices. When a flash disk is inserted, the flash disk is recognized as a SCSI disk. Usually, the following command is entered:

# mount /dev/sda1 /usb

You can add the file system on the flash drive.

Little knowledge

Linux commands and Shell

The so-called Shell

is the command interpreter. It provides a programming interface and you can use the program to programming. Learning Shell is very important for Linux beginners to understand the Linux system.

The Shell of the Linux system serves as the shell of the operating system and provides users with an interface for using the operating system. Shell is the collective name for command language, command interpreter and programming language. It is the interface program between the user and the

Linux kernel. If you imagine the Linux kernel as the center of a sphere, the Shell is the outer layer surrounding the kernel. When a command is passed to Linux from the Shell or other program, the kernel will respond accordingly. The role of Shell in Linux systems is similar to COMMAND.COM under MS DOS and

explorer.exe in Windows 95/98. Although the Shell is not part of the system core and is just an extension of the system core, it can call most functions of the system kernel. Therefore, it can be said that

Shell is the most important utility in Unux/Linux.

There are many types of Shells in Linux, the most commonly used ones are Bourne

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

Again Shell. It is an extension of Bourne Shell, referred to as bash. It is fully backward compatible with Bourne Shell and is based on Bourne

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

Shell and Korn

Shell. It has a flexible and powerful programming interface and a very friendly user interface. 40 of the more than 200 commands in the Linux system are bash internal commands, mainly including

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

60 Must-Learn Linux Commands (2)-File Processing Commands

Linux

System information is stored in files, which are similar to ordinary official files. 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, etc. 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, and the system provides many file processing programs. Here we mainly introduce the commonly used file processing commands.

file

1. Function Determine the file type based on the file content, and the usage permission is for all users.

2.Format

file passes the detection file

file [options] file name

3.[options]main parameters

-v: Display version information after standard output and exit.

-z: Detect compressed file types.

-L: Allow conforming connections.

-f name: Read the list of file names to be analyzed from the file namefile.

4. Brief explanation

Use the file command to know whether a file is a binary (ELF format) executable file, a Shell Script file, or some other format. The file types that file can recognize include directories, shell scripts, English texts, 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 time, the system displays that this is an English text file. It should be noted that the file command cannot detect multimedia file types including graphics, audio, video, etc.

mkdir

1. Function

The function of the mkdir command is to create a subdirectory named dirname. It is similar to the md command under MS DOS. Its usage permissions are all user.

2.Format

mkdir [options] Directory name

3.[options]Main parameters

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

-p, --parents: Create the upper-level directory when necessary; if the directory already exists, it will not be treated as an error.

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

--version: Display version information and then exit.

4. Application Example

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

$ mkdir -m 777 tsk

grep

1. Function

The grep command can search for specific content in a specified file and output the lines containing these contents to the standard output. The full name of grep is Global Regular Expression Print, which means the global regular expression version. Its usage permissions are for all users.

2. Format

grep [options]

3. Main parameters

[options]Main parameters:

-c: Only the count of matching rows is output.

-I: Case-insensitive (only applicable to single characters).

-h: Do not display the file name when querying multiple files.

-l: When querying multiple files, only the file names containing matching characters will be output.

-n: Display matching lines and line numbers.

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

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

pattern Regular expression main parameters:

\: Ignore the original meaning of special characters in the regular expression.

^: matches the starting line of the regular expression.

$: Matches the end line of the regular expression.

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

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

[-]: Range, such as [A-Z], that is, A, B, C to Z all meet the requirements.

. : All single characters.

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

Expressions are a very important concept in Linux/Unix systems. A regular expression (also called "regex" or "regexp") is a pattern that can describe a type of string

(Pattern). If a string can be described by a regular expression, we say that the character matches the regular expression. This is similar to how users in DOS can use the wildcard character

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

4. Application examples

Query

Querying DNS services is one of the daily tasks, which means maintaining a large number of IP addresses covering different networks. Sometimes there are more than 2,000 IP addresses. If you want to view the nnn.nnn network address, but forget the rest of the second part of

, you only know that there are two periods, such as nnn nn.... To extract all nnn.nnn IP addresses, use [0-9]\{3

\}\.[0-0\{3\}\. The meaning is any number appearing 3 times, followed by a period, followed by any number appearing 3 times, followed by a period.

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

Additional explanation, the grep family also includes fgrep and egrep. fgrep is fix grep, which allows searching for strings instead of a pattern; egrep is an extension of grep, which supports basic and extended regular expressions, but does not support the application of \q pattern range and some corresponding more standardized patterns.

dd

1. Function

The dd command is used to copy files and convert and format the data according to the parameters.

2.Format

dd [options]

3.[options]Main parameters

bs=bytes: force ibs= and obs=.

cbs=bytes: specified per conversion.

conv=Keyword: Convert the file according to a comma-separated keyword representation.

count=Number of blocks: Only copy the specified input data.

ibs=Bytes: Read the specified number each time.

if=File: Read the content instead of the standard input data.

obs=bytes: specified each time written.

of=File: Write data instead of displaying it to standard output.

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

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

4. Application examples

The dd command is often used to create a Linux boot disk. First find a bootable kernel, make its root device point 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 explains that use the rdev command to point the root device in the bootable kernel vmlinuz to /dev/hda. Please replace "hda" with your own root partition. Next Use the dd command to write the kernel to the floppy disk.

find

1. Function

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

2. Format

find [path][options][expression]

path specifies the directory path, from which the system starts to search for files downwards along the directory tree. It is a list of paths, separated by spaces. If path is not written, it defaults to the current directory.

3. Main parameters

[options] Parameters:

-depth: Use the depth level search process method to prioritize the search for file contents in a specified directory at a certain level.

-maxdepth levels: Indicates that at most the level-th subdirectory of the starting directory is found. Level is a non-negative number. If level is 0, it means searching only in the current directory.

-mindepth levels: Indicates that at least the level-level subdirectory of the starting directory is found.

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

-version: print version.

[expression] is a matching expression and is an expression accepted by the find command. All operations of the find command are based on expressions. It has many parameters. Here we only introduce some commonly used parameters.

—name: Supports the wildcard characters * and ?.

-atime n: Search for files read in the past n days.

-ctime n: Search for files modified in the past n days.

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

-user username: Search for all files whose owner is the username (ID or name).

-size n: Search for files whose size is n blocks.

-print: Output the search results and print them.

4. Application skills

Several ways to find files using the find command:

(1) Search based on the file name

For example, we want to find For a file whose file name is lilo.conf, you 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

Finding files based on file names will encounter a practical problem, that is, it will take a long time, especially for large-scale Linux When file system and large hard disk files are placed in deep subdirectories. If we know that the file

is stored in a certain directory, then we can save a lot of time by just searching down in this directory. For example, the smb.conf file can be judged from its file suffix ".conf" as a configuration file. Then it should be in the /etc directory. In this case, you can use the following command:

find /etc -name smb.conf

In this way, using the "quickly find files" method can shorten the time.

(3) Search method based on part of the file name

Sometimes we know that only a certain file contains the four characters abvd, then we need to find all the files in the system that contain these four characters You can enter the following command:

find / -name '*abvd*'

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

(4) Use mixed search method to find files

The find command can use mixed search method. For example, we want to find files larger than 500000 bytes in the /etc directory and within 24 hours. If you modify a certain file, you can use -and (and) to link the two search parameters to form a mixed search method.

find /etc -size 500000c -and -mtime 1

mv

1. Function

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

2. Format

mv[options] Source file or directory Target file or directory

3.[options]Main parameters

-i: Interaction way to operate. If the mv operation will cause the overwriting of an existing target file, the system will ask whether to rewrite and require the user to answer "y" or "n" to avoid accidentally overwriting the file.

-f: Disable interactive operations. The mv operation does not give any instructions when overwriting an existing target file. After specifying this parameter, the i parameter will no longer have any effect.

4. Application example

(1) Move all files in /usr/cbu to the current directory (indicated by "."):

$ mv /usr/cbu/ * .

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

$ mv cjh.txt wjz.txt 

ls

1. Function

ls command is used to display directory contents, similar to the dir command under DOS. Its usage permissions are for all users.

2. Format

ls [options][filename]

3.options main parameters

-a, --all: Do not hide any Items starting with "." character.

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

--author: Print the author of each file.

-b, --escape: Represent unprintable characters as octal overflow sequence.

--block-size=Size: The block is in specified bytes.

-B, --ignore-backups: Do not list any items ending with ~ character.

-f: No sorting is performed, the -aU parameter takes effect, and the -lst parameter fails.

-F, --classify: Add the file type indicator (one of */=@|).

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

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

-i, --inode: List the inode number of each file.

-I, --ignore=Style: Do not print any items that match Shell wildcards.

-k: that is--block-size=1K.

-l: Use a longer format to list information.

-L, --dereference: When displaying file information of a symbolic link, display the object indicated by the symbolic link, 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 lists UID and GID numbers.

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

-p, --file-type: Add the file type indicator (one of /=@|).

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

-r, --reverse: Arrange in reverse order.

-R, --recursive: List all subdirectory levels at the same time.

-s, --size: Ordered by block size.

4. Application examples

ls

command is the most frequently used command in Linux systems, and it also has the most parameters among Linux commands. There are several different colors when using the ls command. Blue represents a directory, green represents an executable file, red represents a compressed file, light blue represents a link file, and bold Black represents symbolic links, gray represents files in other formats. The most commonly used ls is ls-l, as shown in Figure 1.

Figure 1 Use the ls-l command

The file type starts with a string of 10 characters. The first character indicates the file type, which can be one of the following types: - (ordinary file), d (directory), l (symbolic link), b (block device file), c (Character device file). The following 9 characters represent the file access permissions, divided into 3 groups, each group has 3 digits. The first group represents the permissions of the file owner, the second group represents the permissions of users in the same group, and the third group represents the permissions of other users. Each group of three characters represents read (r), write (w), and execute permissions (x) on the file. For directories, indicates access permissions. s means that when the file is executed, the UID

or GID of the file is assigned to the UID (user ID) or GID (group

ID) of the executing process. t means setting the flag bit (remaining in memory and not being swapped out). If the file is a directory, files in the directory can only be deleted by the superuser, the directory owner, or the file owner. If it is an executable file, the pointer to its text segment remains in memory after the file is executed. This will allow the system to load the file faster when you execute it again. What is then displayed is the file size, generation time, file or command name

.

diff

1. Function

The diff command is used to compare two files and point out the difference between them. Its usage permissions are for all users.

2.Format

diff [options] Source file target file

3.[options]Main parameters

-a: Treat all files as files to process this file.

-b: Ignore differences caused by spaces.

-B: Ignore differences caused by blank lines.

-c: Use schema output format.

-H: Use heuristics to speed up searches of large files.

-I: Ignore case changes.

-n --rcs: Output RCS format.

cmp

1. Function

The cmp (abbreviation of "compare") command is used to briefly indicate whether there are differences between two files. Its usage permissions are for all users.

2.Format

cmp[options] File name

3.[options]Main parameters

-l: Convert bytes to decimal Output, and it is convenient to output the difference in the two files in octal mode.

cat

1. Function

cat (abbreviation of "concatenate") command is used to connect and display information about one or more specified files. Its use Permissions are for all users.

2. Format

cat [options] File 1 File 2...

3.[options] Main parameters

-n: from the first Line start numbers the rows of all output.

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

-s: When there are more than two consecutive blank lines, replace them with one blank line.

4. Application examples

(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 it is necessary to process several files into file and saves the results of this processing to a separate output file. The cat command accepts one or more files on its input and prints them as a single file

to its output. For example, after adding line numbers to the file contents of README and INSTALL (blank lines are not added), append the contents to a new text file File1:

$ cat README INSTALL File1

(3 ) Another important function of cat is to number the lines, as shown in Figure 2. This feature is convenient for the preparation of program documentation, as well as the preparation of legal and scientific documents. The line numbers printed on the left make it easy to refer to a certain part of the document, which is useful in programming, scientific research, business reports, and even legislative work. is very important.

Figure 2 Use the cat command/etc/named.conf file to number

The line numbering functions include -b (only non-blank lines can be numbered) and -n (can number non-blank lines) All lines are numbered) Two parameters:

$ cat -b /etc/named.conf

ln

1. Function

ln command is used To create links between files, its usage rights are available to all users.

2. Format

ln [options] Source file [link name]

3. Parameters

-f: When linking, first link the source file delete.

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

-s: Perform soft link (Symbolic Link).

-b: Back up files that will be overwritten or deleted during linking.

There are two types of links, one is called Hard Link and the other is called Symbolic Link. By default, the ln command generates hard links.

Hard

The connection refers to the connection through the index node. In the Linux file system, files stored in disk partitions are assigned a number regardless of their type, called the index node number (Inode

Index). In Linux, multiple file names pointing to the same index node exist. Generally this connection is a hard connection. The function of hard link is to allow a file to have multiple valid path names, so that users

can establish hard links to important files to prevent "accidental deletion". The reason for this 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 index node itself and

other connections. Only when the last connection is deleted, the data blocks of the file and the directory connections will be released. In other words, the file will actually be deleted.

Corresponding to the hard connection, there is another connection in the Lnux system, called the symbolic link (Symbilc Link), also called a soft link. Soft link files are somewhat similar to Windows shortcuts. It is actually a type of special file. In a symbolic link, the file is actually a text file that contains the location information of another file.

Hands-on practice

We have introduced the Linux file processing commands above. Here are a few examples so that you can practice the commands just mentioned.

1. Use symbolic links to quickly access key directories

symbol links are a very practical function. Suppose there are some directories or files that need to be used frequently, but due to Linux's file and directory structure and other reasons, this file or directory is in a deep subdirectory. For example,

Apache

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

very difficult to remember).

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

In order to easily enter the directory where the Web server (/usr/local/httpd/htdocs) document is located, you can use the following command in the home directory:

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

In this way, you can access the documents of the Web server every time you enter the gg directory. If you no longer access the documents of the Web server, just delete gg, and the documents of the real Web server will not be accessed. Not deleted.

2. Use the dd command to import the root.ram content in the init.rd format into the 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 it can be called internally in many Linux systems .

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

$ ls -l | grep '∧d'

(2) If it is in a directory Query all files that do not contain directories, the method is as follows:

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

(3) Use the find command to call grep, such as all C sources "Chinput" in the code, the method is as follows:

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

Linux must learn 60 Commands (3)-System management commands

Must-learn system management commands for Linux

For Linux systems, whether it is the central processor, memory, disk drive, keyboard, mouse, or user, they are all files, and the commands of Linux system management are the core of its normal operation. After becoming familiar with the commonly used file processing commands in Linux, this lecture introduces the commands for managing the system and users.

df

1. Function

The df command is used to check the disk space usage of the file system. The usage permission is for all users.

2. Format

df [options]

3. Main parameters

-s: Only the occupied data blocks are given for each Names parameter. total.

-a: Recursively display the number of data blocks occupied by each file in the specified directory and each file in the subdirectory. If neither -s nor -a is specified, only the number of disk blocks occupied by each directory in Names and each subdirectory in it is displayed.

-k: Lists disk space usage in units of 1024 bytes.

-x: Skip directories on different file systems and do not count them.

-l: Calculate the size of all files, and calculate multiple times for hard link files.

-i: Display inode information instead of block usage.

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

-P: Use POSIX output format.

-T: Display the file system type.

4. Description

The df command is widely used to generate file system usage statistics. It can display information about all file systems in the system, including total capacity and available free space. , current installation point, etc.

Users with super-level permissions will find this situation when using the df command: the capacity of a certain partition exceeds 100%. This is because Linux systems reserve 10% of space for the superuser, at their sole disposal. That is to say, for the super user, the hard disk capacity he sees will be 110%. This arrangement is good for system management. When the capacity of the hard disk is close to 100%, the system administrator can still work normally.

5. Application examples

Linux supports many file systems, including JFS, ReiserFS, ext, ext2, ext3, ISO9660, XFS, Minx, vfat, MSDOS, etc. You can also get file system information when using 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

In addition to the capacity and usage of the disk space, you can see the file system type and mount of the partition. Loading points and other information are also available at a glance.

top

1. Function

The top command is used to display the executing program process, and the usage permission is for all users.

2.Format

top [-] [d delay] [q] [c] [S] [s] [n]

3.Main parameters

d: Specify the update interval, measured in seconds.

q: Updates without any delays. If the user has a super user, the top command will be executed with the highest priority.

c: Display the complete path and name of the process.

S: Accumulation mode will accumulate the CPU time of completed or disappeared sub-trips.

s: Safe mode.

i: Do not display any idle or useless trips.

n: Display the number of updates, and top will exit after completion.

4. Description

The top command is a main command for Linux system management, through which you can obtain a lot of information. Here we combine Figure 1 to illustrate the information it gives.

Figure 1 Display of the top command

In

Figure 1, the items represented in the first line are the current time, the system startup time, the current number of system logged-in users, load average. The second line shows all started processes, currently running, suspended

(Sleeping) and useless (Zombie) processes. The third line shows the current CPU usage, including the system occupation ratio, user usage ratio, and idle (Idle) ratio.

The fourth line shows the usage of physical memory, including total usable memory, used memory, free memory, and memory occupied by buffers. The fifth line shows swap partition usage, including total swap partition, used, free and cache size. The sixth row shows the most items and detailed explanations are listed below.

PID (Process ID): process identification number.

USER: The user name of the process owner.

PR: Priority level 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 status of the process, where S means sleeping, R means running, Z means zombie state, and N means the priority value of the process is a negative number.

%CPU: CPU usage occupied by the process.

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

TIME+: The total CPU time occupied by the process after it was started.

Command: The name of the startup command for process startup. If this line cannot be displayed, the process will have a complete command line.

When using the top command, you can also use some interactive commands to complete the functions of other parameters. These commands are launched via shortcut keys.

: Refresh immediately.

P: Sort according to CPU usage.

T: Sort according to time and accumulated time.

q: Exit the top command.

m: Switch display of memory information.

t: Switch to display process and CPU status information.

c: Switch between displaying command name and complete command line.

M: Sort according to the memory size used.

W: Write the current settings into 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, which is especially important 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. The default is to monitor the processes of all users. If you want to check the status of a specified user, press the "U" key in the terminal and enter the user name. The system will switch to the process running interface of the specified user, as shown in Figure 2.

Figure 2 Use the top command to monitor the specified user

free

1. Function

The free command is used to display the memory usage, and the usage permission is all user.

2.Format

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

3 .Main parameters

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

-s delay: Displays the number of seconds to display memory usage.

-t: Display the memory sum column.

-o: Do ​​not display the buffer adjustment column.

4. Application Example

The free command is the main command used to check memory usage. Compared with the top command, its advantage is that it is simple to use and only takes up very few system resources. Through the -S parameter, you can use the free command to continuously monitor how much memory is being used, so that you can use it as a convenient real-time monitor.

#free -b -s5

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

quota

1. Function

quota command is used to display disk usage and restrictions, using superuser permissions.

2.Format

quota [-g][-u][-v][-p] User name group name

3.Parameters

-g: Display the disk usage limit of the user's group.

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

-v: Displays the allocation of file systems that have no allocated space.

-p: Display simplified information.

4. Application examples

Disk quota is very important in enterprise applications, and ordinary users must learn to understand their own disk usage. To query your own disk quotas, you can 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, and the number of files is set to 500~1000 , and the hard disk space limit is set to 200MB~400MB. Once the disk quota is used up, you need to delete some junk files or request an additional quota from the system administrator.

at

1. Function

The at command is used to execute the specified command sequence at the specified time.

2. Format

at [-V] [-q x] [-f file] [-m] time

3. Main parameters

-V: Display standard error output.

-q: Many queue outputs.

-f: Read jobs from files.

-m: Send an email to the user after executing the job.

time: Set the time for job execution. The time format has strict requirements and consists of hours, minutes, date and time offset. The date format is MM.DD.YY, MM is the minute, DD is the date, and YY refers to the year. The format of the offset is time + offset, and the units are minutes, hours and days.

4. Application example

#at -f data 15:30 2 days

The above command means to let the system execute the file specified in the file data at 17:30 two days later Operation.

lp

1. Function

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

2. Format

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

3.Main parameters

-c: Copy the file first and then print.

-d: Print queue file.

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

-number: Number of copies to print.

-title: Print title.

-p: Set the printing priority level, up to 100.

4. Application examples

(1) Use the 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))" means that this is the 11th print command, and the three files are printed in sequence.

(2) Set the printing priority level

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

Specify printing by adding "-p 90" The job's priority is 90. It will print before print jobs with a priority lower than 90, including jobs with no priority set. The default priority is 50

useradd

1. Function

The useradd command is used to establish a user account and create the user's home directory. The user permission is super user.

2.Format

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

3. Main parameters

-c: Add remark text, which is saved in the remark column of passwd.

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

-D: Change the default value.

-e: Specify the validity period of the account. The default means it is permanently valid.

-f: Specify the number of days after the password expires to close the account.

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

-G: Specify additional groups to which the user belongs.

-m: Automatically create the user's login directory.

-M: Do not automatically create the user's login directory.

-n: Cancel the creation of a group named by the user name.

-r: Create a system account.

-s: Specify the shell used by the user after logging in.

-u: Specify the user ID number.

4. Description

useradd can be used to create a user account. It is the same as the adduser command. After the account is created, use passwd to set the password for the account. The account created using the useradd command is actually saved in the /etc/passwd text file.

5. Application example

Create a new user account and set the ID:

#useradd caojh -u 544

It should be noted that, set When setting the ID value, try to be greater than 500 to avoid conflicts. Because some special users will be created after Linux is installed, values ​​between 0 and 499 are generally reserved for system accounts such as bin and mail.

groupadd

1. Function

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

2. Format

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

3. Main parameters

-g gid: Specify the group ID number.

-o: Allow group ID number, not necessarily unique.

-r: Join group ID number, lower than 499 system account number.

-f: When joining an existing group, the development program exits.

4. Application example

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

#groupadd -g 344 cjh

At this time / An item with a group ID (GID) of 344 is generated in the etc/passwd file.

kill

1. Function

The kill command is used to terminate a process.

2. Format

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

kill -l [signal]

3. Parameter

-s: Specify the signal to be sent.

-p: simulate sending signals.

-l: Name list of specified signals.

pid: ID number of the process to be terminated.

Signal: Indicates signal.

4. Description

The process is a very important concept in the Linux system. Linux is a multi-tasking operating system, and multiple processes are often running on the system at the same time. We don't care about 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 includes three different types of processes, each with its own characteristics and attributes. An interactive process is a process started by a Shell. Interactive processes can run in the foreground or in the background.

The batch process has no connection with the terminal and is a sequence of processes. The monitoring process (also called the system daemon) is a process that is started when the Linux system starts and runs in the background. For example, httpd is the monitoring process of the famous

Apache server.

The working principle of the kill command is to send a system operation signal

and the process identification number of a certain program to the kernel of the Linux system, and then the system kernel can kill the process specified by the process identification number. Perform operations. For example, in the top command, we see that the system is running many processes. Sometimes we need to use the

in kill to stop certain processes to increase system resources. When explaining the installation and login commands, it was mentioned that the function of multiple virtual consoles in the system is that when a program error causes a system deadlock, you can switch to other virtual consoles to close the program. The command used at this time is kill, because kill can be called directly by most shell internal commands.

5. Application examples

(1) Forcefully terminate (often used to kill) a process with a process identification number of 324:

#kill -9 324

(2) Release the deadlock of the Linux system

Sometimes such a situation occurs in Linux

: a program crashes and is in a deadlock state. At this time, there is generally no need to restart the computer. You only need to terminate (or close) the problematic program. When

kill is in the X-Window interface, the main programs (except for the crashed program) have generally started normally. Now open a terminal and terminate the offending program there. For example, if

the Mozilla browser program is locked, you can use the kill command to terminate all programs that include the Mozolla browser. First use the top command to check the PID of the program, and then

use the kill command to stop the program:

#kill -SIGKILL XXX

Among them, XXX contains the Mozolla browser The process identification number of the server's program.

(3) Use command to recycle memory

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

#kill -9 XXX

where XXX is the useless process identification number.

Then use the following command:

#free

You will find that the available memory capacity has increased.

(4) killall command

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

# killall -HUP inetd

crontab

1. Function

The crontab configuration file can be modified using the crontab command, and then the configuration is executed by the cron utility at the appropriate time. The permissions for this command are All users.

2. Format

crontab [-u user] file

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

3. Main parameters

-e: Execute a text editor to set the schedule. The default text editor is vi.

-r: Delete the current schedule.

-l: List the current schedule.

crontab

The format of the file is "M H D m d

cmd". Among them, M represents the minute (0 to 59), H represents the hour (0 to 23), D represents the day (1 to 31), m represents the month (1 to 12), and d represents the day of the week (0 to 6, 0 is the

day of the week). cmd represents the program to be run, which is sent to sh for execution. This Shell only has three environment variables: USER, HOME, and SHELL.

4. Description

Compared with the at command, the crontab command is suitable for completing fixed-cycle tasks.

5. Application example

Set a scheduled and periodic system prompt:

[cao @www cao]#crontab -e

At this time the system will Open a vi editor.

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

# 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 "

So every Friday at 17:35 the system will pop up a terminal to remind you that you can play CS on Saturday ! The displayed results are shown in Figure 3.

Figure 3 A scheduled and regular system prompt

Hands-on exercise

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

Start first Run the top command on one terminal, and then start another terminal and use the kill command, as shown in Figure 4.

Figure 4 Observe the impact of the kill command on the top terminal

At this time, use the kill command introduced above to terminate some programs:

#kill SIGKILL XXX

Then look at the changes in the top command terminal, including memory capacity, CPU usage, system load, etc. Note that some processes cannot be terminated, but you can try it when learning Linux commands to see how the system reacts.

2. Use the at and halt commands to schedule shutdown

First set the shutdown time to 17:35, 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-01-01 17:35

At this time, you have actually entered the Linux system Shell and written the simplest program: halt -i

-p. The end of text symbol in the Shell above means pressing the "Ctrl+D" key combination to close the command and submit the task to exit the Shell. "Job 6 at 2004-01-01

17:35" means that the system accepts the 6th at command and executes the command at "2004-01-01 17:35": first, all network-related devices Stop, shut down the system and then turn off the power.

3. Use the crontab command to implement daily scheduled virus scanning

A simple crontab command operation has been introduced before. Here are some more important operations.

(1) Create a file and set the file name yourself, assuming it is caoproject:

#crontab -e

(2) The file content is as follows:

05 09 * * * antivir

Use vi to edit, save and exit. Antivir is a software that detects and kills Linux viruses. Of course, it should be installed in the system first if necessary.

(3) Use the crontab command to add it to the task list:

#crontab caoproject

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

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

Windows users generally know that after modifying important configuration files, they often have to restart the computer for the modification to take effect. Because Linux adopts a modular design, you can set up services in real time according to your needs. Here we take the network service inetd as an example to introduce some operating techniques.

inetd

is a listening daemon process that monitors and provides Internet service processes (such as rlogin, telnet, ftp, rsh) for connection requirements, and expands the required service processes. By default, the daemons monitored by

inetd are listed in the /etc

/inetd.conf file. Edit the /etc/inetd.conf file to change the options 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 other editor, first use the following command:

#ps -ef |grep inetd

The above code indicates the query of inetd.conf Process ID (PID), assuming it is 1426, then use the following command:

# kill -1426 inetd

The configuration file will take effect.

The system management commands introduced in this lecture are all relatively important, especially the crontab command and quota command, which are difficult to use and require more practice. In addition, when using the kill command, pay attention to the "-9" parameter. It is best not to run some important programs during practice.

60 commands you must learn in Linux (4) - Network operation commands 60 commands you must learn in Linux: network operation commands

Because the Linux system is on the Internet Originating and developing on the Internet, it inherently has powerful network functions and rich network application software, especially the implementation of TCP/IP network protocol is particularly mature.

Linux has many network commands, some of which like ping,

ftp, telnet, route, netstat, etc. can also be seen on other operating systems, but there are also some Unix/Linux systems Unique commands, such as ifconfig,

finger, mail, etc. One characteristic of Linux network operation commands is that there are many command parameter options and functions. One command can often also realize the functions of other commands.

ifconfig

1. Function

ifconfig is used to view and change the address and parameters of the network interface, including IP address, network mask, and broadcast address. The usage permission is super user.

2. Format

ifconfig -interface [options] address

3. Main parameters

-interface: The specified network interface name, such as eth0 and eth1.

up: Activate the specified network interface card.

down: Close the specified network interface.

broadcast address: Set the broadcast address of the interface.

pointopoint: Enable point-to-point mode.

address: Set the IP address of the specified interface device.

netmask address: Set the subnet mask of the interface.

4. Application instructions

ifconfig is a command line tool used to set up and configure the network card. This is a command that must be mastered in order to configure the network manually. The advantage of using this command is that there is no need to restart the machine. To assign the eth0 interface the 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

The

command is used to set the IP address, network mask and local broadcast address of the network card eth0. If you run the ifconfig command without any parameters, this command will display

information for all activated interfaces on the machine. The command with the "-a" parameter displays information about all interfaces, including inactive interfaces. 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 certain network interface, you can use the down parameter:

#ifconfig eth0 down

ip

1. Function

ip is a powerful network configuration tool in the iproute2 software package. It can replace some traditional network management tools, such as ifconfig, route, etc., and its usage rights are super users. Almost all Linux distributions support this command.

2. Format

ip [OPTIONS] OBJECT [COMMAND [ARGUMENTS]]

3. Main parameters

OPTIONS is to modify the ip behavior or change its Output options. 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 from which the manager needs to obtain information. The objects currently recognized by IP are shown in Table 2.

Table 1 Options supported by ip

-V,-Version Print the version of ip and exit.

-s,-stats,-statistics output more detailed information. If this option appears two or more times, the output will be more detailed.

-f,-family This option is followed by the protocol type, including inet, inet6 or link, emphasizing the protocol type used. If there is not enough information to tell the IP what kind of protocol to use, IP will use the default value inet or any. Link is special, it means that no network protocol is involved.

-4 is the abbreviation of -family inet.

-6 is the abbreviation of -family inet6.

-0 is the abbreviation of -family link.

-o,-oneline Use a single line of output for each line of records, and replace the new line with characters. If you need to use tools such as wc and grep to process the output of IP, this option will be used.

-r,-resolve Query the domain name resolution system and replace the host IP address with the obtained host name

COMMAND

Set the operation to be performed on the specified object. It is related to the object's Type related. In general, IP supports the addition (add), deletion (delete) and display (show or list) of objects. Some

objects do not support these operations, or have other commands. For all objects, users can use the help command to get help. This command will list the commands and parameter syntax supported by this object. If there is no operation command for the specified object, ip will use the default command. Generally, the default command is list. If the object cannot be listed, the help command will be executed.

ARGUMENTS

are some parameters of the command, which depend on the object and command. IP supports two types of parameters: flag and parameter. The flag consists of a keyword; the parameter consists of a

keyword plus 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 is equal to ip link ls dev eth0. We will introduce the use of each command in detail later, and the default parameters of the command will be marked with default.

4. Application example

Add IP address 192.168.2.2/24 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.0/24 network:

#ip rule add from 192.168.2.0/24 prio 32777 reject

ping

1 .Function

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

2. Format

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

3. Main parameters

-d: Use the SO_DEBUG function of Socket.

-c: Set the number of times to complete the request response.

-f: limit detection.

-i: Specify the number of seconds between sending and receiving information.

-I: The network interface uses the specified network interface to send data packets.

-l: Preload, set the data packet to be sent before sending the request information.

-n: Only output numerical values.

-p: Set the template style for filling packets.

-q: Do not display the instruction execution process, except related information at the beginning and end.

-r: Ignore the ordinary Routing Table and send the data packet directly to the remote host.

-R: Record the routing process.

-s: Set the packet size.

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

-v: Display the execution process of the instruction in detail. The

ping

command is the most commonly used network command. Usually we use it to detect whether the network is connected. It uses the ICMP protocol. But sometimes there is a situation where we can view a web page in the browser, but cannot

ping. This is because some websites have installed firewalls for security reasons. In addition, you can also try it on your own computer and use the following method to prevent the system from responding to ping:

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

netstat

1. Function

Check the entire Linux network status.

2. Format

netstat [-acCeFghilMnNoprstuvVwx][-A][--ip]

3.Main parameters

-a--all : Display all connected Sockets.

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

-c--continuous: Continuously list network status.

-C--cache: Display cache information of router configuration.

-e--extend: Display other network-related information.

-F--fib: Display FIB.

-g--groups: Display the list of multicast function group members.

-h--help: Online help.

-i--interfaces: Display the network interface information form.

-l--listening: Display the Socket of the server being monitored.

-M--masquerade: Display masquerade network connections.

-n--numeric: Use the IP address directly without going through the domain name server.

-N--netlink--symbolic: Displays the symbolic link name of the network hardware peripheral device.

-o--timers: Display timers.

-p--programs: Displays the program identification code and program name that are using Socket.

-r--route: Display Routing Table.

-s--statistice: Display network work information statistics table.

-t--tcp: Display the connection status of TCP transmission protocol.

-u--udp: Display the connection status of UDP transmission protocol.

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

-V--version: Display version information.

-w--raw: Display the connection status of RAW transmission protocol.

-x--unix: Same as specifying the "-A unix" parameter.

--ip--inet: Same as specifying the "-A inet" parameter.

4. Application examples

netstat

is mainly used for Linux to check its own network status, such as open ports, which users it is serving, and the status of the service. Additionally, it displays system routing tables, network interface status, and more. It can be said that it is a comprehensive network status viewing tool. By default, netstat only displays ports for which connections have been established. 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 0 0 *:10000 *:* LISTEN

tcp 0 0 *:http *:* LISTEN

......

The above shows that this host also provides HTTP, FTP, NFS, MySQL and other services.

telnet

1. Function

telnet means to start the terminal phase operation and log in to the remote host. Telnet is a Linux command and a protocol (Remote Login Protocol).

2. 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 automatically log in to the remote system.

-b: Use an alias to specify the remote host name.

-c: Do not read the .telnetrc file in the user-specific directory.

-d: Start debugging mode.

-e: Set the escape character.

-E: Filter out escaped characters.

-f: The effect of this parameter is the same as specifying the "-F" parameter.

-F: When using Kerberos V5 authentication, adding this parameter can upload the authentication data of the local host to the remote host.

-k: When using Kerberos authentication, add this parameter to let the remote host use the specified realm name instead of the domain name of the host.

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

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

-L: Allows output of 8-bit character data.

-n: Specify the file to record related information.

-r: Use a user interface similar to the rlogin command.

-S: Service type, set the IP TOS information required for telnet connection.

-x: If the host has the function to support data encryption, use it.

-X: Close the specified authentication mode.

4. Application instructions

Users

use the telnet command to log in remotely and communicate between remote computers. Users log in on a remote computer over the network just as they log in to the local machine to execute commands. In order to log in to a remote computer through

telnet, you must know the legal username and password on the remote computer. Although some systems do provide login functions for remote users, due to security considerations, the guest's operation

permissions must be restricted, so there are very few functions that can be used in this case.

telnet only provides terminal emulation for ordinary terminals and does not support graphical environments such as X-

Window. When allowing remote users to log in, the system usually places these users in a restricted shell to prevent the system from being damaged by malicious or careless users. Users can also

use telnet to log in to their computer from a remote site and check email, edit files, and run programs just as if they were logged in locally.

ftp

1. Use the

ftp command to perform remote file transfer. FTP is the standard file transfer protocol of ARPANet. This network is the predecessor of today's Internet, so ftp is both a protocol and a command.

2. Format

ftp [-digv][host name IP address]

3.Main parameters

-d: Display the command execution process in detail , which facilitates troubleshooting and analysis of program execution.

-i: Turn off interactive mode and don’t ask any questions.

-g: Turn off the extended feature of supporting special characters in local host file names.

-n: Do not use automatic login.

-v: Display the instruction execution process.

4. Application instructions

ftp

The command is the user interface of the standard file transfer protocol. It is a simple and effective method to transfer files between computers on the TCP/IP network. It allows users to transfer ASCII files and binary files. In order to use ftp

to transfer files, the user must know the valid username and password on the remote computer. This username/password combination is used to authenticate the ftp session and to determine what access the user has to the files being transferred.

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

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

ls: List the current directory of the remote machine.

cd: Change the working directory on the remote machine.

lcd: Change the working directory on the local machine.

close: Terminate the current ftp session.

hash: A # sign is displayed each time the data in the data buffer is transmitted.

get(mget): Transfer the specified file from the remote machine to the local machine.

put (mput): Transfer the specified file from the local machine to the remote machine.

quit: Disconnect from the remote machine and exit ftp.

route

1. Function

route means manually generating, modifying and viewing the routing table.

2.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 routing.

-delete: Delete the route.

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

-host: The route reaches a host.

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

gw: The gateway of the specified route.

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

4. Application Example

The route command is used to view and set the routing information of the Linux system to achieve communication with other networks. To achieve communication between two different subnets, you need a router that connects the two networks, or a gateway that is located on both networks at the same time.

In Linux systems, routing is usually set up to solve the following problems: The Linux system is in a LAN, and there is a gateway in the LAN that allows the machine to access the Internet. Then you need to set the IP address of this machine to Linux The machine's default route. Use the following command to add a default route:

route add 0.0.0.0 192.168.1.1

rlogin

1. Function

rlogin is used for remote register.

2. 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 sending formatted ANSI characters and other special codes. If this option is not used, the parity bit is removed unless the remote characters are not stop and start characters.

-E: Stop treating any character as an escape character. When used with the -8 option, it provides a completely transparent connection.

-K: Turn off all Kerberos confirmations. Use this option only when connecting to a host using the Kerberos acknowledgment protocol.

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

-d: Turn on socket debugging for TCP sockets communicating with the remote host. For more information, consult setsockopt's online help.

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

-k: Requests rlogin to obtain Kerberos permissions for the remote host in the specified zone instead of the remote host zone determined by krb_realmofhost(3).

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

4. Instructions for use

If you have accounts on different systems in the network, or you can access someone else’s account on another system, then you need to access the account in the other system, First, you need to register into the system, and then remotely register through the network into the system where the account is located. rlogin can be remotely registered to other systems, and its parameter should be a system name.

rcp

1. Function

rcp represents remote file copy, which is used to copy files between computers. The usage permission is for all users.

2. Format

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

3. Main parameters

-r: Recursively copy all contents in the source directory to the destination directory. To use this option, the destination must be a directory.

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

-k: Requests rcp to obtain Kerberos permissions for remote hosts in the specified zone instead of obtaining Kerberos permissions for remote hosts in the remote host zone determined by krb_relmofhost(3).

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

finger

1. Function

finger is used to query the login account information on a host. It usually displays the user name, home directory, dead time, and login time. , login shell and other information, the usage rights are for all users.

2. Format

finger [Option] [User] [User@Host]

3. Main parameters

-s: Display user registration Name, actual name, terminal name, writing status, dead time, login time and other information.

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

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

4. Application example

Use finger on the 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 instructions

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 you want to query needs to run finger daemon support.

mail

1. Function

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

2.Format

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

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

3. Main parameters

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

-c address: Represents the list of CC () recipient addresses of the output message.

-f [mailbox]: Read emails from the mailbox specified by the recipient.

-s subject: Specifies the subject line of the output information.

[-u user]: The port specifies the optimized inbox for reading emails.

nslookup

1. Function

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 names corresponding to the IP addresses of different hosts.

2. 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 IP address domain name to be queried after the symbol ">" and press Enter. If you want to exit this command, enter "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 will display the address and domain name of the current DNS server. Otherwise, named fails to start normally.

The following is a brief introduction to some basic DNS diagnosis.

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

if you only enter hp712, nslookup will automatically add the my.com domain name according to the definition of /etc/resolv.conf and answer the corresponding IP address.

◆Check the reverse DNS resolution and enter an IP address at the nslookup prompt, such as 192.22.33.20. nslookup should be able to answer the host name corresponding to the IP address.

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

set q=mx

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

Hands-on exercises

1. Dangerous network commands

Internet

The development of the Internet has made security an issue that cannot be ignored, finger, ftp, rcp and telnet are inherently unsafe because they transmit passwords and data in clear text on the network, and sniffers can easily intercept these passwords and data. Moreover, the security verification methods of these service programs also have weaknesses and are easily vulnerable to "intermediate server" attacks. Here, the author lists some unsafe commands according to the risk level, as shown in Table 3.

Now ftp and telnet can be bound to port 22 by SSH commands instead. The connection

adopts negotiation mode and uses RSA encryption. After identity authentication is completed, all subsequent traffic is encrypted using IDEA

. The SSH (Secure Shell) program can log in to a remote host through the network and execute commands. Remote calling commands such as rcp and rlogin are gradually being replaced by VNC software.

2. Bind multiple IP addresses to one network card

Under Linux, you can use ifconfig to easily bind multiple IP addresses to one network card. For example, if 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 network card MAC address

First you must turn off the network card device, the command is as follows:

/sbin/ifconfig eth0 down

Modify the MAC address, the command is as follows:

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

Restart Enable the network card:

/sbin/ifconfig eht0 up

The MAC address of the network card is changed. The MAC address of each network card is unique, but it cannot be modified. Just ensure the uniqueness of the MAC address in the network.

4. Initial deployment of IPv6

IPv4

technology has played a huge role in the development of the network, but as time goes by, it no longer affects the provision of network addresses and services. Quality, security and other aspects are becoming increasingly inadequate, and IPv6 is about to emerge. Linux

is the first among all operating systems to support IPv6. Generally, Linux distributions based on the 2.4 kernel can use IPv6 directly. However, major distributions do not load the IPv6 module

. Manual loading using commands requires superuser privileges.

(1) Load the IPv6 module

Use the command to detect, in which inet6 addr: fe80::5054:abff:fe34:5b09/64 is the IPv6 address of the eth0 network card.

# 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.0 b) TX bytes:1360 (1.3 Kb)

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

is different from IPv4, use the ping6 command A network card interface must be specified, otherwise the system does not know which network device to send the packet to. I means Interface, eth0 is the first network card, -c means loop, 2 means ping6 is operated twice. The results are shown in Figure 1.

Figure 1 ping6 command under 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 check whether 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 network conditions, log in to remote computers, transfer files, and execute remote commands.

The above introduces the more important network commands in Linux. In fact, there are many commands in Linux that need to be learned. One feature of Linux network operation commands is that there are many command parameter options, and it is not required to remember them all. The key is to understand the main purpose of the command and learn to use the help information.

60 commands you must learn in Linux (5)-Network security commands 60 commands you must learn in Linux: system security related commands

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

passwd

1. Function

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

2. Format

passwd [Option] Account name

3. Main parameters

-l: Lock the named account name, only with super Only users with user rights can use it.

-u: Unlock the account and only users with super user rights can use it.

-x, --maximum=DAYS: Maximum password usage time (days), only users with super user rights can use it.

-n, --minimum=DAYS: Minimum password usage time (days), only users with super user rights can use it.

-d: Delete the user's password. Only users with super user rights can use it.

-S: Check the password authentication type of the specified user. Only users with super user rights 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 the above, use The passwd command requires entering the old password and then entering the new password twice.

su

1. Function

The function of su is to change the identity of other users, except the super user, who needs to enter the password of the user.

2. Format

su [Option]... [-] [USER [ARG]...]

3. Main parameters

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

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

-m, -p, --preserve-environment: Do not change environment variables when executing su.

-c command: Change the account to USER, execute the command (command) and then change back to the original user.

USER: The user account to be changed, ARG passes in the new Shell parameters.

4. Application example

Change the account to super user and restore the user after executing the df command. su -c df root

umask

1. Function

umask sets the default shielding value for file creation of user files and directories. If you put this command into the profile file, You can control the access permissions of subsequent files created by this user. It tells the system who to deny access to when creating a file. Access rights are for all users.

2. Format

umask [-p] [-S] [mode]

3. Parameter

-S: Determine the current umask setting .

-p: Modify umask settings.

[mode]: Modify the value.

4. Description

Traditionally

The umask value of traditional Unix is ​​022, which prevents other users who belong to the same group and users of other groups from modifying the user document. Since each user owns and belongs to his own private group, this "group protection mode" is no longer needed. Strict permission settings form the basis of Linux security, and making mistakes in permissions is fatal. It should be noted that the umask command is used to set the read and write permissions of files created by the process. The safest value is 0077, which means that the read and write permissions of all processes except the process that created the file are closed, which means for -rw-------. In

~/.bash_profile, adding a line of command umask 0077 can ensure that the umask permissions of the process can be correctly set every time the Shell is started.

5. Application example

umask -S

u=rwx,g=rx,o=rx

umask -p 177

umask -S

u=rw,g=,o=

The above 5-line command first displays the current status, and then changes the umask value to 177. As a result, only the file owner has Permission to read and write the file, other users cannot access the file. This is obviously a very secure setup.

chgrp

1. Function

chgrp means to modify the group to which one or more files or directories belong. Access rights are superuser.

2. 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 only displays results when there are changes.

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

-h, --no-dereference: Will affect the symbolic link itself, rather than the destination indicated by the symbolic link (this option is only effective when the system supports changing the owner of the symbolic link).

-f, --silent, --quiet: Remove most error messages.

--reference=Reference file: Use the owning group instead of the specified one.

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

-v, --verbose: Display information when processing any file.

4. Application instructions

This command changes the user group to which the specified file belongs. The 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 space-separated list of files whose groups are to be changed, and wildcards are supported. If the user is not the owner or superuser of the file, the group of the file cannot be changed.

5. Application example

Change the ownership group of all files in /opt/local /book/ and its subdirectories to book. The command is as follows:

$ chgrp - R book /opt/local /book

chmod

1. Function

chmod command is very important. It is used to change the access permissions of files or directories. Users can use It controls access permissions to files or directories, and the usage permissions are superuser.

2. Format

The chmod command has two uses. One is a character setting method that includes letters and operator expressions (relative permission setting); the other is a numeric setting method that includes numbers (absolute permission setting).

(1) Character setting method

chmod [who] [ | - | =] [mode] File name

◆The operation object who can be one of the following letters Any one or their combination

u: Indicates the user, that is, the owner of the file or directory.

g: Indicates users in the same group, that is, all users with the same group ID as the file owner.

o: Indicates other users.

a: Indicates all users, it is the system default value.

◆Operation symbol

: Add a certain permission.

-: Cancel a certain permission.

=: Grants the given permission, and removes all other permissions (if any).

◆The permission to set mode can be any combination of the following letters

r: readable.

w: Writable.

x: Executable.

X: Append the x attribute only when the target file is executable for some users or the target file is a directory.

s: When the file is executed, the owner or group ID of the process is set to the file owner of the file. The mode "u+s" sets the user ID bit of the file, and "g+s" sets the group ID bit.

t: Save the text of the program to the exchange device.

u: Has the same permissions as the file owner.

g: Has the same permissions as users in the same group as the file owner.

o: Has the same permissions as other users.

File name: A space-separated list of files whose permissions are to be changed, wildcards are supported.

Multiple permission methods can be given in one command line, separated by commas.

(2) Number setting method

The general form of the number setting method is: chmod [mode] File name

The format of the number attribute should be 3 0 to The octal number of 7, the order is (u) (g) (o) file name, a space-separated list of files whose permissions are to be changed, and wildcards are supported.

The meaning of the permissions represented by the numbers

is as follows: 0001 is the execution permission of the owner; 0002 is the write permission of the owner; 0004 is the read permission of the owner; 0010 is the execution permission of the group Permissions; 0020 is the write permission of the group; 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 means false

If this file is an executable file, the group ID is the position, otherwise the file lock bit is set; 4000 means if the file is an executable file, the user ID is the position Bit.

3. Example

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

In the code above

, how is the number 666 calculated? 0002 is the write permission of the owner, 0004 is the read permission of the owner, 0020 is the write permission of the group, 0040 is the read permission of the group,

0200 is the write permission of others, 0400 is the read permission of others Permissions, the sum of these 6 numbers is 666 (note that the above numbers are all octal numbers), the result is shown in Figure 1.

Figure 1 Use the chmod digital method to set file permissions

As can be seen from Figure 1, the permissions of the tem file are -rw-rw-rw-, that is, the user has read and write access to this file permissions.

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

#chmod a =wx tem

chown

1. Function

Change the owner and group of one or more files or directories. Access rights are superuser.

2. Format

chown [options] User or group file

3. Main parameters

--dereference: Affected are the symbolic links The object pointed to, not the symbolic link itself.

-h, --no-dereference: Will affect the symbolic link itself, rather than the destination indicated by the symbolic link (this option is only effective when the system supports changing the owner of the symbolic link).

--from=Current Owner:Current Group The owner and group will only be changed if the owner and group of each file match those specified by the options. One of them can be omitted, and the omitted attribute does not need to match the original attribute.

-f, --silent, --quiet: Remove most error messages.

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

-v, --verbose: Display information when processing any file.

4. Description

chown Change the owner of the specified file to the specified user or group. The user can be the user name or user ID; the group can be the group name or group ID; the file is a space-separated list of files whose permissions need to be changed. Support Wildcard. System administrators often use the chown command to give the user permission to use the file after copying it to another user's directory.

5. Application example

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

$ chown wan shiyan.c

2. Change the directory The owner of /hi and all files and subdirectories under it is changed to wan, and the group owner is changed to users.

$ chown - R wan.users /hi

chattr

1. Function

Modify ext2 and ext3 file system attributes (attributes), use permissions root.

2. Format

chattr [-RV] [- =AacDdijsSu] [-v version] File or directory

3. Main parameters

- R: Process all files and subdirectories recursively.

-V: Display the modified content in detail and print the output.

-:Invalid attribute.

+: Activate attributes.

=: Specify attributes.

A: Atime, tells the system not to modify the last access time of this file.

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

a: Append Only, the system only allows appending data after this file, and does not allow any process to overwrite or truncate this file. If a directory has this attribute, the system will only allow files to be created and modified in this directory, but will not allow any files to be deleted.

i: Immutable, the system does not allow any modification 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 or delete files.

D: Check compressed files for errors.

d: No dump, the dump program will ignore this file when performing file system backup.

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

s: Secure Delete, allowing the system to fill the area where the file is located with 0s when deleting the file.

u: Undelete, when an application requests to delete this file, the system will retain its data blocks so that the file can be restored and deleted later.

4. Description

chattr

command is very useful. Some of the functions are supported by the Linux kernel version. If the Linux kernel version is lower than 2.2, then many Function cannot be implemented. Similarly, the function of -D to check the error

in the compressed file requires kernel 2.5.19 or above to support it. In addition, modifying attributes through the chattr command can improve system security, but it is not suitable for all directories. The chattr command cannot

protect the /, /dev, /tmp, and /var directories.

5. Application example

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

# chattr -R u/root

2. 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 by anyone. In order to prevent them from being accidentally deleted or modified, you can set this The "immutable bit" of the file, the command is as follows:

# chattr i /etc/fstab

sudo

1. Function

sudo It is a command that is based on restricting the commands in the configuration file, is used by users within a limited time, and is recorded in the log. The permissions are for all users.

2. Format

sudo [-bhHpV] [-s ] [-u ] [Command]

sudo [-klv]

3. Main parameters

-b: Execute the command in the background.

-h: Display help.

-H: Set the HOME environment variable to the HOME environment variable of the new identity.

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

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

-p: Change the prompt symbol for asking for password.

-s: Execute the specified Shell.

-u: Use the specified user as the new identity. If not used, it defaults to root.

-v: Extend the password validity period by 5 minutes.

4. Description

sudo

command configuration is in the /etc/sudoers file. When users use sudo, they need to enter a password to authenticate the user's identity. The defined commands can be used in a subsequent period of time. When a command not included in the configuration

file is used, an alarm will be recorded. sudo is a program used by system administrators to allow certain users to run some/all system commands as root. An obvious use is to enhance the security of the site

. If you need to do some daily work as a super user every day and often execute a few fixed commands that can only be executed as a super user, then use sudo is very suitable.

ps

1. Function

ps displays the dynamics of the instant process (process), and the usage rights are for all users.

2. Format

ps [options] [--help]

3. Main parameters

ps has many parameters, only listed here Here are some commonly used parameters.

-A: List all processes.

-l: Display long list.

-m: Display memory information.

-w: Display widening can display more information.

-e: Display all processes.

a: Display all processes on the terminal, including processes of other users.

-au: Display more detailed information.

-aux: Display all processes containing other users.

4. Description

To

monitor and control the process, you must first understand the situation of the current process, that is, you need to view the current process. The ps command is the most basic and very powerful process viewing command. Use this command to determine which

processes are running, their running status, whether the process has ended, whether there are zombies in the process, which processes occupy too many resources, etc. Figure 2 gives a detailed explanation of the ps-aux command. Most of the information can be obtained by executing this command. The three most commonly used parameters are u, a, and x. The following is a detailed description of the role of the ps command based on 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 occupied CPU usage; %MEM represents the physical memory usage occupied; VSZ represents the occupied virtual memory size; RSS is the physical memory value occupied by the process; TTY is the secondary device number of the terminal.

STAT

represents the status of the process, where D is uninterruptible static (I/O action); R is executing; S static state; T suspends execution; Z does not exist, but It cannot be eliminated temporarily; W There are not enough memory pages to allocate

; High-priority processes; N Low-priority processes; L There are memory pages allocated and locked in the memory body (real-time system or

I/O). START is the process start time. TIME is the execution time. COMMAND is the instruction executed.

4. Application examples

When performing system maintenance, it often happens that the memory usage is astonishing, and it is not known which process occupies 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. Function

who displays which users in the system have logged in to the system. The displayed information includes user ID, login terminal used, online time, idle time, CPU usage, and what was done. Access rights are for all users.

2. Format

who - [husfV] [user]

3. Main parameters

-h: Do not display the title column.

-u: Do not show the user's actions/work.

-s: Use short format for display.

-f: Do not display the user's online location.

-V: Display program version.

4. Description

This

command is mainly used to view the current online users. If a user wants to establish instant communication with other users, such as using the talk command, the first thing to make sure is that the user is indeed online, otherwise the

talk process cannot be established. For another example, if the system administrator wants to monitor what each logged-in user is doing at this moment, he or she should also use the who command. The who command is very simple to apply and can accurately grasp the user's situation, so it is very widely used.

Hands-on exercises

1. Use Linux commands to detect system intruders

Have installed Mandrake Linux and Red Hat

Linux All users will know that the Linux system will have three different levels of built-in firewalls (standard, high, and higher). After installing the Linux server and making some basic settings, the server should be relatively It is safe, but there will also be hackers using various methods to invade the system by taking advantage of the system administrator's negligence. How to quickly find hackers is very important. Generally speaking, you can use commands to check whether hackers have invaded, see Table

1.

Table 1 Command correspondence table for querying hacker intrusion phenomena

For example, if a hacker sniffs the network, then it must put the network card interface in promiscuous mode. Use the following command to query:

#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 the output of this command, you can see to the concepts mentioned above. 00:00:E8:A0:25:86 in the first line is the mac address, 192.168.1.7 in the second line is the IP address,

The fourth line talks about the receiving data status, which is being processed at this time Hacker sniffing. Generally speaking, the network card has several states for receiving data frames, such as Broadcast, Multicast,

Promiscuous, etc. Broadcast refers to receiving all types of data frames that are broadcast messages; Multicast refers to receiving specific multicast messages; Promiscuous

is commonly referred to as the promiscuous mode, which refers to the destination hardware address in the message. The working mode of receiving everything without any checking.

2. Limit the abuse of su command

We

know that the super user has the greatest rights in Linux, and almost all hackers want to get this goal. Linux can increase restrictions on switching to superuser. Use PAM

(Pluggable Authentication

Modules) to prevent anyone except the wheel group from becoming root, modify the /etc/pam.d/su file, and remove the shielding flag #. Use

/usr/sbin/usermod G10 bjecadm to add the bjecadm account to the group with gid 10, which is the wheel group. The command is as follows:

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

#auth sufficient /lib/security/pam_wheel.so debug

# Limit only the wheel group Users can switch to root

#auth required /lib/security/pam_wheel.so use_uid

chmod -G10 bjecadm

In addition, whenever a user attempts to use the su command to enter the system user, the command will write a message in the /usr/adm/sulog file. If the file records a large number of invalid operation information trying to use su to enter root, it means Someone may be trying to decipher the root password.

Linux commands have powerful functions. For Linux system administrators, they often only need to combine various security command techniques to form a security line of defense. From the perspective of computer security, there is no absolutely safe computer system in the world, and Linux systems are no exception.

60 commands you must learn in Linux (6)-Other commands

60 commands you must learn in Linux: other commands

In the previous lectures, we put Linux The commands are divided into several parts and introduced separately according to their functions in the system. However, there are still some commands that are difficult to classify, but it is also important to learn them.

tar

1. Function

The tar command is a reliable method for backing up files in Unix/Linux systems. It can work in almost any environment. Its usage permissions are all user.

2. Format

tar [Main option and secondary option] File or directory

3.Main parameter

When using this command, the main option is required Yes, it tells tar what to do. The auxiliary options are auxiliary and can be selected.

Main options:

-c Create a new archive file. If the user wants to back up a directory or some files, he or she must select this option.

-r Append the file to be archived to the end of the archive file. For example, the user has made a backup file and finds that there is another directory or some files that he has forgotten to back up. In this case, you can use this option to append the forgotten directory or files to the backup file.

-t List the contents of archive files and see which files have been backed up.

-u Update file. That is to say, the original backup file is replaced with the new file. If the file to be updated cannot be found in the backup file, it is appended to the end of the backup file.

-x Release the file from the archive.

Auxiliary options:

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

-f When using an archive file or device, this option is usually required.

-k Save existing files. For example, if you restore a certain file and encounter the same file during the restore process, it will not be overwritten.

-m When restoring files, set the modification time of all files to the present.

-M Creates a multi-volume archive for storage on several disks.

-v Detailed reporting of file information processed by tar. Without this option, tar does not report file information.

-w Ask for confirmation at every step.

-z Use gzip to compress/decompress files. Adding this option can compress archive files, but you must also use this option to decompress when restoring.

4. Application Description

tar is the abbreviation of Tape Archive (tape archive), originally designed for packaging files onto tapes. If you have downloaded the source code of Linux, you may have encountered the tar file

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

5. Application examples

tar is a command line tool without a graphical interface. Use Konsole to open a terminal window, followed by a simple backup command (create a back.tar file in the /temp directory, with all the contents of the /usr directory included.):

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

In addition, the tar command supports the crontab command mentioned in the previous lecture 3, which can be set to time-based using the crontab tool Run regularly. For example, to back up the /usr directory to

hda - the main drive of the first IDE interface (always located on the first hard disk) at 6 o'clock every night, just add the following statement to the root's crontab. Available:

$00 06 * * * tar cvf /dev/hda1/usrfiles.tar - /usr

Generally, the following directories need to be backed up:

◆/etc contains all 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 file, HTTP server file, dB2 instance configuration, etc.

◆/home Contains the home directory of all default users, including personal settings, downloaded files, and other information that the user does not want to lose.

◆/root The home directory of the root user.

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

Some directories do not need to be backed up:

◆/proc This directory should never be backed up. 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 just a waste of resources.

◆/dev Contains file representations of hardware devices. 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 backing up /dev is not necessary.

unzip

1. Function

unzip

The commands are located in the /usr/bin directory. They are the same as pkzip, pkunzip and MS# under MS DOS.

##The Winzip software in Windows has the same function. It compresses files into .zip files to save hard disk space. When needed, use the unzip command to unzip the compressed files. The usage rights of this command are limited to all users.

2.Format

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

3. Main parameters

-c: Display the decompression result on the screen and perform appropriate conversion of characters.

-f: Update existing files.

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

-p: Similar to the -c parameter, the decompression result will be displayed on the screen, but no conversion will be 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 will also be decompressed into the directory.

-v: Display detailed information when executing.

-z: Only display the comment text of the compressed file.

-a: Perform necessary character conversion on the text file.

-b: Do not perform character conversion on text files.

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

-j: Do not process the original directory path in the compressed file.

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

-M: Send the output results to the more program for processing.

-n: Do not overwrite the original file when decompressing.

-o: No need to ask the user first, the original file will be overwritten after unzip is executed.

-P: Use zip's password option.

-q: No information is displayed during execution.

-s: Convert whitespace characters in file names to underscore characters.

-V: Keep VMS file version information.

-X: Save the original UID/GID of the file at the same time when decompressing.

[.zip file]: Specify the .zip compressed file.

[File]: Specify which files in the .zip compressed file to process.

-d: Specify the directory where the file will be stored after decompression.

-x: Specify which files in the .zip compressed file are not to be processed.

-Z unzip: -Z is equivalent to executing the zipinfo command. In Linux, a tool called zipinfo is also provided, which can view detailed information of zip compressed files. The latest version of unzip is 5.50.

gunzip

1. Function

The gunzip command is used to decompress files, and the usage permissions are for all users.

2.Format

gunzip [-acfhlLnNqrtvV][-s ][File...]

or

gunzip [-acfhlLnNqrtvV][- s ][Directory]

3. Main parameters

-a or --ascii: Use ASCII text mode.

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

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

-h or --help: online help.

-l or --list: List information about compressed files.

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

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

-N or --name: When decompressing, if the compressed file contains the original file name and timestamp, it will be saved back to the decompressed file.

-q or --quiet: Do not display warning messages.

-r or --recursive: Recursive processing, processing all files and subdirectories in the specified directory together.

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

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

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

-V or --version: Display version information.

4. Description

gunzip is a widely used decompression program. It is used to decompress files compressed by gzip. The default extension of these compressed files is ".gz". . In fact, gunzip is a hard connection to gzip, so whether it is compression or decompression, it can be completed through the gzip command alone. The latest version of gunzip is 1.3.3.

unarj

1. Function

unarj decompresses files in .arj format, and the usage permissions are for all users.

2. Format

unarj [eltx][.arj compressed file]

3. Main parameters

e: Decompress the .arj file.

l: Display the files contained in the compressed file.

t: Check whether the compressed file is correct.

x: Keep the original path when decompressing.

4. Description

Files with the .arj extension are created by the ARJ utility for MS DOS and Windows. Because ARJ is a shareware program for which the source code is not freely available, in

mtools

1. Function

mtools

is actually a The command set is a tool program of the DOS file system. It can simulate many DOS commands and is very convenient to use. Access rights are for all users. The Linux system provides a set of portable tools called

mtools, which allows users to easily read and write files and directories from standard DOS floppy disks. They are very useful for exchanging files between DOS and Linux environments. mtools

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

mcopy a:*.*

In other words, Just add a letter "m" before the corresponding DOS command to complete the corresponding function. This software is generally available in Linux distributions. You can use the following command to check it.

rpm -qa|grep mtools

If it is not installed, it doesn’t matter. You can download the latest version from the Internet (http://mtools.linux.lu/) to install it. The latest mtools version currently available for download is

2. Included command

mcd Directory name: Change the directory under MS DOS.

mcopy source file target file: Copy files between MS DOS and Unix.

mdel file name: delete files under MS DOS.

mdir directory name: displays the directory under MS DOS.

mformat drive letter: Creates an MS DOS file system on a low-level formatted floppy disk.

rnlabel Drive letter: Generate 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 Target file: Rename an existing MS DOS file.

mtype file name: Displays the contents of MS DOS files.

Please 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 the DOS system and is not case-sensitive, "CDE" and "cde" are the same here.

3. Application examples

(1) If you want to quickly format a floppy disk, you can use the command mformat:

mformat A:

mtools

The original development purpose was to process DOS file systems, so it can only be used on partitions in FAT file format. It should be noted that if you use the mount command to mount the FAT16/32 partition, then you cannot use the mtools instructions to process the files on these partitions. This is because once the FAT16/32 partition is mounted in the Linux file directory, Linux will regard it as part of the file system

itself. At this time, if you want to operate it, you must use the instructions that come with Linux itself. set.

(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. Function

man command is used to provide online help, and the usage permission is for all users. An online manual is stored in the Linux system for users to search on the terminal. Use the man command to access the help information, which is very convenient and practical.

2. 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: Specify the setting file man.conf, the default value is /etc/ man.conf.

-M path: Specifies the search path for online manuals. If not specified, the setting of the environment variable MANPATH will be used; if MANPATH is not used, the setting in /usr/lib/man.conf will be used. ;If MANPATH is an empty string, it means using the default value.

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

-S section_list man: List of sections to be searched (separated by colon). This option will override the setting of the environment variable MANSECT.

-a man: The default is to stop searching after displaying the first found manual. Using this option will force man to continue to display all online manuals matching the name.

-c: Even if there is the latest cat page, continue to retype the online manual. This option is particularly meaningful when the number of rows and columns on the screen changes or the typeset online manual is damaged.

-d: Do not actually display the online manual, only display debugging messages.

-D: Display online manual and debugging messages at the same time.

-h: Display the help message and then end the program.

-K: Search all online manuals for the specified string. Please note that the response speed of this function may be very slow. If you specify a section (region), it will help the speed.

-m system: Specify another set of online manuals based on the specified system name.

man: It is the abbreviation of manual. When you have difficulty entering commands, you can get this document immediately. For example, if you encounter difficulties using the ps command, you can enter man ps to get help information. The man page of ps will be displayed.

Since the man page is viewed using the less program (the screen can be easily turned up and down), all options of less can be used in the man page. The more important function keys in

less are:

[q] to exit;

[Enter] to scroll down line by line;

[Space] one Turn page down;

turn up one page;

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

[n] found the last time Find the next match.

4.Read the man page

Man pages provide a lot of information in a small space. Here is a brief introduction to some of the content found in most man pages. The Linux man page mainly has nine parts: user instructions, system calls, program libraries, device descriptions, file formats, games, miscellaneous, system instructions, and kernel. A snapshot of the man page is shown in Figure 1.

Figure 1 ps command man page snapshot

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

5. Application examples

Linux

There are some basic and important commands, such as ps, find, cat and ls. Let's give an example of comprehensive application. From this, we can see that the status of man is crucial in Linux. However, the information displayed by man is not ordinary text. If you redirect these words directly to a text file, you will find that the highlighted text in man becomes two, and there are countless

number of tab characters makes printing and editing very inconvenient. However, you can get ps command printing by using the following statement.

# man ps | col -b | lpr

This command uses both output redirection and pipe techniques. The function is to print the help information of the ps command directly. For more Man files, please view Linux Man

unencode

1. Function

The unencode command can encode a binary file table into a text file, and the usage permissions are for all users .

2. Format

uuencode [-hv] [source file] Target file

3. Main parameters

-h: List the instruction format (help).

-v: List version information.

4. Application Description

The uuencode command can convert binary files into ASCII encoding that can be sent by email. The data encoded by uuencode starts with begin and ends with end, and usually the beginning of each line is "M". The middle part is the encoded file. The encoded file is larger than the source file.

uudecode

1. Function

The uudecode command is used to restore files encoded by uuencode. uudecode will only restore the encoded data between the begin and end tags. The program Data outside the tag will be skipped. Its usage rights are for all users.

2. Format

uuencode [-hv] [file1 ...]

3. Main parameters

-h: List the instruction format (help).

-v: List version information.

4. Application example

Use the following command to restore several files at a time:

uuencode file1.uud file2.uud file3.uud

Hands-on exercise

1. Sending emails under the Linux command line

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

cat | mail

cat (cat is the abbreviation of concatenate ) command is to process several files into one file and save the result of this processing to a separate output file. Here we use it to merge the text of the email.

Write the email name, for example, cjkmail, and then use the following command:

$uuencode >>cjkmail

This way You can use the vi editor to write the cjkmail file, write the text of the letter in front, and then send it.

After receiving the letter, the other party copies the content in the letter that belongs to cjkmail and saves it as themail.uue. If the other party is under Windows, you can use WinRAR or WinZip to decompress it, so that you can see the attachment.

If the other party also uses Linux, you can use the undecode command to restore:

$ uudencode -o themail.uue

2. Implement tar volume

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 completed by a combination of three commands, that is, packaging with tar and splitting with split , merge with cat. "tar czvf - dir" means to package the dir directory and output it to standard output (argv), so that it can be directly output to split using a pipe.

3. Continuously execute a command

Use the watch command to execute the command repeatedly. If combined with ls, you can achieve the effect of observing the size changes of a certain file.

$watch ls -l file.name

4. Use the tar command to export a file

There is a DVD file in tar format GLvPro6.4_linux.tar, because this file It is very large (4.7GB). If it is troublesome to decompress it all, you can use the following command to export readme.txt first.

tar xvf GLvPro6.4_linux.tar readme.txt

In this way, readme.txt is exported separately.

5. When using tar to package a directory, only back up several subdirectories

tar cf --exclude home/cjh home/cao

In this way, there is only cjh in the home directory and cao subdirectory backup.

The above is the detailed content of 60 Linux commands you must learn. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn