In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the commands that must be learned in linux, which can be used for reference by interested friends. I hope you will gain a lot after reading this article. Let's take a look at it.
Linux provides a large number of commands, which can be used to do a lot of work effectively.
Do, such as disk operation, file access, directory operation, process management, file permission setting, etc. Therefore, working on a Linux system is inseparable from using the commands provided by the system. To really understand the Linux system
You must start with the Linux command, and you can further understand the Linux system through basic command learning.
The number of commands varies from Linux to Linux distribution, but there are more than 200 commands for the fewest Linux distributions. Here, the author divides the more important and most frequently used commands into the following six parts according to their role in the system.
◆ installation and login commands: login, shutdown, halt, reboot, install, mount, umount, chsh, exit, last
◆ file processing commands: file, mkdir, grep, dd, find, mv, ls, diff, cat, ln
◆ system management related commands: df, top, free, quota, at, lp, adduser, groupadd, kill, crontab
◆ network operation commands: ifconfig, ip, ping, netstat, telnet, ftp, route, rlogin, rcp, finger, mail, nslookup
◆ system security related commands: passwd, su, umask, chgrp, chmod, chown, chattr, sudo ps, who
◆ other commands: tar, unzip, gunzip, unarj, mtools, man, unendcode, uudecode.
This paper takes Mandrake Linux 9.1 (Kenrel 2.4.21) as an example to introduce the installation and login commands under Linux.
Immortality press: please use ctrl+f to find a part of the content or the use of a command on this page.
60 necessary commands for Linux (1)-installation and login commands
Login
1. Action
The role of login is to log in to the system, and its permissions are for all users.
two。 Format
Login [name] [- p] [- h host name]
3. Main parameters
-p: tells login to keep the current environment parameters.
-h: used to transfer user names between remote logins.
If you choose to log in to Linux in command-line mode, the first Linux command you see is login:.
The general interface looks like this:
Manddrake Linux release 9.1 (Bamboo) for i586
Renrel 2.4.21-0.13mdk on i686 / tty1
Localhost login:root
Password:
In the above code, the first line is the Linux release number, and the second line is the kernel version number and the login virtual console. We enter the login name on the third line, press the "Enter" key to enter the account password after Password, and then log in to the system. For security reasons, the characters will not be echoed on the screen and the cursor will not move when entering the account password.
After logging in, you will see the following interface (take superuser as an example):
[root@localhost root] #
Last login:Tue, Nov 18 10:00:55 on vc/1
Shown above is the virtual console logged in for the week, month, day, time, and use.
4. Application skills
Linux
Is a true multi-user operating system that allows multiple users to log in at the same time and allows a user to log in multiple times. This is because Linux, like many versions of Unix, provides a virtual console
The access method allows users to log in multiple times at the same time from the console (the console of the system is a monitor and keyboard directly connected to the system). Each virtual console can be seen as a separate workstation, workbench
Can be switched between. The switching of the virtual console can be achieved by pressing the Alt key and a function key, usually using F1-F6.
For example, after the user logs in, click "Alt+"
With the F2 key, the user can see the "login:" prompt above, indicating that the user has seen the second virtual console. Then simply press "Alt+"
A newly installed Linux system allows users to access the first six virtual consoles using the "Alt+F1" to "Alt+F6" keys. Virtual control
The most useful thing is that when a program goes wrong and causes a system deadlock, you can switch to another virtual console to work and close the program.
Shutdown
1. Action
The function of the shutdown command is to shut down the computer, and its permission is superuser.
two。 Format
Shutdown [- h] [- I] [- k] [- m] [- t]
3. Important parameters
-t: tell the init program how long it takes to shut down before changing to another run level.
K: it doesn't really turn off, it just sends a warning signal to every logger.
-h: turn off the power after shutting down.
-c:cancel current process cancels the currently executing shutdown program. So of course there is no time parameter for this option, but you can enter a message for interpretation, and this information will be sent to each user.
-F: force fsck when restarting the computer.
-time: set the time before shutdown.
-m: change the system to single-user mode.
-I: displays system information when shutting down.
4. Command description
Shutdown
Command can safely shut down the system. Some users will shut down the Linux system by directly cutting off the power supply, which is very dangerous. Because Linux is different from Windows, it runs in the background
Many processes, so forced shutdown may result in data loss of the process, leave the system in an unstable state, and even damage hardware devices (hard drives) in some systems. Use before the system shuts down
Shutdown command, the system administrator will notify all logged-in users that the system is about to shut down, and the login command will be frozen, that is, new users can no longer log in.
Halt
1. Action
The function of the halt command is to shut down the system, and its permission is superuser.
two。 Format
Halt [- n] [- w] [- d] [- f] [- I] [- p]
3. Description of main parameters
-n: prevents sync system calls, which are used after patching the root partition with fsck to prevent the kernel from overwriting the patched super block with older versions of the super block.
-w: it's not really a restart or shutdown, it's just a wtmp (/ var/log/wtmp) record.
-f: forced shutdown or restart instead of calling shutdown.
-I: turn off all network interfaces before shutting down (or rebooting).
-f: forced shutdown, do not call the command shutdown.
-p: turn off the power while shutting down the phone.
-d: shut down the system without leaving a record.
4. Command description
Halt
Is to call shutdown.
-h. When halt executes, it kills the application process, executes the sync (data stored in buffer is forced to write to the hard disk) system call, and the kernel is stopped after the file system write operation is complete. If the system
Run level 0 or 6 shuts down the system; otherwise, replace it with the shutdown directive (plus the-h argument).
Reboot
1. Action
The purpose of the reboot command is to restart the computer, and its permission is for the system administrator.
two。 Format
Reboot [- n] [- w] [- d] [- f] [- I]
3. Main parameters
-n: do not write the memory data back to the hard disk before rebooting.
W: it won't really reboot, just write the record to the / var/log/wtmp file.
-d: do not write records to the / var/log/wtmp file (the-n parameter contains-d).
-I: stop all network-related devices before rebooting.
Install
1. Action
The purpose of the install command is to install or upgrade software or backup data, and its permissions are for all users.
two。 Format
(1) install [option]... Source and destination
(2) install [option]... The source. Catalogue
(3) install-d [option]. Catalogue.
In
In the first two formats, copy to or copy multiple files to existing ones, and set the right at the same time
Limited mode and owner / group. In the third format, all specified directories and their home directories are created. The parameters that the long option must use are also necessary when using the short option.
3. Main parameters
-- backup [= CONTROL]: back up each existing destination file.
-b: similar to-- backup, but does not accept any parameters.
-c: (this option is not processed).
All parameters are treated as directories, and all home directories of the specified directory are created.
-D: all home directories before creation, and then will be copied to; useful in the first use format.
-GMAT talk group = group: set the group to which you belong, rather than the group to which the process currently belongs.
-mmam talk mode = mode: set your own permission mode (like chmod) instead of rwxr-xr-x.
Owner: set the owner by yourself (for superusers only).
-pmam talk about the visit / modification time of the file as the time attribute of the corresponding destination file.
-smam copyright strip: use the strip command to delete symbol table, which is only applicable to the first and second formats.
-Smam copyright suffix = suffix: the backup file is specified by yourself.
-vmam Meltel verbose: print the name when processing each file / directory.
-- help: display this help and leave.
-- version: displays the version information and leaves.
Mount
1. Action
The function of the mount command is to load the file system, and its permissions are superuser or allowed user in / etc/fstab.
two。 Format
Mount-a [- fv] [- t vfstype] [- n] [- rw] [- F] device dir
3. Main parameters
-h: displays auxiliary information.
-v: displays information, usually used with-f to debug.
-a: Mount all file systems defined in / etc/fstab.
-F: this command, usually used with-a, generates a stroke for each mount action to be executed. You can speed up loading when the system needs to mount a large number of NFS file systems.
-f: commonly used for debugging. It causes mount not to perform the actual mount action, but to simulate the entire mount process, usually used with-v.
-t vfstype: displays the type of file system being loaded.
-n: generally speaking, mount hangs up and writes a piece of data to / etc/mtab. If there is no writable file system in the system, you can use this option to cancel this action.
4. Application skills
In Linux
And Unix systems, all files are accessed as part of a large tree (with / as root). To access files on CD-ROM, you need to mount the CD-ROM device on a hanger in the file tree
Decorate. If the distribution installs the auto-mount package, this step can be done automatically. In Linux, if you want to use a storage device such as a hard disk or optical drive, you have to load it first, when the storage device is hung up.
You can access it as a directory. Hang up a device and use the mount command. When using the mount directive, you must first know the following three kinds of information: the file system type of the object to be loaded, the file system type to
The name of the device on which the object is loaded and the directory into which you want to load the device.
(1) File systems that can be recognized by Linux
The commonly used FAT 32 file system of ◆ Windows 95True 98: vfat
File system of ◆ Win NT/2000: ntfs
File system for ◆ OS/2: hpfs
File systems for ◆ Linux: ext2, ext3
File system for ◆ CD-ROM CD: iso9660.
Although vfat refers to a FAT 32 system, it is actually compatible with the file system type of FAT 16.
(2) determine the name of the equipment
In Linux
The device name is usually stored in / dev. The naming of these device names is regular, and the device name can be found out by "reasoning". For example, / dev/hda1 this
IDE device, hd is Hard Disk (hard drive), sd is SCSI Device,fd, Floppy Device (or Floppy)
Disk?). A stands for the first device, and usually the IDE interface can be connected to four IDE devices (such as four hard drives). So the ways to identify IDE hard drives are hda, hdb, hdc,
Hdd . The "1" in hda1 represents the first hard disk partition of hda
(partition), hda2 represents the second primary partition of hda, the first logical partition starts with hda5, and so on. In addition, you can check directly
/ var/log/messages file, where you can find the device code that has been recognized by the system after the computer is powered on.
(3) find the connection point
In decision
Before you mount the device, check to see if the computer has an empty directory of / mnt, which is specifically used as a mount point (Mount
Point). It is recommended to create several directories such as / mnt/cdrom, / mnt/floppy, / mnt/mo in / mnt, which can be used as dedicated mount points for directories. For example, such as
To mount the following five devices, the execution instructions may be as follows (assuming that they are all ext2 systems of Linux, change ext2 to vfat if it is Windows XX):
Floppy disk = > mount-t ext2 / dev/fd0 / mnt/floppy
Cdrom = = > mount-t iso9660 / dev/hdc / mnt/cdrom
SCSI cdrom = = > mount-t iso9660 / dev/sdb / mnt/scdrom
SCSI cdr = = > mount-t iso9660 / dev/sdc / mnt/scdr
However, most newer Linux distributions (including Red Flag Linux, medium soft Linux, Mandrake Linux, etc.) can mount the file system automatically, with the exception of Red Hat Linux.
Umount
1. Action
The purpose of the umount command is to unmount a file system with the permission of a superuser or a user allowed in / etc/fstab.
two。 Format
Unmount-a [- fFnrsvw] [- t vfstype] [- n] [- rw] [- F] device dir
3. instructions
Umount
The command is the inverse of the mount command, and its parameters and usage are the same as those of the mount command. After Linux mounts CD-ROM, CD-ROM is locked so that CD- cannot be used.
The Eject button on the ROM panel pops it up. However, when the CD is no longer needed, if / cdrom is already used as a symbolic link, use umount/cdrom to unmount it. Only if there are no users
The command succeeds only when the CD is in use. This command includes a terminal window with the current working directory as a directory on the CD.
Chsh
1. Action
The function of the chsh command is to change the user's shell settings, and its permission is for all users.
two。 Format
Chsh [- s] [- list] [--help] [- v] [username]
3. Main parameters
-l: displays all Shell types of the system.
-v: displays the Shell version number.
4. Application skills
It was introduced earlier that there are many kinds of Shell under Linux. The default is Bash. If you want to change the Shell type, you can use the chsh command. First enter the account password, and then enter the new Shell type, if the operation is correct, the system will display "Shell change". The interface is generally as follows:
Changing fihanging shell for cao
Password:
New shell [/ bin/bash]: / bin/tcsh
In the above code, [] is the currently used Shell. Ordinary users can only modify their own Shell, while superusers can modify the Shell of all users. To query which Shell the system provides, you can use the chsh-l command, as shown in figure 1.
Figure 1 types of Shell that can be used by the system
As you can see from figure 1, there are four kinds of Shell that can be used in the author's system: bash (default), csh, sh, and tcsh.
Exit
1. Action
The function of the exit command is to exit the system, and its permission is for all users.
two。 Format
Exit
3. Parameters.
The exit command has no parameters. After running, exit the system and enter the login interface.
Last
1. Action
The purpose of the last command is to display the recent login of a user or terminal, and its permission is for all users. By viewing the program's log through the last command, the administrator can know who has connected or attempted to connect to the system.
two。 Format
1ast [- n] [- f file] [- t tty] [- h node] [- I-IP] [- 1] [- y] [1D]
3. Main parameters
-n: specifies the number of output records.
-f file: specifies the file file as the log file for the query.
-t tty: only logins on the specified virtual console are displayed.
-h node: only the login on the specified node is displayed.
-I IP: displays only logins on the specified IP.
-1: use IP to display the remote address.
-y: displays the year, month and day of the record.
-ID: know the user name of the query.
-x: displays the history of system shutdown, user login, and logout.
Hands on practice
The above introduces the Linux installation and login commands, and here are a few examples to practice the commands just mentioned.
1. Run multiple commands at a time
Multiple commands can be executed on a command line, separated by semicolons, for example:
# last-x
The above code indicates that the computer is turned off after the history of system shutdown, user login, and logout is displayed.
two。 Using mount mount file system to access Windows system
Many Linux distributions now automatically load Vfat partitions to access the Windows system, while each version of Red Hat does not automatically load Vfat partitions, so manual manipulation is required.
Mount
You can connect the Windows partition to the / mnt directory by connecting the Windows partition to an empty folder in Linux as a "file" of Linux. Because of
Here, just accessing this folder is equivalent to accessing the partition. First, to create the winc folder under / mnt, enter the following command at the command prompt:
# mount-t vfat / dev/hda1 / mnt/winc
That is,
Means to hang the C partition of Windows to the / mnt/winc directory of Liunx. At this point, you can see the contents of disk C in Windows in the / mnt/winc directory. Make
The D and E disks of the Windows system can be accessed by a similar method. The general order in which the partition of Windows is displayed in the Linux system is as follows: hda1 is disk C, hda5 is disk D,
Hda6 is E disk. and so on. The above method shows that there is a big problem with the Windows system, that is, all Chinese file names or folder names in Windows are displayed as question marks.
"?" But English can be displayed normally. We can make it display in Chinese by adding some parameters. Also take the above operation as an example, enter the command at this time:
# mount-t vfat-o iocharset=cp936 / dev/hda1 / mnt/winc
Now it can display Chinese normally.
3. Use mount to mount the file system on the flash drive
Using flash drives under Linux is very easy. Linux has good support for USB devices. When the flash drive is inserted, the flash drive is recognized as an SCSI disk, usually entering the following command:
# mount / dev/sda1 / usb
You can add the file system on the flash drive.
A little knowledge
Linux command and Shell
So
Called Shell, is the command interpreter, it provides a programming interface, you can use programs to program. Learning Shell is very important for Linux beginners to understand the Linux system.
As the shell of the operating system, the Shell of the Linux system provides users with the interface to use the operating system. Shell is the general name of command language, command interpreter and programming language.
The interface program between Linux kernels. If you think of the Linux kernel as the center of a sphere, Shell is the outer layer around the kernel. When life is passed to Linux from Shell or other programs
The kernel will react accordingly. The role of Shell in Linux system and COMMAND.COM and Windows 95 under MS DOS
Explorer.exe is similar. Although Shell is not a part of the system core, it is only an extension of the system core, but it can call most of the functions of the system kernel. Therefore, it can be said that
Shell is the most important utility for Unux/Linux.
There are many types of Shell in Linux, of which Bourne is the most commonly used
Shell (sh), C Shell (csh) and Korn Shell (ksh). The default Shell for most Linux distributions is Bourne
Again Shell, which is an extension of Bourne Shell, or bash for short, is fully backward compatible with Bourne Shell and is available in Bourne
Many features have been added to Shell. Bash is placed in / bin/bash and can provide functions such as command completion, command editing, and command history tables. It also contains a lot of C.
Shell and Korn
The advantages of Shell are flexible and powerful programming interface as well as friendly user interface. Among the more than 200 commands in Linux system, 40 are internal commands of bash, mainly including
Exit, less, lp, kill, cd, pwd, fc, fg, etc.
60 commands that must be learned in Linux (2)-File processing commands
Linux
System information is stored in files, which are similar to ordinary official documents. Each file has its own name, content, storage address and other management information, such as the user of the file, the size of the file, and so on. The file can be
A letter, an address book, or the source statement of a program, the data of a program, and even executable programs and other non-text content.
Linux file system has a good structure, the system provides a lot of file processing programs. This paper mainly introduces the commonly used file processing commands.
File
1. The content of the function determines the file type, and the permission is for all users.
two。 Format
File through the probe text
File [options] file name
3. [options] main parameters
-v: displays version information after standard output and exits.
-z: detects compressed file types.
-L: allow matching connections.
-f name: reads the list of file names to analyze from the file namefile.
4. Simple explanation
Using the file command, you can know whether a file is a binary (ELF format) executable, an Shell Script file, or some other format. The file types that file can recognize are directories, Shell scripts, English text, binary executable files, C language source files, text files, and DOS executable files.
5. Application example
If we see a file grap without a suffix, we can use the following command:
$file grap
Grap: English text
At this point, the system shows that this is an English text file. It is important to note that the file command cannot detect multimedia file types, including graphics, audio, video, and so on.
Mkdir
1. Action
The purpose of the mkdir command is to create a subdirectory named dirname, which is similar to the md command under MS DOS and has permissions for all users.
two。 Format
Mkdir [options] directory name
3. [options] main parameters
-m,-- mode= mode: set permissions, similar to chmod.
-p,-- parents: create an upper-level directory if needed; if the directory already exists, it is not considered an error.
-v,-- verbose: information is displayed every time a new directory is created.
-- version: leave after the version information is displayed.
4. Application example
The permissions of the directory can be set when creating the directory, and the parameter used in this case is "- m". Assuming that the directory name you want to create is "tsk" so that all users have rwx (that is, read, write, and execute permissions), you can use the following command:
$mkdir-m 777 tsk
Grep
1. Action
The grep command can specify that specific content be searched in the file and standard output the lines containing that content. The full name of grep is Global Regular Expression Print, which represents the global regular expression version, and its permission is for all users.
two。 Format
Grep [options]
3. Main parameters
[options] main parameters:
-c: outputs only the count of matching rows.
-I: case-insensitive (for single characters only).
-h: the file name is not displayed when querying multiple files.
-l: when querying multiple files, only the file names that contain matching characters are output.
-n: displays matching lines and line numbers.
-s: does not display error messages that do not exist or have no matching text.
-v: displays all lines that do not contain matching text.
The main parameters of the pattern regular expression:
\: ignore the original meaning of special characters in regular expressions.
^: matches the start line of the regular expression.
$: matches the end line of the regular expression.
\: to the end of the line matching the regular expression.
[]: single character, such as [A], that is, A meets the requirements.
[-]: range, such as [Amurz], that is, A, B, C all the way up to Z meet the requirements.
. All single characters
*: there are characters, and the length can be 0.
Positive
Then expression is a very important concept in Linux/Unix system. A regular expression (also known as "regex" or "regexp") is a pattern that can describe a class of strings
(Pattern). If a string can be described by a regular expression, we say that the character matches the regular expression (Match). This and DOS users can use wildcards
"*" represents any character similar to it. On Linux systems, regular expressions are often used to find patterns for text, as well as to perform search-and-replace operations and other functions on text.
4. Application example
Check
Querying the DNS service is one of the daily tasks, which means maintaining a large number of IP addresses covering different networks. Sometimes there are more than 2000 IP addresses. If you want to check the nnn.nnn network address, but forget it
The rest of the second part only knows that there are two periods, such as nnn nn... To extract all the nnn.nnn IP addresses from it, use [0mur9]\ {3
\}\. [0Mutual 0\ {3\}\. The meaning is that any number appears three times, followed by a period, followed by a period.
$grep'[0Musi 9]\ {3\}\. [0mur0\ {3\}\ 'ipfile
In addition, the grep family also includes fgrep and egrep. Fgrep is a fix grep that allows you to find strings rather than a pattern; egrep is an extended grep that supports basic and extended regular expressions, but does not support the application of the\ Q pattern range and some of the more standardized patterns corresponding to it.
Dd
1. Action
The dd command is used to copy files and convert and format data based on parameters.
two。 Format
Dd [options]
3. [opitions] main parameters
Bs= bytes: force ibs= and obs=.
Cbs= bytes: specified for each conversion.
Conv= keyword: converts files based on how they are represented by comma-delimited keywords.
Number of count= blocks: only the specified input data is copied.
Ibs= bytes: read the specified bytes each time.
If= files: read content, not standard input data.
Obs= bytes: write the specified byte each time.
Of= file: writes data instead of displaying it in standard output.
Number of seek= blocks: skip the specified output data in obs first.
Number of skip= blocks: skip the specified input data in ibs first.
4. Application example
The dd command is often used to make a Linux boot disk. Find a bootable kernel so that its root device points to the correct root partition, and then use the dd command to write it to the floppy disk:
$rdev vmlinuz / dev/hda
$dd if=vmlinuz of=/dev/fd0
The above code shows that using the rdev command to point the root device in the bootable kernel vmlinuz to / dev/hda, please replace "hda" with your own root partition, and then use the dd command to write the kernel to the floppy disk.
Find
1. Action
The function of the find command is to search for files in the directory, and its permission is for all users.
two。 Format
Find [path] [options] [expression]
Path specifies the directory path, from which the system starts looking down the directory tree for files. It is a list of paths separated from each other by spaces. If you do not write path, it defaults to the current directory.
3. Main parameters
[options] parameters:
-depth: use the depth-level search process to find the contents of files first in a specified directory at a certain layer.
-maxdepth levels: indicates that at most the level subdirectory of the start directory can be found. Level is a non-negative number, and if level is 0, it means to look only in the current directory.
-mindepth levels: indicates that at least the level subdirectory of the start directory is found.
-mount: do not look in directories and files of other file systems (such as Msdos, Vfat, etc.).
-version: printed version.
[expression] is a matching expression, an expression accepted by the find command, and all operations of the find command are directed against the expression. It has a lot of parameters, and only some commonly used parameters are introduced here.
-name: wildcard characters * and? are supported.
-atime n: search for files that have been read in the past n days.
-ctime n: search for files that have been modified in the past n days.
-group grpoupname: search for all files whose group is grpoupname.
-user user name: search for all files that belong to a user name (ID or name).
-size n: search for files whose file size is n block.
-print: output the search results and print them.
4. Application skills
There are several ways for the find command to find files:
(1) search based on file name
For example, if we want to find a file with the file name lilo.conf, we can use the following command:
Find /-name lilo.conf
The "/" after the find command means to search the entire hard disk.
(2) quickly find files
Root
A practical problem with finding files by file name is that it takes quite a long time, especially when large Linux file systems and large hard disk files are placed in deep subdirectories. If we find out,
This file is stored in a directory, so just looking down in that directory can save a lot of time. For example, the smb.conf file, judging from its file suffix ".conf", is a match.
Set the file, then it should be in the / etc directory, at this point you can use the following command:
Find / etc-name smb.conf
In this way, you can shorten the time by using the Quick find File method.
(3) search method according to some file names
Sometimes we know that only one file contains the word abvd, so to find all the files in the system that contain these four characters, enter the following command:
Find /-name'* abvd*'
After entering this command, the Linux system will look in the / directory for all files containing the four characters of abvd (where * is a wildcard), such as abvdrmyz and other eligible files can be displayed.
(4) use hybrid search method to find files.
The find command can use a hybrid lookup method. For example, if we want to find a file in the / etc directory that is larger than 500000 bytes and is modified within 24 hours, we can use-and (and) to link the two lookup parameters together to form a hybrid lookup.
Find / etc-size + 500000c-and-mtime + 1
Mv
1. Action
The mv command is used to rename a file or directory, or to move a file from one directory to another, with permissions for all users. This command is like a combination of ren and move in the DOS command.
two。 Format
Mv [options] Source file or directory destination file or directory
3. [options] main parameters
-I: operate interactively. If the mv operation will result in an overwrite of an existing target file, the system asks whether to rewrite and asks the user to answer "y" or "n" to avoid mistakenly overwriting the file.
-f: interoperability is prohibited. The mv operation does not give any indication when it wants to overwrite an existing target file, and the I parameter will no longer work when this parameter is specified.
4. Application example
(1) move all files in / usr/cbu to the current directory (with "." Represents):
$mv / usr/cbu/ *.
(2) rename the file cjh.txt to wjz.txt:
$mv cjh.txt wjz.txt
Ls
1. Action
The ls command is used to display the contents of the directory, similar to the dir command under DOS, with permissions for all users.
two。 Format
Ls [options] [filename]
Main parameters of 3.options
-a,-- all: do not hide anything with "." The item at the beginning of the character.
-A,-- almost-all: list any items except "." and "..".
-- author: print out the author of each document.
-b,-- escape: represents unprintable characters in octal overflow sequences.
-- block-size= size: the block is in specified bytes.
-B,-- ignore-backups: does not list any items that end with the ~ character.
-f: no sorting,-aU parameter takes effect,-lst parameter is invalid.
-F,-- classify: add an indication of the file type (* / = @ | one of them).
-g:like-l, but do not list owner.
-G-- no-group:inhibit display of group information.
-I,-- inode: lists the inode number of each file.
-I,-- ignore= style: no items that match the Shell universal characters are printed.
-k: namely-- block-size=1K.
-l: lists information in a longer format.
-L,-- dereference: when the file information of a symbolic link is displayed, the object indicated by the symbolic link is displayed, not the information of the symbolic link itself.
-m: all items are separated by commas and fill the entire line width.
-n,-- numeric-uid-gid: similar to-l, but list UID and GID numbers.
-N,-- literal: lists unprocessed project names, such as no special handling of control characters.
-p,-- file-type: add an indication of the file type (/ = @ | one of them).
-Q,-- quote-name: enclose the project name in double quotes.
-r,-- reverse: in reverse order.
-R,-- recursive: lists all subdirectory layers at the same time.
-s,-- size: in order of block size.
4. Application example
Ls
Command is the most frequently used command in Linux system, and its parameters are also the most frequently used in Linux commands. There are several different colors when using the ls command, where blue indicates a directory and green indicates an executable
Line files, red indicates compressed files, light blue indicates linked files, bold black indicates symbolic links, and gray indicates files of other formats. The most common use of ls is ls- l, as shown in figure 1.
Figure 1 using the ls-l command
Article
The item type begins with a string of 10 characters. The first character represents the file type, which can be one of the following types:-(normal file), d (directory), l (symbolic link), b (block device text)
C (character device file). The next nine characters represent the access to the file, divided into three groups, each with 3 bits. The first group represents the permissions of the master, the second group represents the permissions of the users in the same group, and the third group represents the permissions of the users in the same group.
The permissions of his users. The three characters in each group represent read (r), write (w), and execute permissions (x) to the file, respectively. For directories, entry permissions. S means that when the file is executed, the UID of the file
Or the UID (user ID) or GID (group) assigned by GID to the execution process
ID). T means to set the flag bit (stay in memory and not be swapped out). If the file is a directory, the files in that directory can only be deleted by the superuser, the directory owner, or the file owner. If it is an executable text
The pointer to its body segment remains in memory after the file is executed. This way, when it is executed again, the system can load the file more quickly. This is followed by the file size, generation time, file or command name
Say.
Diff
1. Action
The diff command is used to compare two files and points out that the difference between the two is that it has permissions for all users.
two。 Format
Diff [options] Source file target file
3. [options] main parameters
-a: treat all files as text files.
-b: the difference caused by ignoring spaces.
-B: the difference caused by ignoring blank lines.
-c: use the outline output format.
-H: use heuristics to speed up the search for large files.
-I: ignore case changes.
-n-- rcs: output RCS format.
Cmp
1. Action
The cmp (abbreviation for "compare") command is used to briefly indicate whether there is a difference between the two files, and its permission is for all users.
two。 Format
Cmp [options] file name
3. [options] main parameters
-l: output bytes in decimal mode, and facilitate the output of different files in octal mode.
Cat
1. Action
The cat (abbreviation for "concatenate") command is used to connect and display information about one or more specified files, and its permissions are for all users.
two。 Format
Cat [options] File 1 File 2...
3. [options] main parameters
-n: number the number of lines of all output starting from the first line.
-b: similar to-n, except that blank lines are not numbered.
-s: when you encounter blank lines with more than two consecutive lines, replace them with blank lines on one line.
4. Application example
(1) one of the simplest uses of the cat command is to display the contents of a text file. For example, if we want to see the contents of the README file on the command line, we can use the command:
$cat README
(2)
Sometimes you need to process several files into a single file and save the results of this processing to a separate output file. The cat command accepts one or more files on its input and treats them as a separate file
Print to its output. For example, after numbering the contents of README and INSTALL files (no blank lines), append the contents to a new text file, File1:
$cat README INSTALL File1
(3) another important function of cat is the ability to number rows, as shown in figure 2. This function is convenient for the preparation of program documentation, as well as legal and scientific documentation, and the line number printed on the left makes it easy to reference a part of the document. these are very important in programming, scientific research, business reports and even legislative work.
Figure 2 numbering using the cat command / etc/named.conf file
The line numbering function has two parameters:-b (only non-blank lines can be numbered) and-n (all lines can be numbered):
$cat-b / etc/named.conf
Ln
1. Action
The ln command is used to create links between files, and its permissions are for all users.
two。 Format
Ln [options] Source file [link name]
3. Parameters.
-f: delete the source file when linking.
-d: allows system administrators to hard-link their own directories.
-s: soft link (Symbolic Link).
-b: back up files that will be overwritten or deleted when linked.
There are two kinds of links, one is called Hard Link, the other is called symbolic link (Symbolic Link). By default, the ln command produces hard links.
Hard
A connection is a connection made through an index node. In Linux's file system, files saved in disk partitions, regardless of type, are assigned a number called index node number (Inode)
Index). In Linux, it is possible to have multiple file names pointing to the same Inode. Generally speaking, this kind of connection is a hard connection. The purpose of a hard connection is to allow a file to have multiple valid pathnames, so that the user
You can establish a hard connection to important files to prevent "accidental deletion" function. The reason is as mentioned above, because there is more than one connection to the index node of the directory. Deleting only one connection does not affect the Inode itself and the
For other connections, only when the last connection is deleted will the connection between the data block of the file and the directory be released. In other words, the file will really be deleted.
Corresponding to the hard connection, there is another kind of connection in the Lnux system, which is called symbolic connection (Symbilc Link), also called soft connection. Soft-link files are a bit like Windows shortcuts. It is actually a kind of special file. In symbolic links, a file is actually a text file that contains information about the location of another file.
Hands on practice
Above we introduced the Linux file processing commands, here are a few examples, you can start to practice the commands just mentioned.
1. Use symbolic links to quickly access key directories
Symbol
The number link is a very practical function. Suppose there are some directories or files that need to be used frequently, but because of the file and directory structure of Linux, this file or directory is in a very deep subdirectory. such as,
Apache
The Web server documentation is in the / usr/local/httpd/htdocs of the system, and you don't want to enter such a long path from the home directory every time (in fact, this path is also
It's not easy to remember.
To solve this problem, you can create a symbolic link in the home directory so that when you need to enter that directory, you only need to go to that link.
To easily access the directory where the Web server (/ usr/local/httpd/htdocs) documents are located, you can use the following command in the home directory:
$ln-s / usr/local/httpd/htdocs gg
In this way, every time you enter the gg directory, you can access the documents of the Web server. In the future, if you no longer access the documents of the Web server, you can delete the gg, but the documents of the real Web server are not deleted.
two。 Use the dd command to import root.ram content in init.rd format into memory
Dd if=/dev/fd0 of=floppy.fd
Dd if=root.ram of=/dev/ram0 #
3.grep command system call
Grep is one of the most widely used commands in Linux/Unix and can be called internally by many Linux systems.
(1) if you want to query the directories in the directory list, the method is as follows:
$ls-l | grep '∧ d'
(2) if you query all files that do not contain a directory in a directory, the method is as follows:
$ls-l | grep '∧ [∧ d]'
(3) call grep with the find command, such as "Chinput" in all C source code, as follows:
$find / ZhXwin-name * .c-exec grep-Q-s Chinput {}\;-print
60 commands that Linux must learn (3)-system Management Command
Linux must learn system management commands
For the Linux system, no matter the CPU, memory, disk drive, keyboard, mouse, or users are all files, the command managed by the Linux system is the core of its normal operation. Once you are familiar with the commonly used file processing commands in Linux, this lecture introduces commands for managing the system and users.
Df
1. Action
The df command is used to check the disk footprint of the file system, with permissions for all users.
two。 Format
Df [options]
3. Main parameters
-s: only the total number of blocks occupied is given for each Names parameter.
-a: recursively displays the number of data blocks occupied by each file in the specified directory and in each subdirectory. If neither-s nor-an is specified, only the number of disk blocks occupied by each directory and its subdirectories in the Names is displayed.
-k: lists disk space usage in 1024 bytes.
-x: directories skipped on different file systems are not counted.
-l: calculate all file sizes and multiple times for hard-linked files.
-I: displays inode information instead of block usage.
-h: print out the file system size in an easy-to-understand format, such as 136KB, 254MB, 21GB.
-P: use the POSIX output format.
-T: displays the file system type.
4. Description
The df command is widely used to generate file system usage statistics, which can display information about all file systems in the system, including total capacity, available free space, current mount points, and so on.
Super
When using the df command, level-level users will find that the capacity of a partition exceeds 100%. This is because the Linux system reserves 10 per cent of the space for superusers, which is at their disposal. That is,
Said that for the superuser, the hard disk capacity he saw would be 110%. This arrangement is good for system management, and the system administrator can be normal when the capacity of the hard disk is close to 100%.
Work.
5. Application example
Linux supports many file systems, including JFS, ReiserFS, ext, ext2, ext3, ISO9660, XFS, Minx, vfat, MSDOS, and so on. You can also get information about the file system when you use the df-T command to view disk space:
# df-T
File system type capacity used available used mount point
/ dev/hda7 reiserfs 5.2G 1.6G 3.7G 30% /
/ dev/hda1 vfat 2.4G 1.6G 827M 66% / windows/C
/ dev/hda5 vfat 3.0G 1.7G 1.3G 57% / windows/D
/ dev/hda9 vfat 3.0G 2.4G 566m 82% / windows/E
/ dev/hda10 NTFS 3.2G 573M 2.6G 18% / windows/F
/ dev/hda11 vfat 1.6G 1.5G 23m 99% / windows/G
From the above, you can see not only the capacity and usage of disk space, but also the file system type and mount point of the partition.
Top
1. Action
The top command is used to display the progress of the program in execution, and the permission is for all users.
two。 Format
Top [-] [d delay] [Q] [c] [S] [s] [n]
3. Main parameters
D: specifies the interval between updates, measured in seconds.
Q: there are no delayed updates. If the user has a superuser, the top command will be executed in the highest priority.
C: displays the full path and name of the process.
S: cumulative mode, which accumulates the CPU time of subtrips that have been completed or disappeared.
S: safe mode.
I: do not show any idle (Idle) or useless (Zombie) itinerary.
N: displays the number of updates, and will exit top after completion.
Thank you for reading this article carefully. I hope the article "what must be learned in linux" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.