Linux system management command
Wall Command Function: The function of this command is to send information to all logged in users. Users can write the information you want to send in a file, then enter: # Wall
SYNC Command Features: The sync command is used when turning off the Linux system. Users need to note that the system cannot shut down the system with a simple shutdown power, because the Linux is like other UNIX systems, many data is cached in memory, and the memory data and the hard disk data are required to check, guarantee when shutting down the system. Hard disk data is the latest in shutting down the system, only this can ensure that the data will not be lost. The process of generally normal shutdown systems is automatically performed, and it is also required to do this during the system operation, and user intervention is required. The SYNC command is forced to write data in memory back to the hard disk to prevent data loss. Users can use this command when needed. Format: Sync Shutdown Command Function: The shutdown command secures or restarts the Linux system safely, which prompts all the login users on the system before the system is turned off to a warning message. This command also allows the user to specify a time parameter, which can be a precise time or a time period from now. The exact time is format is HH: mm, represents hours and minutes; the time period is represented by " " and minutes. After the system executes this command, the data synchronization is automatically performed. Format: Shutdown [Option] [Time] [Warning Information] Parameters: - K does not really shut down, but just issue a warning message to all users. - Retart immediately after shutdown. - The h is turned off after shutdown. - f Qu quickly and skips FSCK when restarting. - n Quick shutdown, no init program. - C Cancel a rundown that has been run. It is important to specify that this command can only be used by superuser. Example 1: The system is turned off after ten minutes and will be restarted immediately. # Shutdown - R 10 Case 2: The system is turned off immediately and does not restart. # Shutdown - h Now free command function: The feature of the free command is to view the usage of the current system memory, which displays the remaining and used physical memory and swap memory in the system, and shared memory and the core used buffer. Format: Free [-b | -k | -m] parameter: -b Displayed in bytes. -K is displayed in k bytes. -M is displayed in megabytes. Example: $ free Total Used Free Shared Buffers Cached Mem: 63076 32020 31056 8204 16360 6048 - / Buffers / Cache: 9612 53464 SWAP: 64476 2240 62236UPTIME Command function: UPTIME command display system has run how long, it displays the following Information: Now, how long it has been running, how many login users are currently available, and the system has an average load in the past 1 minute, 5 minutes and 15 minutes. Format: UPTIME Example: # uptime 4:43 PM Up 1 Day, 5:51, 2 User, Load Average: 0.01, 0.01, 0.00 Linux and user-related commands
For system security, each user in the Linux system has its own user password except for its username. Therefore, when using the Useradd command to increase, you also need to use the passwd command to set your password for each newly added user; users can change their passwords with the passwd command. The general format of this command is: Passwd [User Name] where the username is the username that needs to modify the password. Only super users can use the "PasswD User Name" to modify the passwords of other users, and ordinary users can only modify their own passwords with the Passwd command without parameters. The method of this command is as follows: Enter passwd
Syntax: RMDIR [Option] DIRNAME Description: DIRNAME represents a directory name. This command deletes one or more subdirectories from a directory. It is important to note that a directory must be empty before being deleted. (Note that the RM - R DIR command can replace RMDIR, but there is a big risk.) You must also have write access to the parent directory when deleting a directory. Parameters: - P Removable Delete Directory DirName, which is also deleted when the child catalog is empty after delete. If the entire path is deleted or reserved for some reason, the system displays the corresponding information on the standard output. For example: $ RMDIR - P / USR / XU / TXT deletes the / usr / xu / txt directory. Change the working directory, display the directory content command CD command function: Change the work directory. Syntax: CD [Directory] Description: This command changes the current directory to the directory specified by Directory. If Directory is not specified, return to the user's home directory. In order to change to the specified directory, the user must have execution and read permissions to the specified directory. This command can use wildcards (see Chapter 10 of the wildcard mean). For example: Suppose the user's current directory is: / home / xu, now you need to replace it to the / home / xu / pro directory, $ CD PRO At this point, the user can execute the PWD command to display the work directory. $ PWD / HOME / XU / PRO PWD Command Features: In the Linux hierarchical directory structure, users can create a new directory with the mkdir command in an authorized directory, or use the CD command to switch from a directory to another. However, there is no prompt to tell the user which directory is currently in. To know the current directory, you can use the PWD command that displays the entire path name. Syntax: PWD Description: This command shows the absolute path of the current work directory. Example: $ PWD / Home / XU Displayed The path name is / home / XU, each directory name is separated by "/", the root directory is indicated by "/". LS command function: LS is a short-term English word List, which is functional to list the contents of the directory. This is one of the most common commands of users, as users need to view the content of a certain directory from time to time. This command is similar to the DIR command under DOS. Syntax: LS [Option] [Directory, or File] For each directory, this command will list all subdirectories and files. For each file, the LS will output its file name and other information required. By default, the output entries are sorted in alphabetical order. When the directory name or file name is not given, the current directory is displayed. Parameters: - A Displays all subdirectories and files in the specified directory, including hidden files. - a Display all subdirectories and files in the specified directory, including hidden files. But not listed "." And "..". - b Display the non-display character in the file name with an octal escape character. - c Sort by the modification time of the file. - C is divided into multiple columns display. - D If the parameter is a directory, only its name is displayed without displaying each file. Often use together with the L option to get detailed information on the directory. - f is not sorted. This option will make the LTS option to fail and make the AU options are valid. - f Tag "/" after the directory name "/", the executable "*", the symbol link is marked "@", the pipe (or FIFO) after marking "@", pipe (or FIFO), "=" after the SOCKET file. - i Node i node I display file in the first column output. - l Details of the file in a long format. This option is most commonly used.
The information listed in each line is: File Type and Permissions Link Document The main file genus file size creates or recently modified time names After the symbolic link file, the displayed file name has "->" and reference file path name. For device files, its File Size field displays the primary, secondary device number, not the file size. The total number of numbers in the directory displays the beginning of the long format list, which contains an indirect block. - L If the specified name is a symbolic link file, the file pointed to by the link is displayed. - m Output by a character flow format, the file is displayed, and the comma is separated. - N The output format is the same as the L option, but only in the output of the file owner and the group group are represented by the corresponding UID number and the GID number, not the actual name. - O is the same as the L option, but does not display the owner information. - p After adding a "/" behind the directory. - q Use "?" Instead of "?" In the file name. - r Displays the output results in an alphanist or first priority order. - R Credit Displays files in each subdirectory of the specified directory. - S gives the number of blocks used in each directory, including indirect blocks. - T is displayed in the modification time (recently priority) instead of by the name. If the file modification is the same, it is in the dictionary order. The modification time depends on whether C or U selection is used. The default time tag is the last revision time. - U shows the time (recently priority) of the last file (recently) instead of being sorted by name. The time tag of -t is to modify to the last time. - X The information of each row is displayed by row. -------------------------------------------------- -------------------------------------------------- - In the information displayed by the ls - l command, the beginning is a string consisting of 10 characters, where the first character represents the file type, which can be one of the following types: - Ordinary file D directory L Sign Link B The 9 characters behind the device file C character device file represents the access rights of the file, divided into 3 groups, 3 digits per group. The first group represents the authority of the file owner, the second group represents the authority of the same group, and the third group represents the permissions of other users. The three characters of each group indicate read, write, and execution permissions for files, respectively. Each permission is as follows: R read W writes X execution. For the directory, it means enters permissions. S When the file is executed, the UID or GID of the file is given the UID (user ID) or GID (group ID) of the process. T Set the flag bit (stay in memory, not being swapped out). If the file is a directory, the files in this directory can only be deleted by the superuser, directory owner, or file owner. If it is an executable file, after the file is executed, the pointer to its positive segment remains in memory. This will then load the file faster when it is executed again. - No permissions are set. -------------------------------------------------- -------------------------------------------------- - Example 1: List the contents of the current directory. $ LS -F BIN / LIB / VAR / ETC / TMP / INDEX. HTML Example 2: Lists the content of a directory. $ Ls -f / home / xu mai1 / map1e / mm / ptr / telnetd * fd / mbox mount sobsrc. TGZ TMP / Example 3: List all files in a directory (including hidden files).
$ 1S -AF / Home / Xu ./. .E1m / .Netscape / Map1E Ptr / ../ .fvwin2rc95 .Term / Mbox Sobsrc. TGZ .xAuthority .kermrc MAI1 / MM / TE1NETD * .BASH-HISTORY .NCFTP / FD / MOUNT TMP / Example 4: List all files in a directory (including hidden files) with long formats. $ 1S -LAF / Home / XR-X L2 root root 1024 NOV 02 22:07 ./ DRWXR-XR-X 15 BBS BBS 1024 JUL 29 07:08 ../ -rw-r - r - 1 yu uses 4343 ju1 29 22:20 .bash-history drwx ------ 2 yu users 1024 May 17 06:36 .e1m / --rw ------ 1 root root 4628 JUN 2 1L : 34 MBOX LRWXRWXRWX 1 ROOT ROOT L4 JU1 29 03:08 Mount -> / MNT DRWXRWXR-X 4 Root Root 1024 JU1 23 03:43 PTR / -RW - R - R- 1 Root Root 483997 JU1 L5 17: 3L Sobsrc. TGZ -RWXR-XR-X L Root Users 60177 JUN 8 01:29 Telnetd * DRWXR-XR-X 2 Root Root 1024 Mar 6 22:32 TMP / Example 5: List all of a directory with a long format The files include hidden files and their I node numbers. And display the file owner and group in the form of UID number and GID. $ 1S -1AINF / Home / Xu Tota1 584 399672 DRWXR-XR-X L2 0 0 L024 NOV 30 22:07 ./333907 DRWXR-XR-X 15 9999 99 L024 JU1 29 07:08 .:/ 39980l -RW-- ----- L 0 0 0 JUN 2 2:09.xauthority 399679 -RW-R - R - 1 505 l00 4343 Jul 29 22:20 .bash-hist0ry 30L763 DRWXR ----- 2 505 100 l024 May 17 06:36 .e1m / ... Linux change file or directory access to each file and directory in the Linux system have access license permissions, use it to determine who can access files and directories And operation. The access rights of the file or directory are divided into read-only, only three kinds of only written and can be implemented. Take a document as an example, read-only authority represents only the contents of its content, but prohibits any changes to do anything. The executable permission indicates that the file is allowed to be executed as a program. When the file is created, the file owner automatically has read, write, and executable permissions to the file to facilitate reading and modification of the file. Users can also set access to any combination of access as needed. There are three different types of users to access files or directories: file owners, group users, other users. Everyone is generally the founder of the file. Owners allow the same group of users to have access to files, and access to other users in the system. In this case, each user in the system can access the file or directory owned by the user. There are three groups of access to each file or directory. Each group is represented by three representations, respectively, write and execute permissions, read, write and execute permissions from the owner's associated group; User read, write, and execute permissions. When the details of the file or directory are displayed with the LS -L command, the leftmost list is the file access.
For example: $ ls -l sobsrc. TGZ -RW-R - R - 1 Root Root 483997 JU1 L5 17: 3L Sobsrc. TGZ horizontal line represents empty license. R represents read-only, W is written, and X represents executable. Note that there are 10 locations here. The first character specifies the file type. In the usual sense, a directory is also a file. If the first character is a horizontal line, it is a non-directory file. If D, it is a directory. For example: - rw- r - R - Normal file file main group user Other users are access to file SOBSRC.TGZ, indicating that Sobsrc.tgz is a normal file; Sobsrc.tgz's home owner has read and write permissions; with SOBSRC The .TGZ is the user's user only read the permissions; other users only have read rights. After identifying the access permission of a file, the user can use the chmod command provided by the Linux system to reset different access rights. You can also use the chown command to change the owner of a file or directory. Use the chGRP command to change the user group of a file or directory. These commands are described below. Chmod Command Features: The chmod command is very important for changing access to files or directories. Users use it to control files or directory access. Syntax: This command has two usage. One is a text setting method containing letters and operator expressions; the other is a digital setting method containing numbers. 1. Text setting method chmod [WHO] [ | - | =] [MODE] file name? Parameter: Operation object WHO, any one of the following or a combination: u Represents "User", That is, the owner of the file or directory. G indicates that "Group) users, that is, all users with the owner of the file owner. O Represents "other (others) users. A Represents "All (all) users. It is the system default value. The operation symbol can be: Add a certain permission. - Cancel a certain permission. = Give a given permissions and cancel all all permissions (if any). Set the permissions represented by MODE available to any combination of the following: r readable. W can be written. X can be executed. X Only the X attribute is added to some users if the user is executable or the target file is a directory. S The owner or group ID of the process is set to the file owner of the file when executed. The user ID bit of the "U S" setting file, "G S" sets the group ID bit. T Save the program's text to the switch. U Have the same authority with the owner of the file. G has the same permissions with users of the owner of the file. O Have the same permissions from other users. File Name: Separate the list of files to change permissions, support wildcard. Multiple permissions can be given in a command line, and there is a comma. For example: CHMOD G R, O R EXAMPLE makes the group and other users read permissions to file EXAMPLE. 2. Digital Settings We must first understand the meaning of the attribute represented by the number: 0 means no permissions, 1 means executable permissions, 2 indicate that can be written, and then add it. Therefore, the format of the digital attribute should be 3 binary numbers from 0 to 7, and the order is (U) (G) (O).
For example, if you want to have two permissions to "read / write", you need to write 4 (read / write) = 6 (read / write). General form of digital setting method is : Chmod [MODE] file name? Example: (1) Text setting method: Example 1: $ chmod a x sort, setting file sort's properties: file owner (u) increase execution permission and file owner Group User (G) Add Permissions Other User (O) Adding Execution Execution 2: $ ChMOD UG W, ox text is the property of setting file text: file owner (u) increase write permissions and file owners Group User (G) Increase Write Permissions Other User (O) Delete Execution Execution Example 3: $ ChMOD U S A.out assumptions Permissions for a.out after CHMOD (you can use the ls - l a.out command) : -Rws - x - x 1 ININ Uses 7192 Nov 4 14:22 A.out and this execution file To use a text file Shiyan1.c, its file access rights are "-rw ------ - "The file is only its owner has read and write permissions. When other users perform A.out this program, his identity is temporarily turned into inin (because the S option is used in the chmod command), so he can read the file (although this file is set) Do not have any permissions for others), this is the function of S. Therefore, in the entire system, in particular the root itself, it is best not to set up this type of file (unless necessary) to ensure the security of the system, avoiding the system to invading the system because of the BUG of some programs. Example 4: $ chmod a-x mm.txt $ chmod -x mm.txt $ chmod ugo-x mm.txt The above three commands are deleted with execution permission of the file mm.txt, which is set for all user. (2) Digital Setting: Example 1: $ CHMOD 644 mm.txt $ ls -l set file mm.txt properties: -rw-r - r - 1 inin users 1155 NOV 5 11:22 MM.TXT file owner (U) ININ has read, write permissions and file owner's same group users (G) Have read permissions Other (o) Have Read Rights 2: $ ChMOD 750 Wch.txt $ ls -l -rwxr-x --- 1 ISERS 44137 NOV 12 9:22 WCHTXT set the attribute of the WCHTXT this file is: File Master (U) ININ read / writable / executable rights and file main group people ( g) Readable / Execute Rights Other People (O) No Permissions CHGRP Command Features: Change the group of files or directories. Syntax: Chgrp [Option] Group filename? This command changes the user group to which the specified file belongs. Where Group can be a user group ID, or a group name of the user group in the / etc / group file.
The file name is a list of files that are separated by spaces to support wildcards. If the user is not the owner or super user of the file, the group of the file cannot be changed. Parameters: - r Cancellation Change the group of all subdirectories and files under the specified directory. Example 1: $ ChGRP - R Book / Opt / Local / Book Change / Opt / Local / Book / and Groups of All files in its subdirectory are BOOK. CHOWN Command Features: Change the owner and genus of a file or directory. This order is also commonly used. For example, the root user copies its own files to the user XU, in order to allow the user XU to access this file, the root user should set this file to XU, otherwise, the user XU cannot access this file. Syntax: Chown [Option] User or Group file Description: Chown changes the owner of the specified file to the specified user or group. The user can be a username or user ID. The group can be a group name or group ID. The file is a list of files that are separated by spaces to support wildcards. Parameters: - R Cancellation changes the owner of the specified directory and all the subdirectories and files. - v shows the work made by the chown command. Example 1: Change the owner of the file Shiyan.c to Wang. $ Chown Wang Shiyan.C Example 2: Change the owner of all files and subdirectories under the directory / HIS to wang, and the genus is changed to Users. $ Chown - r wang.users / hislinux file copy, delete, and move command CP command function: copy the file or directory to another file or directory, just like the COPY command under DOS, the function is very powerful. Syntax: CP [Option] Source File or Directory Target File or Directory Description: This command copies the specified source file to the target file or copy multiple source files to the target directory. Parameters: - A This option is usually used when copying the directory. It retains links, file properties, and recursively copys the directory, which is equal to the combination of DPR options. - Reserved link when D copy is copied. - f Delete the existing target file without prompting. - The I and F options are reversed, which will give a prompt before the target file is overwritten to require the user to confirm. When the answer y, the target file will be overwritten and is an interactive copy. - P At this point, CP will also copy its modification time and access to the new file in addition to copying the contents of the source file. - R If the source file given is a directory file, the CP will recursively copy all the subdirectory and files in the directory. At this point the target file must be a directory name. - l Does not copy, just link files. It should be noted that in order to prevent the user from using the CP command to use the CP command to destroy another file, such as the user-specified target file name is an existing file name, after copying the file with the CP command, this file will be newly copied. The source file is overwritten, so it is recommended that the user is best to use the I option when using the CP command to copy files. $ CP - I Exam1.c /usr/wang/shiyan1.c This command copies the file exam1.c into the / usr / wang this directory and renamed Shiyan1.c. If you don't want to rename it, you can use the following command: $ cp - r / usr / xu / / usr / liu / 将 / USR / XU directory all files and their subdirectories Copy to the directory / usr / liu. MV Command Features: Transfer your file or directory or transfer the file into another directory. This command is like a combination of REN and MOVE under DOS.
Syntax: MV [Option] Source File or Directory Target File or Directory Description: Different in the second parameter type in the mv command (Is the target file or target directory), the mv command renames the file or moves to a new one. Directory. When the second parameter type is a file, the mv command completes the file rename. At this time, the source file can only have one (or a source directory name), which rename the source file or directory to a given Target file name. When the second parameter is an existing directory name, the source file or directory parameter can have multiple, the MV command moves the source file specified by each parameter to the target directory. When moving files across file systems, the MV copy, then delete the original file, and the link to the file will also be lost. Parameters: - i interactive operation. If the MV operation will result in overwriting the existing target file, at which point the system is inquiry, requiring the user to answer Y or N, which avoids erroneous overwriting files. - F prohibits interactive operation. When the MV operation is to override an existing target file, the I option will no longer work after specifying this option. If the destination file (not a directory) already exists, the content of the file will be overwritten by the new file. To prevent the user from using the MV command to destroy another file in an inadvertent situation, it is recommended that the user is best to use the I option when using the MV command to move files. It should be noted that MV is different from the results of CP. MV seems to "moving", the number of files is increased, while CP is copied to the file, and the number of files is increased. Example 1: Move all files in / usr / x to the current directory ("."): $ Mv / usr / xu / *. Example 2: Rename the file wch.txt $ wjz.doc $ mv Wch.txt wjz.doc RM Command Function: Create files in Linux, it is easy to have files at any time in the system and useless access. Users can use the RM command to delete it. The functionality of this command is to delete one or more files or directories in a directory, and it can also be deleted with all the files and subdirectories under a directory. For link files, just delete links, the original file remains unchanged. Syntax: RM [Options] File ... If you do not use the RE option, RM does not delete the directory. Parameters: - f ignores files that do not exist, never given a prompt. - R indicates that RM is recursively deleted all directories and subdirectories listed in the parameters. - i interactively deleted. Be careful with the RM command. Because once a file is deleted, it cannot be recovered. For example, when entering the CP, MV or other commands, accidentally entered the RM command, when the user presses the Enter key and recognizes his own mistake, it is too late, the file is no longer. To prevent this happening, you can use the I option in the RM command to confirm each file to be deleted. If the user enters Y, the file will be deleted. If you enter anything else, the file will be retained. In the next example, the user wants to delete the file TEST and EXAMPLE. Each file will then be confirmed. The user finally decides to delete the Example file and retain the TEST file. $ RM - II TEST EXAMPLE REMOVE TEST? N Remove Example? Y Linux file content query command grep, fgrep and egrep command This set of commands in specifying the mode search file, and notify the user to search for characters that match the specified pattern Strings, and print out all the texts that contain the string, the most in front of the text is the file name where the line is located.
The grep command can only search for a specified mode at a time; the EGREP command retrieves the extended regular expression (including expression groups and options); the fgrep command retrieves the fixed string, which does not identify the regular expression, is a quick search command. This set of commands is useful in searching for specific themes in the location file. The mode to search for can be considered some keywords that you can use them to search these keywords included. When writing a program, you can use it to find a function, or the relevant phrase. The search function of the grep command is powerful than the FGRep, because the search mode of the grep command can be a regular expression, but FGREP cannot be. See the Shell chapter for regular expressions. Each command in this group command has a set of options that can be used to change its output. For example, you can add a line number on a searched text line, or only the line number of the text line, or output all the text lines that do not match the search mode, or simply output the file name that has been searched for the specified mode, and You can specify whether you write on mode when lookup mode. This group of commands find rows that match the pattern in the specified input file. If you do not specify a file, read it from the standard input. Normally, each matching row is displayed to the standard output. If the file to be found is multiple, add the file name before each row output. Syntax: GREP [Option] [Find Mode] [File Name 1, File Name 2, ...] EGREP [Option] [Find Mode] [File Name 1, File Name 2, ...] FGREP [Option] [Find Mode] [File Name 1, File Name 2, ...] Parameters: - E Each mode is treated as an extension regular expression. - F Each mode is treated as a set of fixed strings (separated from a new row) without as a regular expression. - b Displays the byte offset containing rows in the file in each line of the output. - c shows only the number of matches. - I don't care when comparison. - h When looking up multiple files, indicating that GREP does not to add a file name before the output. - l Displays the file name where the first matching string is located and disabled by the wrap. This file name is not repeated when a matching string is displayed many times in a file. - n The line number in which the matching string is added before the output (the file first line number is 1). - V Only rows that do not contain matching strings are displayed. - x shows only rows of strict matching of the whole line. - e expression specifies the mode of retrieval. The pattern used to prevent the beginning of "-" is interpreted as a command option. - f Expfile Gets the mode to search from the ExpFile file, and a pattern occupies a row. Use the use of the group command to pay attention to the following: Type the search mode after the command, type the file you want to search. Among them, special characters can also be used in the file name list, such as "*", etc. to generate a list of file names. If you want to include a space in the search mode, you can use single quotes to search for the mode to search, indicating that the search is composed of a string containing spaces. Otherwise, the shell will consider the space for the delimiter of the command line parameter, and the grep command will explain the words in the search mode as part of the file name list. In the example below, the grep command search mode "text file" in the file eXample. $ GREP 'TEXT FILE' EXAMPLE users can generate a list of file names that will search with SHELL special characters on the command line. In the following example, special characters "*" is used to generate a list of file names, which contains all files in the current directory. This command will search for rows that match all files in all files in the current directory. $ GREP DATA * Special characters are very useful when searching for a set of specified files. For example, if you want to search all the specific modes in all C program source files, you can use "* .c" to specify a list of file names.
Suppose the user's C program contains some unnecessary steering statements (GOTO statements), want to find these statements, can use the following command to search and display all code rows containing the GOTO statement: $ grep goto * .c user can Type a search mode on the command line, or you can use the -f option to read the mode to search from the specified file. In the file, each search mode occupies a row. This feature is very useful if you are searching for a set of common strings. In the following example, the user wants to search for the string "editor" and "create" in the file exam, put the mode to search in the file mypats, then the grep command reads the mode to search from the file mypats. $ Cat mypats editor create $ grep -f mypats Exam file lookup command find command function: Search files in the directory structure and perform the specified operation. This command provides considerable lookup conditions, which is very powerful. Syntax: Find start directory Search Conditions Operating Instructions: The Find command starts from the specified start directory, recursively searching its individual subdirectories, finds files that meet the search criteria and taking relevant operations. This command is provided with a composite condition that is composed of logical operators NOT, AND, OR. The meaning of logical operators and, or, NOT is: (1) AND: logic, in command, "-a" in command, is the system default option, indicating that only when the conditions given, looking for conditions Complete satisfaction. For example: $ find -name 'tmp'-type c -user 'inin' This command finds all the files that meet all the conditions. (2) OR: Logic or represented by "-o" in the command. The operator indicates that the search is satisfied as long as there is a satisfaction in the conditions given. For example: $ find -name 'tmp' -o -name 'mina *' This command query file name is 'TMP' or all files match 'mina *'. (3) NOT: Logic is not used in the command. The operator represents the file that is not satisfied with the condition. For example: $ find! -Name 'TMP' This command query file name is not all files of 'TMP'. It should be noted that when using a lot of logical options, these options can be enclosed in parentheses. In order to avoid the shell itself cause misunderstandings, it is necessary to add the sense character "//" before the voice number to remove the meaning of parentheses. Example: $ find // (- Name 'TMP' //) Looking for Conditions The following options: First, the n values in the following options can have three input mode, assuming that n is 20, then : 20 indicates that after 20 (21, 22, 23, etc.) -20 indicates 20 previous (19, 18, 17, etc.) 20 indicates that it is just 20 1. Looks with name and file attribute. - Name 'String' Find all files of the file name match the string of the string, the string can be used in wildcard *, []. - Lname 'String' Find File Name Matches All Symbol Link Files of the String String, and the wildcards available in the string *,?, []. -Gid n Find all files for user groups belonging to the ID number N. -UID N looks out all files of users belonging to the ID number N. -Group 'String' looks into all files that belong to the user group name as the string.
-user 'String' looks up all files belonging to the username as a given string. -Empty looks for directory or files of size zero. -Path 'String' Find all files of the path name match the string of the string, wildcards available in the string *,?, []. -Perm Permissions Find files and directories with specified permissions, and privileges may be as 711,644. -Size n [bckw] Find files for specified file size, n, indicating units, defaults B, represents 512 bytes of blocks. -type x Find the file file, X is one of the following characters: b Device file C Character Device file D Directory file P Named pipe (FIFO) F Ordinary file L Symbol Link file (SOMBOLIC LINKS) S socket file - type X is basically the same as -type, but only looks for symbolic link files. 2. Find out time for conditions - Amin N looks for all the files previously visited before. - Atime N looks for all the files previously visited before. - cmin n Find all the files modified by N minutes. - CTIME N looks for all files modified by N days before file status. - Mmin N looks for N minutes before the file content modified all files. - Mtime N looks for all files that have been modified by N days. 3. Executable Operation - Exec Command Name {} Performs the LINUX command to which the eligible file does not ask if the user needs to execute the command. {} Indicates the parameter of the command is the file found; the end of the command must end with "//;". - OK command name {} The Linux command given to the eligible file is different from the EXEC, which will ask if the user needs to execute the command. - LS details all the files found. - The FPRINTF file name writes the file name to the specified file. - Print displays the file name that looks out on the standard output device. - Please refer to the book about C language, please refer to the book about the C language. Example 1: Find all the files starting with main directory and display the contents of these files. $ FIND. - Name 'main *' - Exec More {} //; Example 2: Delete a .out or * .o file that has not been accessed within all weeks in the current directory. $ FIND. // (- Name a.out - o - name '* .o' //) //> - atime 7 - EXEC RM {} //; Description: "." in the command represents the current directory At this time, Find will start from the current directory, and find a file that satisfies the following specified conditions one by one in its subdirectories. / / (And //) indicate parentheses (), "//" is called an escar. The reason why writing is due to the other meaning of the shell, rather than the use of combination conditions here. "- Name a.out" refers to the file you want to find named A.out; "- Name '* .o'" means the file to find all the names to end .o. These two-name-o represents logic or (or), that is, the lookup name is a.out or name to end files ending with .o, find after the current directory and its subdirectories, then find this file Judgment, see if its final access time is 7 days (condition -Atime 7), if yes, the file is executed command RM (- EXEC RM {} //;).
The {} represents the file name that the currently asserting eligible, //; is required by the syntax. The last one of the first rows in the above command is a continuation. When the command is too long and you can't write, you can enter one //, then the system will display a>, indicating that the user continues to enter the command. Locate command function: locate command is used to find files, which is fast than the search speed of the Find command, which requires a database, which is created by a routine work (crontab) program. When we establish this database, you can easily search for the required files. Syntax: locate related words, for example,: lookup related words Issue $ locate Issue / etc / ssue /etc/issue.net /usr/man/man5/issue.5 /usr/man/man5/issue.net.5 Linux backup and compression Command users often need to back up data in the computer system, in order to save storage space, often compress the backup files. The commands for backup and compression are described below. TAR command role: TAR can create a file for files and directories. With TAR, users can create files for a particular file (backup file), or change files in the file, or add new files to the file. TAR was originally used to create files on tape, and now users can create files on any device, such as floppy disk. With TAR commands, you can pack all a lot of files and directories into a file, which is very useful for backing up files or combining several files into a file for network transmission. TAR on Linux is a GNU version. Syntax: TAR [primary option counseling] file or directory uses this command, the master option must be, it tells Tar to do something, the counseling is auxiliary use, you can choose. Parameters: c Create a new file file. If the user wants to back up a directory or some files, select this option. R Put the file you want to archive to the unlucky of the file file. For example, the user has made a backup file, and there is also a directory or some file forgot backup, then you can use this option to add a directory or file to the backup file. T list the contents of the file file, see which files have been backed up. U Update the file. That is to say, replacing the original backup file with a new file, if you can't find a file in the backup file, append it to the last of the backup file. X Release files from the archive file. Auxiliary Options: b This option is set for the tape drive. Then follow a number, used to explain the size of the block, the system preset value is 20 (20 * 512 bytes). F Use the file or device, this option is usually necessary. K Saves the already existing file. For example, we restore a file, during the restore, encounter the same file, and will not be overwritten. M When restoring the file, set the modification time of all files to now. M Create a multi-volume file to store in several disks. V Detailed report information of TAR processing. If there is no such option, TAR does not report file information. W Each step is required to confirm. Z Use GZIP to compress the / to decompress files, add this option to compress the file file, but must also use this option to decompress when it is restored. Example: Example 1: Take all backup files in the subdirectory in the / home directory, and the backup file is named usr.tar.
$ TAR CVF USR.TAR / HOME Example 2: All the subdirectories in the / home include all backup files and compressed, and the backup file is named usr.tar.gz. $ TAR CZVF USR.TAR.GZ / HOME Example 3: Restore the USR.TAR.GZ this backup file and decompressed. $ Tar xzvf usr.tar.gz Example 4: View the contents of the usr.tar backup file and display it on the display in a split screen. $ TAR TVF usr.tar | More To back up files to a specific device, just use the device name as the backup file name. Example 5: Create a backup file in the / dev / fd0 device's floppy disk and copy all the files in the / home directory to the backup file. $ TAR CF / DEV / FD0 / Home To recover files in the device disk, you can use the XF options: $ TAR XF / DEV / FD0 If the user backed up file size exceeds the storage space available in the device, such as floppy disk, you can create one Multi-volume TAR backup files. M Options indicate that TAR command prompts you to use a new storage device, when archiving a floppy drive with M option, the TAR command will remind you to add a new floppy disk when a floppy is full. This way you can save the TAR file into several disks. $ TAR CMF / DEV / FD0 / Home To restore the files in a few discs, just put the first place in the floppy drive, then enter the tar command with the X and M options. When necessary, you will be reminded to put another floppy disk. $ TAR XMF / DEV / FD0 GZIP command effect: Reducing file size has two obvious benefits, one is to reduce storage space, and the second is to reduce the transmission time when transferring files over the network. Gzip is a command to compress and decompress the files in the Linux system, which is convenient and easy to use. Syntax: Gzip [Option] File Name Parameters of Compressed (Decompressed): -c Write the output to the standard output and retains the original file. -D will decompress the compressed file. -L For each compressed file, display the following field: The size of the size of the compressed file is not compressed by the size compression of the specified directory and compresses all files or decompresses the name -R-RC class-R-generated. -T test, check if the compressed file is complete. -V's file name and compression ratio for each compression and decompression file. -Num Adjusts the compressed speed, -1 or -fast represents the fastest compression method (low compression ratio), - 9 or - BEST represents the slowest compression method (high compression ratio). The system default is 6. Suppose a directory / home has file mm.txt, sort.txt, xx.com. Example: Example 1: Complicates each file under the / home to the .gz file. $ CD / Home $ GZIP * $ LS M.TXT.GZ Sort.txt.gz xx.com.gz Example 2: Unzip each compressed file in Example 1 and lists detailed information. $ gzip -dv * mm.txt.gz 43.1% ----- Replaced with mm.txt sort.txt.gz 43.1% ----- Replaced with sort.txt xx.com.gz 43.1% ---- -Replaced with xx.com $ ls mm.txt sort.txt xx.com Example 3: Detailed Display Information of each compressed file in Example 1 does not decompress.
$ gzip -l * compressed uncompr. Ratio uncompressed_name 277 445 43.1% mm.txt 278 445 43.1% Sort.txt 277 445 43.1% xx.com $ ls mm.txt.gz sort.txt.gz xx.com.gz Example 4 : Compress a TAR backup file, such as usr.tar, the extension of the compressed file is .TAR.GZ $ GZIP USR.TAR $ ls usr.gz unzip command: Using the compressed software under MS Windows Winzip compressed How do files expand under Linux? You can use the unzip command, which is used to desleviate the compressed file named .zip. Syntax: UNZIP [Option] Compressed file name .zip Parameters: -x File List Decomposing File, but does not include the specified file file. -V View the compressed file directory, but does not decompress. -T test file is damaged, but does not decompress. -D directory solves the compressed file to the specified directory. -Z only shows the annotation of the compressed file. -N does not override existing files. -O covers existing files and does not require user confirmation. -J does not rebuild the directory structure of the document, unfolding all files to the same directory. Example: Example 1: Unpacking the compressed file text.zip in the current directory. $ UNZIP TEXT.ZIP Example 2: Describe the compressed file text.zip to the specified directory / TMP, if the same file exists, the unzip command does not overwrite the original file. $ Unzip -n text.zip -d / tmp case 3: View the compressed file directory, but does not decompress. $ Unzip -v text.zip zgrep Command The function of this command is to find a regular expression, the usage and grep commands are the same, just that the object is compressed. If the user wants to see if there is a certain sentence in a compressed file, use the zgrep command. Running the DOS Command in the Linux Environment provides a set of portable tools called Mtools to make users easily read, write files and directories from the standard DOS floppy disk. They are very useful to exchange files between DOS and Linux environments. They are a powerful means of exchange files between systems that do not have a common file system format. For a floppy disk of an MS-DOS, just put the floppy disk in the floppy drive, you can use the commands provided by mtools to access files on the floppy disk. MTools's main commands are as follows: MCD directory name changes the msdos directory; McOPY source file target file replicates files between MSDoS and UNIX; MDEL file name deletes MSDOS files; MDIR directory name shows msdos directory; MFormat drive letter in low-level formatted floppy disk Create a MSDOS file system; RNLabel drive letter generates a MSDOS volume list; MMD directory name is established; MRD directory name deletes the MSDOS directory; MREN source file target file renames existing MSDOS files; mtype file name shows the contents of the MSDOS file. These commands are very similar to the corresponding MSDOS commands that do not add M.
Example 1: Look at the top of the DOS disk under the Linux environment: $ mdir A: Volume in Drive A Has No Label Volume Serial Number IS 15F6-3362 Directory of A: / SS6 CPP 331 09-24-99 7: 41 SS6.CPP CH9 11-20-99 16:22 CH9 XXQ 0 11-20-99 16:24 xxq 95czxta DOC 36, 864 06-15-98 22:51 95CZXTA.DOC 95CZXTB DOC 39, 936 06-16-98 7:18 95CZXTB.DOC HTCA DOC 27, 136 01-08-99 0:13 htca.doc HTCB DOC 27, 136 01-08-99 0:12 htcb.doc 6 file (s) 131,403 bytes 1 dir (s) 1,295,872 BYTES FREE Example 2: The file xxq on the DOS disk is copied to the current directory and verify it with the LS command. $ mcopy a: /htca.doc $ ls -l htca.doc -rw-r- -r- - 1 xxq xxq 27136 Jan 1 01:80 HTCA.DOC Linux's common network command computer network main advantage is to achieve resources And information sharing, and users can access information remotely. Linux provides a set of powerful network commands to serve users, which help users log in to remote computers, transfer files and execute remote commands. This chapter describes the following commonly used commands: FTP Transfer file Telnet logs in to the remote computer R - Use a variety of remote command NetStat to view the network status NSLookup query domain name and IP address corresponding finger Query a user's information PING Query whether a machine is using the FTP command to remotely file the FTP command is a user interface for the standard file transfer protocol. FTP is a simple and efficient way to transfer files between computers on the TCP / IP network. It allows users to transfer ASCII files and binary files. During the FTP session, the user can connect to another computer using the FTP client. Since then, the user can move up and down in the directory, list the directory content, copy the file from the remote machine to the local machine, transfer the file from the local machine to the remote system. It should be noted that if the user does not have access permissions of that file, you cannot obtain a file from the remote system or transfer files to the remote system. In order to use FTP to transfer files, the user must know the legal username and password on the remote computer. The combination of this username / password is used to confirm the FTP session and to determine what kind of access can be made to the user to transfer. In addition, users clearly need to know the name or IP address of the computer that performs FTP sessions. The FTP command function is to transfer the file between the local machine and the remote machine. The general format of this command is as follows: $ FTP Host Name / IP where "hostname / IP" is the host name or IP address of the remote machine to be connected. In the command line, the host name belongs to the option. If the host name is specified, the FTP will try to connect with the remote machine's FTP service; if no hostname is specified, the FTP will give a prompt, waiting for the user to enter command: $ ftp ftp> At this point, enter the OPEN command to add the host name or IP address after the FTP> prompt, and will try to connect the specified host. Regardless of which method is used, if the connection is successful, you need to log in to the remote machine. If you have an account on the remote machine, you can use this account through FTP and provide a password. The read and write permission on the user account on the remote machine determines what files can be downloaded on the remote machine and put the upload file in which directory.
If there is no dedicated login account for a remote machine, many FTP sites have a special account that can be used. This account is named Anonymous (also known as anonymous FTP). When using this account, you request an Email address as a password. If the remote system provides an anonymous FTP service, users can log in to special, for public use. Generally provide two directory: PUB directory and incoming directory. The PUB directory contains all files that the site is available for public, and the file is stored on the site. Once the user logs in to the remote site, the "FTP>" prompt will be obtained. Now you can use the command provided by the FTP, you can use the HELP command to get the list of commands available, or you can specify the specific command name after the HELP command, and you can get the description of this command. The most commonly used commands are: LS lists the current directory CD of the remote machine CD Change the working directory LCD on the remote machine Change the working directory ASCII Settings File Transfer Method for ASCII Mode Binary Settings File Transfer Method for Binary Mode CLOSE Termination Current FTP Session Every time, each time the data is transmitted in the data buffer, it shows a ## Get (MGET) from the remote machine to the local machine PUT (MPUT) from the local machine transfer specified file to the remote machine OPEN connection remote FTP site QUIT break Enter the connection with the remote machine and exit FTP? Display Local Help Information! Go to the SHELL to make a brief introduction of the FTP common command. Start the FTP session Open command to open a session with the remote host. The general format of this command is that Open Host Name / IP If you want to connect with more than one site during the FTP session, you usually use only the FTP command without parameters. If you just want to connect with a computer during the session, specify the remote host name or IP address as the parameter of the FTP command on the command line. Termination FTP session close, disconnect, quit, and bye commands are used to terminate sessions with remote machines. The close and disronnect commands turn off the connection with the remote machine, but users stay in the FTP program of the local computer. The quit and bye commands are turned off the user with the remote machine, and then exit the FTP program on the user machine. Changing the Directory "CD [Directory] command to change the directory on the remote machine during the FTP session, the LCD command changes the local directory, and the user can specify the location of the field file. The remote directory list ls command lists the contents of the remote directory, just like using an LS command in interactive shell. The general format of the LS command is: LS [Contributory] [Local File] If the directory is specified as a parameter, then LS lists the contents of the directory. If the name of a local file is given, then this directory list is placed in this file you specified on the local machine. Gets the file GET and MGET commands from the remote system to get files from the remote machine. The general format of the GET command is: Get file name You can also give a local file name, this file name is the file name that this file is created on your local machine. If you don't give a local file name, then use the remote file original name. Mget Commands Get multiple remote files at a time. The general format of the MGET command is: the MGET file name list uses a file name list separated by spaces or band-through to specify the file to be acquired, and each file of it requires the user to confirm whether to transmit. Send a file PUT and MPUT command to the remote system to send files to the remote machine. The general format of the put command is: the PUT file name mput command sends multiple local files at a time, the general format of the mPut command is: the MPUT file name list uses a file name list separated by spaces or band-through-bands to specify the files to send. Each file of it requires the user to confirm whether to send.
Change file transfer mode By default, FTP Press the ASCII mode to transfer files, and users can specify other modes. The function of the ASCII and the brinary command is to set the transmission mode. Transferring files with ASCII mode is very good, but in order to avoid damage to binary files, users can transfer files in binary mode. Checking the transfer status to transmit large files, it is very useful to find that the FTP provides feedback information about the transmission situation. After the Hash command enables FTP to print a # character on the screen after the data in the data buffer is transferred each time. This command can be used when sending and receiving files. The local command in the ftp When you use FTP, the character "!" is used to transfer a command to the command shell on the machine. If the user is in the FTP session, it is useful if shell is doing something. For example, the user wants to create a directory to save the received file. If you enter! Mkdir new_dir, Linux creates a directory called New_DIR in the current local directory. Downloading binary data files from the remote machine grunthos typical conversation as follows: $ ftp grunthos Connected to grunthos 220 grunthos ftp server Name (grunthos: pc): anonymous 33l Guest login ok, send your complete e-mail address as password Password:. 230 Guest 1ogin ok, access restrictions apply. Remote system type is UNIX. ftp> cd pub 250 CWD command successful. ftp> ls 200 PORT command successful. l50 opening ASCII mode data connection for / bin / 1s. total ll4 rog1 rog2 226 Transfer comp1ete . ftp> binary 200 Type Set to I. FTP> Hash Hash Mark Printing ON (1024 Bytes / Hash Mark). ftp> Get Rog1 200 Port Command SuccessFu1. 150 Opening Binary Mode Data Connection For Rogl (L4684 Bytes). # # # # # 226 Transfer Complete. 14684 Bytes Received In 0.0473 SECS (3e 02 kbytes / sec) FTP> Quit 22L Goodbye. Accessing Remote Computer Using Remote Computer Use the Telnet command to remotely log in. This command allows users to communicate between remote computers using the Telnet protocol, and users can log in to remote computers over the network, just like logging in to the local machine. To log in to the remote computer via Telnet, you must know the legal username and password on the remote machine. Although some systems do login functionality for remote users, it is necessary to limit the operation permission of the guests for security considerations. Therefore, it is very small in this case. When the remote user is allowed to log in, the system usually places these users in a restricted shell to prevent the system to be damaged by malicious or accidentally. Users can also log in to their own computers using Telnet, check email, editing files, and runners, just like locally logging in.
However, the user can only use the terminal-based environment rather than the X Wndows environment, Telnet only provides terminal simulation to ordinary terminals without supporting X WDOW graphics environments. The general form of the telnet command is: Telnet hostname / IP where "hostname / IP" is the host name or IP address to which you want to connect. If this command is executed, you will get the login: prompt from the remote machine. The process of logging in using the telnet command is as follows: $ TELNET Host Name / IP Start Telnet session. Once the Telnet is successfully connected to the remote system, the login information is displayed and the user name and password will be losed. If the user name and password are entered correct, you can successfully log in and work on the remote system. After the Telnet prompt, you can enter a lot of commands to control the Telnet session, which has a detailed description of these commands in the Telnet online help manual. Below is a Telnet session on a Linux computer. Kernel 2.0.18 on AN i486 login: Bubba Password: Last Login: Mon Nov L5 20:50:43 for localhost Linux 2. 0.6. (POSIX). Server: ~ $ server: ~ $ logout connection closed by foreiign Host $ After the user ends the remote session, be sure to use the logout command to exit the remote system. Then the Telnet reports the remote session is turned off and returns to the Shell prompt of the user's local machine. The R-series command except FTP and Telnet, Use the R-series command to exchange remote computers and exchange files on the network. Use the R-series commands to pay special attention, because if users are not careful, they will cause serious security vulnerabilities. After users send a R-series command, remote system check Files named /etc/hosts.equiv to see if the user's host is listed in this file. If it does not find the host's host, check the file named.rhosts named .rhosts on the main directory of the remote machine to see if it is. Includes the user's host. If the user's host includes any of these two files, the user does not have to provide a password. Although the user does not use the user to enter the mouth without the user, it may be very Convenient, it may also bring serious security issues. We recommend that users carefully consider the security issues implied by R-commands before establishing /etc/hosts.equiv and.rhosts files. Rlogin Command Features: rlogin is " Remote login is abbreviated. This command is similar to the telnet command, allowing users to launch interactive command sessions on remote systems. Format: rlogin [-8ekldx] [-e char] [-k realm] [- l Username ] Host Parameters: -8 This option always allows 8-bit input data channels. This option allows you to send formatted ANSI characters and other special code. If you don't need this An option, unless the termination of the far end and the starter character are not or or otherwise it will go to the parity bit. -E stops regarding any characters as a escape character. When you are working with the -8 option, it provides a complete transparent connection. -K Close all Kerberos confirmation. This option is only used when connecting to a host connection using the Kerberos confirmation protocol.
-L allows the Rlogin session to run in the Litout mode. For more information, please consult the TTY online help. -D opens Socket debugging of TCP sockets that communicates with the remote host. For more information, please refer to the online help of SetsockOpt. -E is an Rlogin session setting escape character, the default escape character is "~", the user can specify a text character or an eight-input number in the form of // nnn. -K request rlogin's Kerberos license for remote hosts in the specified area, rather than obtaining Kerberos licenses for remote hosts within a remote host area determined by KRB_REALMOFHOST (3). -X Open DES encryption for all data transmitted through the Rlogin session. This will affect the response time and the CPU utilization, but can improve security. RSH Command Function: RSH is an abbreviation for "Remote Shell". This command launches a shell on the specified remote host and executes the command specified in the RSH command line. If the user does not give the command to be executed, RSH uses the rlogin command to log in to the remote machine. Format: RSH [-kdnx] [-k realm] [-l username] host [command] Command can be any Linux command from the Shell prompt. Parameters: -k Close all Kerbero confirmation. This option is only used when connecting to a host confirmed using Kerbero. -D opens Socket debugging of TCP sockets that communicates with the remote host. For more information, please refer to the online help of SetsockOpt. -K request RSH to get the Kerberos license for the remote host in the specified area, not the Kerberos license of the remote host in the remote host area determined by KRB_RELMOFHOST (3). -L By default, the remote username is the same as the local username. This option allows the remote user name to be specified. If the remote username is specified, use Kerberos confirmation and is the same as in the rlogin command. -N redirects from special equipment / dev / null input. -X Open DES encryption for all data transmitted. This will affect the response time and the CPU utilization, but can improve security. Linux places the standard input into the RSH command and copy it to the standard input of the command to be executed remotely. It copies the standard output of the remote command to the standard output of RSH. It also copies remote standard errors to local standard error files. Any exit, abort and interrupt signals are sent to the remote command. When the remote command is terminated, the RSH will terminate. RCP Command Function: RCP represents "Remote File Copy". This command is used to copy files between computers. There are two formats in the RCP command. The first format is used for files to files; the second format is used to copy files or directories into another directory. Format: RCP [-px] [-k realm] file1 file2 RCP [-px] [-r] [-k realm] File Directory Each file or directory parameter can be either a remote file name or a local file name. The remote file name has the following form: RNAME @ rhost: path, where RNAME is a remote username, Rhost is a remote computer name, and Path is the path of this file. Parameters: -r Recursively copy all content in the source directory into the destination directory. To use this option, the purpose must be a directory. -P Attempts to reserve the modification time and mode of the source file, ignore Umask.