Linux commonly used 100+ command Daquan detailed long text (Collector's Edition)

Linux provides a large number of commands that can be used to efficiently perform a large number of tasks, such as disk operations, file access, directory operations, process management, file permissions, and more. Therefore, working on a Linux system is inseparable from using the commands provided by the system. To truly understand the Linux system, you must learn from Linux commands and learn more about Linux systems through basic command learning.

The number of commands for different Linux distributions is different, but there are more than 200 commands for Linux distributions. Here, the Marco linux college study group divides the more important and frequently used commands into the following six parts according to their role in the system.

â—† Installation and login commands: login, shutdown, halt, reboot, install, mount, umount, chsh, exit, last;

â—† File processing commands: file, mkdir, grep, dd, find, mv, ls, diff, cat, ln;

â—† System management related commands: df, top, free, quota, at, lp, adduser, groupadd, kill, crontab;

â—† Network operation commands: ifconfig, ip, ping, netstat, telnet, ftp, route, rlogin, rcp, finger, mail, nslookup;

â—† System security related commands: passwd, su, umask, chgrp, chmod, chown, chattr, sudo ps, who;

â—† Other commands: tar, unzip, gunzip, unarj, mtools, man, unendcode, uudecode.

This article uses 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.


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

Login

Function

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

2. Format

Login [name][-p ][-h hostname]

3. Main parameters

-p: Notifies login that the current environment parameters are maintained.

-h: Used to transfer the username to the remote login.

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

The general interface is like this:

Manddrake Linux release 9.1(Bamboo) for i586renrel 2.4.21-0.13mdk on i686 / tty1localhost login:rootpassword:

In the above code, the first line is the Linux distribution number, the second line is the kernel version number and the login virtual console. We enter the login name in the third line, press the “Enter” key to enter the account password after the password. log in system. For security reasons, characters are not echoed on the screen when the account password is entered, and the cursor does not move.

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

[root@localhost root]#last login:Tue,Nov 18 10:00:55 on vc/1

Shown above is the login week, month, day, time, and virtual console used.

4. Application skills

Linux is a true multi-user operating system that accepts multiple users at the same time and allows multiple users to log in multiple times. This is because Linux, like many versions of Unix, provides access to the virtual console, allowing users to log in multiple times at the same time from the console (the system's console is the monitor and keyboard directly connected to the system). Each virtual console can be thought of as a separate workstation that can be switched between workbenches. The virtual console can be switched by pressing the Alt key and a function key, usually using F1-F6.

For example, after the user logs in, press the "Alt+F2" button, and the user can see the "login:" prompt that appears above, indicating that the user has seen the second virtual console. Then just press the "Alt+F1" button and you can go back to the first virtual console. A newly installed Linux system allows users to access the first six virtual consoles using the "Alt+F1" to "Alt+F6" keys. The most useful thing about the virtual console is that when a program error causes the system to deadlock, you can switch to another virtual console to work and close the program.

Debug

Function

The shutdown command is used to shut down the computer and its usage rights are superusers.

2. Format

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

3. Important parameters

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

-k: Does not really shut down, just sends a warning signal to each registrant.

-h: Turn off the power after shutting down.

-c:cancel current process cancels the shutdown program currently being executed. So of course this option has no time parameters, but you can enter a message for explanation, and this information will be sent to each user.

-F: Force fsck when restarting the computer.

-time: Set the time before shutdown.

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

-i: Displays system information when shutting down.

4. Command Description

The shutdown command safely shuts down the system. Some users will shut down the Linux system by directly disconnecting the power supply, which is very dangerous. Because Linux is different from Windows, it runs many processes in the background, so forcible shutdown may result in data loss of the process, making the system unstable, and even in some systems, the hardware device (hard disk) will be damaged. Use the shutdown command before the system is shut down. 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, the new user can no longer log in.

Halt

Function

The halt command is used to shut down the system and its usage rights are superusers.

2. Format

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

3. Description of main parameters

-n: Prevents sync system calls. It is used after patching the root partition with fsck to prevent the kernel from overwriting the patched superblock with the old version of the superblock.

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

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

-i: Turn off all network interfaces before shutting down (or restarting).

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

-p: When the power is turned off, the power is turned off.

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

4. Command Description

Halt is called shutdown -h. When halt is executed, it kills the application process, executes sync (forces the data stored in the buffer to the hard disk). The system calls, and the kernel stops after the file system write operation is completed. If the system's run level is 0 or 6, shut down the system; otherwise, replace it with the shutdown command (plus the -h parameter).

Reboot

Function

The reboot command is used to restart the computer. Its usage rights are system administrators.

2. Format

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

3. Main parameters

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

-w: Doesn't really reboot, just write the record to the /var/log/wtmp file.

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

-i: Stop all network related devices before rebooting.

Install

Function

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

2. Format

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

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

(3) install -d [options]... directory...

In the first two formats, <source> is copied to <destination> or multiple <source> files are copied to the existing <directory>, and the permission mode and owner/owner group are set. In the third format, all specified directories and their home directories are created. The parameters that must be used for long options are also required when using short options.

3. Main parameters

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

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

-c: (This option is not processed).

-d, --directory: All parameters are processed as directories, and all home directories of the specified directory are created.

-D: Create all home directories before <destination>, then copy <source> to <destination>; useful in the first usage format.

-g,--group=Group: Set the own group, not the current group of the process.

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

-o,--owner=Owner: Set the owner by yourself (only for superusers).

-p, --preserve-timestamps: Use the access/modification time of the <source> 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 <suffix> of the backup file by yourself.

-v, --verbose: Prints the name when processing each file/directory.

--help: Display this help message and leave.

--version: Display version information and leave.

Mount

Function

The role of the mount command is to load the file system. Its permissions are superusers or users allowed in /etc/fstab.

2. Format

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

3. Main parameters

-h: Display auxiliary information.

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

-a: hang all filesystems defined in /etc/fstab.

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

-f: Usually used for debugging. It causes mount to not perform the actual hanging action, but instead simulates the entire hanging process, usually with -v.

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

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

4. Application skills

On Linux and Unix systems, all files are accessed as part of a large tree (with / as root). To access a file on a CD-ROM, you need to mount the CD-ROM device at a mount point in the file tree. This step can be automated if the distribution has an automount package installed. In Linux, if you want to use a storage device such as a hard disk or an optical drive, you must first load it. Once the storage device is mounted, you can access it as a directory. Mount a device using the mount command. When using the mount command, at least the following three kinds of information must be known: the file system type of the object to be loaded, the device name of the object to be loaded, and the directory where the device is to be loaded.

(1) File system that Linux can recognize

â—† Windows 95/98 commonly used FAT 32 file system: vfat;

â—† Win NT/2000 file system: ntfs;

â—† File system for OS/2: hpfs;

â—† File system for Linux: ext2, ext3;

â—† File system for CD-ROM: iso9660.

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

(2) Determine the name of the device

In Linux, device names are usually stored in /dev. The names of these device names are all regular, and the device name can be found by "reasoning". For example, the /dev/hda1 IDE device, hd is Hard Disk, sd is SCSI Device, and fd is Floppy Device (or Floppy Disk?). a represents the first device, usually the IDE interface can be connected to 4 IDE devices (such as 4 hard drives). So the way to identify the IDE hard drive is hda, hdb, hdc, hdd. The "1" in hda1 represents the first hard disk 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, where you can find the device ID that the system has recognized after the computer is turned on.

(3) Find the mount point

Before deciding to mount the device, first check to see if the computer has an empty directory of /mnt, which is the directory dedicated to the Mount Point. It is recommended to create several /mnt/cdrom, /mnt/floppy, /mnt/mo directories in /mnt as a dedicated mount point for the directory. For example, if you want to mount the following five devices, the execution instructions may be as follows (assuming all are ext2 systems for Linux, if you are Windows XX, change ext2 to vfat):

Floppy disk===>mount -t ext2 /dev/fd0 /mnt/floppycdrom ===>mount -t iso9660 /dev/hdc /mnt/cdromSCSI cdrom ===>mount -t iso9660 /dev/sdb /mnt/scdromSCSI Cdr ===>mount -t iso9660 /dev/sdc /mnt/scdr

However, most newer Linux distributions (including Red Flag Linux, Medium Soft Linux, Mandrake Linux, etc.) can automatically mount file systems, with the exception of Red Hat Linux.

Umount

Function

The umount command is used to unload a file system. Its usage rights are superusers or users allowed in /etc/fstab.

2. Format

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

3. Instructions for use

The umount command is the inverse of the mount command. Its parameters and usage are the same as the mount command. After Linux mounts the CD-ROM, it locks the CD-ROM so that it cannot be ejected using the Eject button on the CD-ROM panel. However, if the CD is no longer needed, if you have /cdrom as a symbolic link, use umount/cdrom to uninstall it. This command will only succeed if no user is using the disc. This command includes a terminal window that takes the current working directory as a directory on the disc.

Chsh

Function

The purpose of the chsh command is to change the user shell settings, which are used by all users.

2. Format

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

3. Main parameters

-l: Display all shell types of the system.

-v: Display the shell version number.

4. Application skills

I introduced a variety of shells under Linux. The default is Bash. If you want to replace the shell type, you can use the chsh command. Enter the account password first, 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 caoPassword:New shell [/bin/bash]: /bin/tcsh

In the above code, [ ] is the currently used shell. Ordinary users can only modify their own shells, and superusers 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 type that the system can use

As can be seen from Figure 1, the shells that can be used in the author system are bash (default), csh, sh, tcsh.

Exit

Function

The exit command is used to quit the system, and its usage rights are all users.

2. Format

Exit

3. Parameters

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

Last

Function

The role of the last command is to display the login status of recent users or terminals. Its usage rights are all users. By viewing the log of the program with the last command, the administrator can know 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: Specifies the number of records to be output.

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

-t tty: Displays only the login status on the specified virtual console.

-h node: Displays only the login status on the specified node.

-i IP: Displays only the login on the specified IP.

-1: Use IP to display the remote address.

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

-ID: Know the username of the query.

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

Hands-on practice

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

1. Run multiple commands at once

You can execute multiple commands on a single command line, separating each command with a semicolon, for example:

#last -x;halt

The above code indicates that the computer is shut down after displaying a history of system shutdown, user login, and logout.

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

Many Linux distributions now automatically load Vfat partitions to access Windows systems, and Red Hat versions do not automatically load Vfat partitions, so manual operations are required.

Mount can attach a Windows partition as a "file" of Linux to an empty folder on Linux, thus linking the Windows partition to the /mnt directory. Therefore, just accessing this folder is equivalent to accessing the partition. First create the winc folder under /mnt and type the following at the command prompt:

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

This means that the C partition of Windows is hung in 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 disks of the Windows system. In Linux, Windows partitions are generally displayed in the following order: hda1 is C drive, hda5 is D drive, hda6 is E drive, and so on. The above method can be viewed in Windows system has a big problem, that is, all Chinese file names or folder names in Windows are displayed as question mark "?", but English can be displayed normally. We can show it in 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 drive

Using a flash drive under Linux is very simple. Linux has good support for USB devices. When a flash drive is inserted, the flash drive is recognized as a SCSI disk. Usually enter the following command:

# mount /dev/sda1 /usb

It is possible to add a file system on the flash drive.

tips

Linux commands and shell

The so-called shell is the command interpreter, which provides a programming interface that can be programmed using a program. Learning Shell is very important for Linux beginners to understand Linux systems. The shell of the Linux system acts as the shell of the operating system and provides the user with an interface to use the operating system. Shell is a general term for command language, command interpreter, and programming language. It is an interface program between the user and the Linux kernel. If you think of the Linux kernel as the center of a sphere, the shell is the outer layer around the kernel. When you pass commands from Shell or other programs to Linux, the kernel reacts accordingly. The role of Shell in Linux systems is similar to COMMAND.COM under MS DOS and explorer.exe for Windows 95/98. Although Shell is not part of the system core, it is just an extension of the system core, but it can call most of the functions of the system kernel. Therefore, it can be said that Shell is the most important utility of Unux/Linux.

There are many types of shells in Linux, the most common of which are Bourne Shell (sh), C Shell (csh), and Korn Shell (ksh). The default shell for most Linux distributions is the Bourne Again Shell, which is an extension of the Bourne Shell, bash for short, fully backwards compatible with the Bourne Shell, and adds many features to the Bourne Shell. Bash is placed in /bin/bash and provides functions such as command completion, command editing, and command history tables. It also includes many of the advantages of the C Shell and Korn Shell, with a flexible and powerful programming interface, and a very user-friendly interface. 40 of the more than 200 commands in the Linux system are internal commands of bash, including exit, less, lp, kill, cd, pwd, fc, fg, etc.

60 commands that Linux must learn (2) - file processing commands

Linux system information is stored in a file similar to a normal business file. Each file has its own name, content, storage address, and other management information, such as the user of the file, the size of the file, and so on. A file can be a letter, an address book, or a source statement of a program, program data, or even executable programs and other non-text content. The Linux file system has a good structure and the system provides many file handlers. Here are the main commonly used file processing commands.

File

1. The content of the action piece determines the file type, and the usage rights are all users.

2. Format

File through probe text

File [options] filename

3.[options] main parameters

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

-z: Detects compressed file types.

-L: Allows the connection to be met.

-f name: Reads the list of file names to be parsed from the file namefile.

4. Brief description

Use the file command to know whether a file is a binary (ELF format) executable, a Shell Script file, or something else. File types that can be recognized by file include directory, shell script, English text, binary executable file, C language source file, text file, and DOS executable file.

5. Application examples

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

$ file grap

Grap: English text

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

Mkdir

Function

The mkdir command is used to create a subdirectory named dirname, similar to the md command under MS DOS. Its usage rights are all users.

2. Format

Mkdir [options] directory name

3.[options] main parameters

-m, --mode= mode: Set the permission <mode>, similar to chmod.

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

-v, --verbose: Displays information each time a new directory is created.

--version: Leave after displaying the version information.

4. Application examples

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

$ mkdir -m 777 tsk

Grep

Function

The grep command can specify a file to search for specific content and output the line containing the content as standard. The full name of grep is Global Regular Expression Print, which represents the global regular expression version, and its usage rights are for all users.

2. Format

Grep [options]

3. Main parameters

[options] main parameters:

-c: Output only the count of matching rows.

-I: Not case sensitive (only for single characters).

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

-l: When querying multiple files, only the file name containing the matching characters is output.

-n: Display matching lines and line numbers.

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

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

Pattern regular expression main parameters:

/: Ignores the original meaning of special characters in regular expressions.

^: Matches the start line of the regular expression.

$: matches the end line of the regular expression.

/<: Starts with a line that matches the regular expression.

/>: Ends the line that matches the regular expression.

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

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

. : All single characters.

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

Regular expressions are a very important concept in Linux/Unix systems. A regular expression (also known as "regex" or "regexp") is a pattern that can describe a type of string. If a string can be described by a regular expression, we say that the character matches the regular expression (Match). This is similar to the use of the wildcard "*" for any character in DOS. 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

Querying the DNS service is one of the daily tasks, which means maintaining a large number of IP addresses covering different networks. Sometimes the IP address will exceed 2000. If you want to look at the nnn.nnn network address, but forget the rest of the second part, you only know that there are two periods, such as nnn nn.. To extract all of the nnn.nnn IP addresses, use [0-9 ]/{3 /}/.[0-0/{3/}/. The meaning is that any number appears 3 times, followed by a period, followed by any number 3 times, followed by a period.

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

In addition, the grep family also includes fgrep and egrep. Fgrep is fix grep, which allows you to find strings instead of a pattern; egrep is an extended grep that supports basic and extended regular expressions, but does not support /q mode-scoped applications and some of the more standard patterns that correspond to them.

Dd

Function

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

2. Format

Dd [options]

3.[opitions] main parameters

Bs=byte: Force ibs=<byte> and obs=<byte>.

Cbs=byte: The specified <byte> is converted each time.

Conv=keyword: Convert files according to the way comma-separated keywords are represented.

Count=number of blocks: Only the input data of the specified <number of blocks> is copied.

Ibs=byte: Reads the specified <byte> each time.

If= file: Read <file> content instead of standard input data.

Obs=byte: Writes the specified <byte> each time.

Of=File: Write data to <file> instead of standard output.

Seek=number of blocks: The output data of the specified <number of blocks> in obs is skipped first.

Skip=Number of blocks: The input data of the specified <number of blocks> in ibs is skipped first.

4. Application examples

The dd command is often used to make Linux boot disks. First find a bootable kernel, point its root device to the correct root partition, and then write it to the floppy disk using the dd command:

$ rdev vmlinuz /dev/hda

$dd if=vmlinuz of=/dev/fd0

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

Find

Function

The function of the find command is to search for files in the directory. Its usage rights are all users.

2. Format

Find [path][options][expression]

Path specifies the directory path from which the system looks down the file along the directory tree. It is a list of paths separated from each other by spaces. If you do not write path, the default is the current directory.

3. Main parameters

[options] parameters:

-depth: Use the depth level search process to find the file content first in a specified directory on a certain layer.

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

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

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

-version: Print version.

[expression] is a matching expression, which is an expression accepted by the find command. All operations of the find command are for expressions. It has a lot of parameters, only some common parameters are introduced here.

—name: Supports the wildcards * and ?.

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

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

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

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

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

-print: Output search results and print.

4. Application skills

The find command finds several ways to find a file:

(1) Find by file name

For example, we want to find a file whose file name is lilo.conf. You can use the following command:

Find / -name lilo.conf

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

(2) Quickly find files

Finding a file based on the file name has a real problem, which is a considerable amount of time, especially when large Linux file systems and large hard disk files are placed in deep subdirectories. If we know that this file is stored in a directory, then looking down in this directory can save a lot of time. For example, the smb.conf file, from its file suffix ".conf" can be judged that this is a configuration file, then it should be in the /etc directory, you can use the following command:

Find /etc -name smb.conf

This way, you can use the "quick find files" method to reduce the time.

(3) Find method based on partial file name

Sometimes we know that only a file contains the 4 words abvd, then to find all the files in the system that contain these 4 characters, you can enter the following command:

Find / -name '*abvd*'

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

(4) Find files using hybrid lookup

The find command can use a hybrid lookup method. For example, if we want to find a file larger than 500000 bytes in the /etc directory and modify it within 24 hours, we can use -and to link the two lookup parameters. Synthesize a mixed lookup.

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

Mv

Function

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

2. Format

Mv[options] source file or directory object file or directory

3.[options] main parameters

-i: Interactive mode operation. If the mv operation will result in an overwriting of the existing target file, the system asks whether to rewrite, and asks the user to answer "y" or "n", so as to avoid accidentally overwriting the file.

-f: Disable interworking. The mv operation does not give any indication when it wants to overwrite an existing target file. After this parameter is specified, the i parameter will no longer work.

4. Application examples

(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

Function

The ls command is used to display the contents of the directory, similar to the dir command under DOS, and its usage rights are all users.

2. Format

Ls [options][filename]

3.options main parameters

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

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

--author: Print out each file author.

-b, --escape: Indicates unprintable characters in an octal overflow sequence.

--block-size=Size: The block is in bytes of the specified <size>.

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

-f: Do not sort, the -aU parameter takes effect, and the -lst parameter fails.

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

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

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

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

-I, --ignore=Style: Do not print any items that match the Shell universal character <style>.

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

-l: Lists information in a longer format.

-L, --dereference: When the file information of the symbolic link is displayed, the object indicated by the symbolic link is displayed instead of 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: Lists unprocessed project names, such as no special handling of control characters.

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

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

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

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

-s, --size: in block order.

4. Application examples

The ls command is the most frequently used command in Linux systems, and its parameters are the most common in Linux commands. There are several different colors when using the ls command, where blue indicates a directory, green indicates an executable file, red indicates a compressed file, light blue indicates a link file, bold black indicates a symbolic link, and gray indicates Is a different format file. The most commonly used ls is ls-l, as shown in Figure 1.

Figure 1 Using the ls-l command

The file type begins with a string of 10 characters. The first character represents the file type, which can be one of the following types: - (plain file), d (directory), l (symbolic link), b (block device file), c (character device file). The next 9 characters indicate the access rights of the file, divided into 3 groups of 3 bits each. The first group represents the permissions of the owner of the file, the second group represents the permissions of the same group of users, and the third group represents the permissions of other users. The three characters of each group represent the read (r), write (w), and execute permission (x) of the file. For directories, indicates access rights. s indicates 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 execution process. t indicates the setting flag (left in memory, not swapped out). If the file is a directory, files in that directory can only be deleted by the superuser, directory owner, or file owner. If it is an executable file, the pointer to its body segment remains in memory after the file is executed. When you execute it again, the system can load the file faster. The file size, build time, file or command name is then displayed.

Diff

Function

The diff command is used to compare between two files and points out the difference between the two, and its usage rights are all users.

2. Format

Diff [options] source file object file

3.[options] main parameters

-a: Treat all files as text files.

-b: Ignore the difference caused by spaces.

-B: Ignore the difference caused by blank lines.

-c: Use the outline output format.

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

-I: Ignore case changes.

-n --rcs: Outputs the RCS format.

Cmp

Function

The cmp (short for "compare") command is used to briefly indicate whether there is a difference between two files, and its usage rights are all users.

2. Format

Cmp[options] filename

3.[options] main parameters

-l: 将字节以十进制的方式输出,并方便将两个文件中不同的以八进制的方式输出。

cat

1.作用

cat(“concatenate”的缩写)命令用于连接并显示指定的一个和多个文件的有关信息,它的使用权限是所有用户。

2.格式

cat [options] 文件1 文件2……

3.[options]主要参数

-n:由第一行开始对所有输出的行数编号。

-b:和-n相似,只不过对于空白行不编号。

-s:当遇到有连续两行以上的空白行时,就代换为一行的空白行。

4.应用举例

(1)cat命令一个最简单的用处是显示文本文件的内容。例如,我们想在命令行看一下README文件的内容,可以使用命令:

$ cat README

(2)有时需要将几个文件处理成一个文件,并将这种处理的结果保存到一个单独的输出文件。cat命令在其输入上接受一个或多个文件,并将它们作为一个单独的文件打印到它的输出。例如,把README和INSTALL的文件内容加上行号(空白行不加)之后,将内容附加到一个新文本文件File1 中:

$ cat README INSTALL File1

(3)cat还有一个重要的功能就是可以对行进行编号,见图2所示。这种功能对于程序文档的编制,以及法律和科学文档的编制很方便,打印在左边的行号使得参考文档的某一部分变得容易,这些在编程、科学研究、业务报告甚至是立法工作中都是非常重要的。

图2 使用cat命令/etc/named.conf文件进行编号

对行进行编号功能有-b(只能对非空白行进行编号)和-n(可以对所有行进行编号)两个参数:

$ cat -b /etc/named.conf

ln

1.作用

ln命令用来在文件之间创建链接,它的使用权限是所有用户。

2.格式

ln [options] 源文件[链接名]

3.参数

-f:链结时先将源文件删除。

-d:允许系统管理者硬链结自己的目录。

-s:进行软链结(Symbolic Link)。

-b:将在链结时会被覆盖或删除的文件进行备份。

链接有两种,一种被称为硬链接(Hard Link),另一种被称为符号链接(Symbolic Link)。默认情况下,ln命令产生硬链接。

硬连接指通过索引节点来进行的连接。在Linux的文件系统中,保存在磁盘分区中的文件不管是什么类型都给它分配一个编号,称为索引节点号(Inode Index)。在Linux中,多个文件名指向同一索引节点是存在的。一般这种连接就是硬连接。硬连接的作用是允许一个文件拥有多个有效路径名,这样用户就可以建立硬连接到重要文件,以防止“误删”的功能。其原因如上所述,因为对应该目录的索引节点有一个以上的连接。只删除一个连接并不影响索引节点本身和其它的连接,只有当最后一个连接被删除后,文件的数据块及目录的连接才会被释放。也就是说,文件才会被真正删除。

与硬连接相对应,Lnux系统中还存在另一种连接,称为符号连接(Symbilc Link),也叫软连接。软链接文件有点类似于Windows的快捷方式。它实际上是特殊文件的一种。在符号连接中,文件实际上是一个文本文件,其中包含的有另一文件的位置信息。

动手练习

上面我们介绍了Linux文件处理命令,下面介绍几个实例,大家可以动手练习一下刚才讲过的命令。

1.利用符号链接快速访问关键目录

符号链接是一个非常实用的功能。假设有一些目录或文件需要频繁使用,但由于Linux的文件和目录结构等原因,这个文件或目录在很深的子目录中。比如, Apache Web服务器文档位于系统的/usr/local/httpd/htdocs中,并且不想每次都要从主目录进入这样一个长的路径之中(实际上,这个路径也非常不容易记忆)。

为了解决这个问题,可以在主目录中创建一个符号链接,这样在需要进入该目录时,只需进入这个链接即可。

为了能方便地进入Web服务器(/usr/local/httpd/htdocs)文档所在的目录,在主目录下可以使用以下命令:

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

这样每次进入gg目录就可访问Web服务器的文档,以后如果不再访问Web服务器的文档时,删除gg即可,而真正的Web服务器的文档并没有删除。

2.使用dd命令将init.rd格式的root.ram内容导入内存

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

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

3.grep命令系统调用

grep是Linux/Unix中使用最广泛的命令之一,许多Linux系统内部都可以调用它。

(1)如果要查询目录列表中的目录,方法如下:

$ ls -l | grep '∧d'

(2)如果在一个目录中查询不包含目录的所有文件,方法如下:

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

(3)用find命令调用grep,如所有C源代码中的“Chinput”,方法如下:

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

Linux必学的60个命令(3)-系统管理命令

对于Linux系统来说,无论是中央处理器、内存、磁盘驱动器、键盘、鼠标,还是用户等都是文件,Linux系统管理的命令是它正常运行的核心。熟悉了Linux常用的文件处理命令以后,这一讲介绍对系统和用户进行管理的命令。

df

1.作用df命令用来检查文件系统的磁盘空间占用情况,使用权限是所有用户。

2.格式df [options]

3.主要参数-s:对每个Names参数只给出占用的数据块总数。-a:递归地显示指定目录中各文件及子目录中各文件占用的数据块数。若既不指定-s,也不指定-a,则只显示Names中的每一个目录及其中的各子目录所占的磁盘块数。-k:以1024字节为单位列出磁盘空间使用情况。-x:跳过在不同文件系统上的目录不予统计。-l:计算所有的文件大小,对硬链接文件则计算多次。-i:显示inode信息而非块使用量。-h:以容易理解的格式印出文件系统大小,例如136KB、254MB、21GB。-P:使用POSIX输出格式。-T:显示文件系统类型。

4.说明df命令被广泛地用来生成文件系统的使用统计数据,它能显示系统中所有的文件系统的信息,包括总容量、可用的空闲空间、目前的安装点等。

超级权限用户使用df命令时会发现这样的情况:某个分区的容量超过了100%。这是因为Linux系统为超级用户保留了10%的空间,由其单独支配。也就是说,对于超级用户而言,他所见到的硬盘容量将是110%。这样的安排对于系统管理而言是有好处的,当硬盘被使用的容量接近100%时系统管理员还可以正常工作。

5.应用实例Linux支持的文件系统非常多,包括JFS、ReiserFS、ext、ext2、ext3、ISO9660、XFS、Minx、vfat、MSDOS等。使用df -T命令查看磁盘空间时还可以得到文件系统的信息:

#df -T文件系统类型容量已用可用已用% 挂载点/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

从上面除了可以看到磁盘空间的容量、使用情况外,分区的文件系统类型、挂载点等信息也一览无遗。

top

1.作用top命令用来显示执行中的程序进程,使用权限是所有用户。

2.格式top [-] [d delay] [q] [c] [S] [s] [i] [n]

3.主要参数d:指定更新的间隔,以秒计算。q:没有任何延迟的更新。如果使用者有超级用户,则top命令将会以最高的优先序执行。c:显示进程完整的路径与名称。S:累积模式,会将己完成或消失的子行程的CPU时间累积起来。s:安全模式。i:不显示任何闲置(Idle)或无用(Zombie)的行程。n:显示更新的次数,完成后将会退出top。

4.说明top命令是Linux系统管理的一个主要命令,通过它可以获得许多信息。这里我们结合图1来说明它给出的信息。

图1 top命令的显示

在图1中,第一行表示的项目依次为当前时间、系统启动时间、当前系统登录用户数目、平均负载。第二行显示的是所有启动的进程、目前运行的、挂起(Sleeping)的和无用(Zombie)的进程。第三行显示的是目前CPU的使用情况,包括系统占用的比例、用户使用比例、闲置(Idle)比例。第四行显示物理内存的使用情况,包括总的可以使用的内存、已用内存、空闲内存、缓冲区占用的内存。第五行显示交换分区使用情况,包括总的交换分区、使用的、空闲的和用于高速缓存的大小。第六行显示的项目最多,下面列出了详细解释。PID(Process ID):进程标示号。USER:进程所有者的用户名。PR:进程的优先级别。NI:进程的优先级别数值。VIRT:进程占用的虚拟内存值。RES:进程占用的物理内存值。SHR:进程使用的共享内存值。S:进程的状态,其中S表示休眠,R表示正在运行,Z表示僵死状态,N表示该进程优先值是负数。%CPU:该进程占用的CPU使用率。%MEM:该进程占用的物理内存和总内存的百分比。TIME+:该进程启动后占用的总的CPU时间。Command:进程启动的启动命令名称,如果这一行显示不下,进程会有一个完整的命令行。top命令使用过程中,还可以使用一些交互的命令来完成其它参数的功能。这些命令是通过快捷键启动的。<空格>:立刻刷新。P:根据CPU使用大小进行排序。T:根据时间、累计时间排序。q:退出top命令。m:切换显示内存信息。t:切换显示进程和CPU状态信息。c:切换显示命令名称和完整命令行。M:根据使用内存大小进行排序。W:将当前设置写入~/.toprc文件中。这是写top配置文件的推荐方法。

可以看到,top命令是一个功能十分强大的监控系统的工具,对于系统管理员而言尤其重要。但是,它的缺点是会消耗很多系统资源。

5.应用实例使用top命令可以监视指定用户,缺省情况是监视所有用户的进程。如果想查看指定用户的情况,在终端中按“U”键,然后输入用户名,系统就会切换为指定用户的进程运行界面,见图2所示。

图2 使用top命令监视指定用户

free

1.作用free命令用来显示内存的使用情况,使用权限是所有用户。

2.格式free [-b|-k|-m] [-o] [-s delay] [-t] [-V]

3.主要参数-b -k -m:分别以字节(KB、MB)为单位显示内存使用情况。-s delay:显示每隔多少秒数来显示一次内存使用情况。-t:显示内存总和列。-o:不显示缓冲区调节列。

4.应用实例free命令是用来查看内存使用情况的主要命令。和top命令相比,它的优点是使用简单,并且只占用很少的系统资源。通过-S参数可以使用free命令不间断地监视有多少内存在使用,这样可以把它当作一个方便实时监控器。#free -b -s5

使用这个命令后终端会连续不断地报告内存使用情况(以字节为单位),每5秒更新一次。

quota

1.作用quota命令用来显示磁盘使用情况和限制情况,使用权限超级用户。

2.格式quota [-g][-u][-v][-p] 用户名组名

3.参数-g:显示用户所在组的磁盘使用限制。-u:显示用户的磁盘使用限制。-v:显示没有分配空间的文件系统的分配情况。-p:显示简化信息。

4.应用实例在企业应用中磁盘配额非常重要,普通用户要学会看懂自己的磁盘使用情况。要查询自己的磁盘配额可以使用下面命令(下例中用户账号是caojh):

#quota caojhDisk quotas for user caojh(uid 502):Filesystem blocks quota limit grace files quota limit grace/dev/hda3 58 200000 400000 41 500 1000

以上显示ID号为502的caojh账号,文件个数设置为500~1000个,硬盘空间限制设置为200MB~400MB。一旦磁盘配额要用完时,就需要删除一些垃圾文件或向系统管理员请求追加配额。

at

1.作用at命令用来在指定时刻执行指定的命令序列。

2.格式at [-V] [-qx] [-f file] [-m] time

3.主要参数-V:显示标准错误输出。-q:许多队列输出。-f:从文件中读取作业。-m:执行完作业后发送电子邮件到用户。time:设定作业执行的时间。time格式有严格的要求,由小时、分钟、日期和时间的偏移量组成,其中日期的格式为MM.DD.YY,MM是分钟,DD是日期,YY是指年份。偏移量的格式为时间+偏移量,单位是minutes、hours和days。

4.应用实例#at -f data 15:30 +2 days

上面命令表示让系统在两天后的17:30执行文件data中指明的作业。

lp

1.作用lp是打印文件的命令,使用权限是所有用户。

2.格式lp [-c][-d][-m][-number][-title][-p]

3.主要参数-c:先拷贝文件再打印。-d:打印队列文件。-m:打印结束后发送电子邮件到用户。-number:打印份数。-title:打印标题。-p:设定打印的优先级别,最高为100。

4.应用实例(1)使用lp命令打印多个文件#lp 2 3 4request id is 11 (3 file(s))

其中2、3、4分别是文件名;“request id is 11 (3 file(s)) ”表示这是第11个打印命令,依次打印这三个文件。

(2)设定打印优先级别#lp lp -d LaserJet -p 90 /etc/aliases

通过添加“-p 90”,规定了打印作业的优先级为90。它将在优先级低于90的打印作业之前打印,包括没有设置优先级的作业,缺省优先级是50

useradd

1.作用useradd命令用来建立用户帐号和创建用户的起始目录,使用权限是超级用户。

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

3.主要参数-c:加上备注文字,备注文字保存在passwd的备注栏中。 -d:指定用户登入时的启始目录。-

Sector Panel Antenna

5G Setor Panel Antemma,4G Sector Panel Antenna,Base Station Grid Antenna,Sector Panel Antenna,MIMO Sector Panel Antenna

Yetnorson Antenna Co., Ltd. , https://www.xhlantenna.com

Posted on