Important commands required for Linux

Source: Internet
Author: User
Tags zipinfo

Important commands required for Linux

Author: Cao yuan, his posting date: 2004.12.16
From: http://www.ccidnet.com
 
In the previous sections, we have divided Linux commands into several parts based on their functions in the system. However, there are still some commands that are difficult to classify, but learning them is equally important.

Tar

1. Role
The tar command is a reliable method for backing up files in Unix/Linux systems. It can work in almost any environment and has the permission of all users.

2. Format
Tar [main option + auxiliary option] file or directory

3. Main Parameters
When you use this command, the main option is required, and it tells tar what to do. The auxiliary option is used for assistance and can be used.

Main options:
-C. Create a new archive file. Select this option if you want to back up a directory or some files.

-R: append the file to be archived to the end of the file. For example, if you have prepared a backup file and find that there is another directory or some files have forgotten to be backed up, you can use this option to append the directory or files you have forgotten to the backup file.
-T list the file content and check which files have been backed up.
-U updates the file. That is to say, replace the original backup file with the new file. If the file to be updated cannot be found in the backup file, append it to the end of the backup file.
-X releases a file from the file.

Auxiliary options:
-B. This option is set for the tape drive, followed by a number to indicate the block size. The default value is 20 (20 × 512 bytes ).
-F this option is usually required when you use an archive file or device.
-K: Save the existing file. For example, if a file is restored, the same file will not be overwritten during restoration.
-M sets the modification time of all files to the present when restoring files.
-M: Create a multi-volume archive file to store it on several disks.
-V details the file information processed by tar. If this option is not available, tar does not report file information.
-W each step requires confirmation.
-Z uses gzip to compress or decompress the file. With this option, you can compress the file, but you must use this option to decompress the file during restoration.

4. Application description
Tar is the abbreviation of tape archive. It was originally designed to package files on tape. If you have downloaded the Linux source code, you may have encountered a tar file. Tar is a file-based command, which essentially stacks files consecutively and at the beginning and end. You can use tar to package the entire directory tree, which makes it especially suitable for backup. You can restore all the archive files, or expand separate files and directories from them. Backups can be saved to file-based devices or tape devices. Files can be redirected during restoration to put them in a directory (or system) different from the directory (or system) where they were originally saved ). Tar has nothing to do with the file system. It can be used on ext2, ext3, JFS, Reiser, and other file systems. It supports various backup media, including floppy disks, disc writers, rewritable discs, jazzip, tapes, and high-end tapes. Files ending with .tar in linuxare all created with tar. It is used beyond simple backup and can be used to put many different files together to form a file that is easy to separate. If you use the Linux source code to install the program, you must have used the tar file. This is a file-based command, which essentially stacks files consecutively and at the beginning and end. Tar official website is http://www.gnu. org/software/tar/tar.html.

Note that Linux is case sensitive. For example, the tar command should always be executed in lower case. The command line switch can be a combination of upper-case, lower-case, or lower-case. For example,-T and-T perform different functions. File or directory names can be both case sensitive and case sensitive, just like the command line switch.

5. Application Instance
Tar is a command line tool without a graphical interface. Use konsole to open a terminal window, followed by a simple BACKUP command (create a back.tar file in the/tempdirectory, and all the content in the/usr directory is included in it .) :
$ Tar CVF-/usr>/temp/back.tar

In addition, the tar command supports the crontab command mentioned in the third lecture. You can use the crontab tool to set it to run regularly based on time. For example, back up the/usr directory to the master drive (always on the first hard disk) of the hda-first ide interface at every night, add the following statement to the root crontab:
$00 06 *** tar CVF/dev/hda1/usrfiles.tar-/usr

Generally, the following directories need to be backed up:
◆/Etc contains all core configuration files, including network configuration, system name, firewall rules, users, groups, and other global system items.
◆/Var contains the information used by the system daemon (service), including DNS configuration, DHCP lease period, Mail Buffer file, HTTP Server File, and DB2 instance configuration.
◆/Home contains the home directories of all default users, including personal settings, downloaded files, and other information that users do not want to lose.
◆/Root Root (Root) user's home directory.
◆/OPT is the place where many non-system files are installed. The IBM software is installed here. OpenOffice, JDK, and other software are installed here by default.

Some directories cannot be backed up:
◆/Proc should never back up this directory. It is not a real file system, but a virtual view of the running kernel and environment, including files such as/proc/kcore. This file is a virtual view of the entire running memory. Backing up these files is just a waste of resources.
◆/Dev contains the file representation of the hardware device. If you plan to restore to a blank system, you can back up/dev. However, if you plan to restore to an installed Linux system, it is unnecessary to back up/dev.

Unzip

1. Role
The unzip command is located in the/usr/bin directory, which is similar to the PKZIP, pkunzip, and winzips in ms dos and Microsoft Windows. The file is compressed into a. ZIP file to save hard disk space, when necessary, unzip the compressed file. This command has the permission of all users.

2. Format
Unzip [-cflptuvz] [-agcjlmnoqsvx] [-P <password> unzip. ZIP file] [file] [-D <directory>] [-x <File>]

3. Main Parameters
-C: displays the extracted results on the screen and converts the characters properly.
-F: update an existing file.
-L: displays the files contained in the compressed file.
-P: similar to the-C parameter, the extracted result is displayed on the screen without any conversion.
-T: Check whether the compressed file is correct.
-U: similar to the-F parameter, but in addition to updating an existing file, other files in the compressed file are also extracted to the directory.
-V: detailed information is displayed during execution.
-Z: only the remarks of the compressed file are displayed.
-A: Perform necessary character conversion for text files.
-B: Do not convert characters in text files.
-C: The file name in the compressed file is case sensitive.
-J: the original directory path of the compressed file is not processed.
-L: change all file names in the compressed file to lowercase.
-M: Send the output result to the more program for processing.
-N: Do not overwrite the original file during decompression.
-O: you do not need to ask the user first. After unzip is executed, the original file is overwritten.
-P <password>: Use the zip password option.
-Q: No information is displayed during execution.
-S: converts the blank characters in the file name to the bottom line characters.
-V: retain the file version information of VMS.
-X: the original UID/GID of the file is saved back at the same time.
. ZIP file]: Specifies the. Zip compressed file.
[File]: Specifies the files in the. Zip compressed file.
-D <directory>: Specifies the directory to be stored after the file is decompressed.
-X <File>: Specifies which files in the. ZIP file are not processed.
-Z unzip:-Z is equivalent to executing the zipinfo command. In Linux, a tool called zipinfo is provided to view the details of zip files. Unzip is 5.50 In the latest version.

Gunzip

1. Role
The gunzip command is used to decompress the file and the permission is granted to all users.

2. Format
Gunzip [-acfhllnnqrtvv] [-S <compressed character string>] [file...]
Or
Gunzip [-acfhllnnqrtvv] [-S <compressed character string>] [Directory]

3. Main Parameters
-A or -- ASCII: Use the ASCII text mode.
-C or -- stdout or -- to-stdout: output the decompressed file to the standard output device.
-F or-force: uncompress the compressed file by force, regardless of whether the file name or hard connection exists, and whether the file is a symbolic connection.
-H or -- help: online help.
-L or -- list: lists information about compressed files.
-L or -- license: displays version and copyright information.
-N or -- no-name: during decompression, if the compressed file contains the original file name and time stamp, it will not be processed.
-N or -- name: during decompression, if the compressed file contains the original file name and timestamp, it will be stored back to the unlocked file.
-Q or -- Quiet: no warning information is displayed.
-R or -- Recursive: recursive processing that processes all files and subdirectories under a specified directory.
-S <compressed character string> or -- suffix <compressed character string>: Change the compressed character string.
-T or -- test: test whether the compressed file is correct.
-V or -- verbose: displays the command execution process.
-V or -- version: displays version information.

4. Description
Gunzipis a simple decompressed program. It is used to open a file that has been compressed by gzip. the extension name of the compressed file is pai.gz ". In fact, gunzip is the hard connection of gzip. Therefore, you can use the gzip command to complete it separately, whether it is compressed or decompressed. The latest version of gunzip is 1.3.3.

Unarj

1. Role
Unarj files in the. ARJ format are decompressed. the permission is granted to all users.

2. Format
Unarj [eltx] [. ARJ compressed file]

3. Main Parameters
E: extract the. ARJ file.
L: displays the files contained in the compressed file.
T: Check whether the compressed file is correct.
X: the original path is retained during decompression.

4. Description
Files with the. ARJ extension are created by the ARJ utility for ms dos and Windows. Because ARJ is a shared item program that cannot obtain source code for free, there is almost no tool that matches its functions on the Linux platform. to decompress the. ARJ file, you must use the unarj utility. Unarj is slower than ARJ and less powerful than ARJ, but at least it can smoothly extract most. ARJ files. Unarj can only Extract files to the current working directory, list file content, or test files. You can download the unarj source code from the site of ARJ software or the FTP server that carries the required Linux release version. In addition, unarj is typically part of a basic Linux release, so you can find it on the CD-ROM of the primary release. If you need to download from the list of all Linux releases, the ARJ software URL is http://www.arjsoft.com, And the ARJ download page is http://www.arjsoft.com/files.htm. The latest unarj version is 2.65. Note that the unarj option does not start with a minus sign.

Mtools

1. Role
Mtools is actually a command set and a tool program of the DOS file system. It can simulate many DOS commands and is very convenient to use. The permission is granted to all users. Linux provides a set of portable tools called mtools, allowing you to easily read and write files and directories from standard DoS floppy disks. They are very useful for switching files between DOS and Linux environments. Mtools is easy to use. If you want to copy all the files in the floppy disk to the hard disk, You can execute the following command:
Mcopy :*.*

That is to say, you only need to add a letter "M" before the corresponding doscommand to complete the corresponding function. This software is usually available in Linux distributions. Run the following command to check the software.
Rpm-Qa | grep mtools

If there is no installation, it does not matter, you can download (http://mtools.linux.lu/) a latest version of the installation from the Internet. Currently, the latest mtools version is 3.9.9. The download link is http://mtools.linux.lu/mtools-3.9.9-3.i386.rpm. Download and install it.

2. Included commands
MCD directory name: Change the directory under ms dos.
Mcopy source file target file: copy the file between ms dos and UNIX.
Mdel file name: delete the file in ms dos.
Mdir directory name: displays the directory under ms dos.
Mformat drive letter: Create a ms dos file system on a low-level formatted floppy disk.
Rnlabel drive letter: generate the volume label under the ms dos.
MMD directory name: create a directory under ms dos.
MRD directory name: Delete the directory under ms dos.
Target file of the mren source file: rename the existing ms dos file.
Mtype file name: displays the content of the ms dos file.

Note that these commands are very similar to the corresponding MS doscommand. In the mtools command, "/" and "/" can be mixed. Because the file list contains documents in the DOS system and is not case sensitive, "CDE" and "CDE" are the same here.

3. Application Instance
(1) If you want to quickly format a floppy disk, run the mformat command:
Mformat:

Mtools was originally developed to process DOS file systems, so it can only be used in partitions in the FAT file format. Note that if fat16/32 partitions are mounted using the mount command, you cannot use the mtools command to process files in these partitions. This is because once the fat16/32 partition is mounted to the Linux File directory, Linux regards it as part of the file system, in this case, you must use the instruction set attached to Linux.

(2) copy the file htca. C on the DOS disk to the current directory and run the LS command for verification.
$ Mcopy A:/htca. c
$ LS-l htca. c
-RW-r--1 xxq 27136 Jan 1 01: 80 htca. c
 
Man

1. Role

The man command is used to provide online help. the permission is granted to all users. In Linux, an online user manual is stored for users to find on the terminal. You can use the man command to view the help information, which is very convenient and practical.

2. Format
Man command name
MAN [-acdfhkktww] [-M system] [-P string] [-C config_file] [-M path] [-P Pager] [-s section_list] [section] Name. ..

3. Parameters
-C config_file: Specifies the man. conf file. The default value is/etc/man. conf.
-M path: Specifies the search path of the online manual. If not specified, the environment variable manpath is used. If manpath is not used,/usr/lib/man is used. conf. If manpath is an empty string, the default value is used.
-P Pager: Specifies the pager to use. man uses this option first, and then sets it according to the environment variable manpager, and then the environment variable pager. Man uses/usr/bin/less-is by default.
-S section_list man: List of chapters to be searched (separated by colons). This option overwrites the mansect setting of the environment variable.
-A man: by default, searches are stopped after the first found manual is displayed. Using this option forces man to continue displaying all online manuals that meet the name.
-C.
-D: do not display the online manual. Only the error message is displayed.
-D: displays both online manuals and debugging messages.
-H: displays the help message and ends the program.
-K: searches all online manuals for specified strings. Please note that the response speed of this function may be slow. If you specify a section (region), it will be helpful.
-M system: specify another group of online manuals based on the specified system name.
MAN: the abbreviation of manual. You can obtain this document immediately when it is difficult to enter the command. For example, if you encounter difficulties when using the ps command, you can enter man PS to get help information. The man page of PS is displayed ).

Since the man page of the manual page is viewed by the less Program (which can be easily used to flip the screen up and down), all the less options can be used in the man page.

More important function keys in less are:
[Q] Quit;
[Enter] one row goes underground;
[Space] page by page;
[B] One page above;
[/] Followed by a string and [enter] To find the string;
[N] finds the next match in the last query.

4. Read the manual page
The manual page provides a lot of information in a few spaces. Here we will briefly introduce some of the content on most manual pages. The Linux manual page consists of nine parts: USER commands, system calls, libraries, device descriptions, file formats, games, miscellaneous, system commands, and kernels.

5. Application Instance
Linux Commands include basic and important commands, such as PS, find, cat, and LS. Here is an example of a comprehensive application. It can be seen that man's position is crucial in Linux. However, the information displayed by man is not common text. If you direct the text to a text file, you will find that the highlighted text in Man is changed to two, there are countless tabs, making printing and editing inconvenient. However, use the following statement to print the ps command.
# Man PS | col-B | LPR

This command uses both the output redirection and pipeline techniques to print the help information of the ps command directly. For more man files, see the Linux man pages Simplified Chinese homepage, which is linked to http://cmpp.linuxforum.net /.

Unencode

1. Role
The unencode command encodes a binary file table into a text file. the permission is granted to all users.

2. Format
UUEncode [-HV] [source file] target file

3. Main Parameters
-H: Lists instructions in the Help format ).
-V: List version information.

4. Application description
The uuencode command can convert a binary file into an ascii code that can be sent by email. The uuencode encoded data starts with begin and ends with end. Generally, each row starts with "M" and the middle part is the encoded file, the encoded file is larger than the source file.

Uudecode

1. Role
The uudecode command is used to restore the uuencode-encoded file. uudecode only restores the encoding data between the in and the end mark, and the program skips the data other than the mark. The permission is granted to all users.

2. Format
UUEncode [-HV] [file1...]

3. Main Parameters
-H: Lists instructions in the Help format ).
-V: List version information.

4. Application Instance
Run the following command to restore several files at a time:
UUEncode file1.uud file2.uud file3.uud

Hands-on exercises

1. send an email under the Linux Command Line
Despite the rapid development of Linux desktop applications, shell still has a strong vitality in Linux. If the email server supports 8-bit bytes, run the following command:
Cat <Attachment File Name> | mail <email address>

The cat (cat is the abbreviation of concatenate) command processes several files into one and saves the processing results to a separate output file, here we use it to merge the text of the mail.

Write the email name, for example, cjkmail, and run the following command:
$ Uuencode <Attachment File Name> cjkmail

In this way, you can use the VI editor to write the cjkmail file, write the text of the letter in front, and then send it.

After receiving the letter, the recipient copies the content in the letter from cjkmail and saves it as themail. UUE. If the recipient is in Windows, you can decompress WinRAR or WinZip to see the attachment.

If the other party also uses Linux, you can use the undecode command to restore:
$ Uudencode-O <Attachment File Name> themail. UUE

2. Implement tar volume sharding
I want to compress a MB file into multiple MB files (I use 64 MB USB). Run the following command:
$ Tar czvf-Dir | split-D-B 63 m

Then merge the command:
$ Cat X *> dir. tgz

The above example is actually completed by a combination of three commands, that is, packaging with tar, splitting with split, and merging with cat. "Tar czvf-Dir" means to package the Dir directory and output it to the standard output (argv). In this way, you can directly output it to the split using a pipeline.

3. Execute a command consecutively
You can run the watch command repeatedly. If it works with LS, you can observe the size of a file.
$ Watch LS-l file. Name

4. Use the tar command to export a file
Refer.
Tar xvf glvpro6.4_linux.tar readme.txt

In this example, readme.txt is exported separately.

5. Only several subdirectories are backed up when a directory is packed with tar.
Tar CF -- exclude Home/cw.home/CaO

In this way, the home directory is backed up in only two subdirectories, csung and Cao.

Up to now, all 60 required Linux commands have been introduced. The command line method of Linux is powerful. If you are familiar with common Linux commands, you can combine a complex command with various techniques to complete your tasks. There are too many commands in Linux, and it is impossible to remember all the commands and parameters in ms dos. Linux provides some methods, such as using "help" and "man" to query the name order.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.