Title: Linux must learn 60 commands (6)-Other __linux

Source: Internet
Author: User
Tags lowercase mixed zipinfo
Title: Linux must learn 60 commands (6)-Other

Linux must learn 60 commands: Other
Important commands that Linux must learn (1)
Author: Cao Yuan its dispatch time: 2004.12.16
In the previous lecture, we introduced the Linux commands into several parts, according to their role in the system. However, some of the commands are not easy to divide, but learning them is also more important.

Tar

1. Role
The tar command is a reliable method of backing up files in a unix/linux system and can work almost anywhere, with permissions for all users.

2. Format
tar [main options + auxiliary options] File or directory

3. Main parameters
When using this command, the main option is required, it tells Tar what to do, the auxiliary option is auxiliary, and can be selected.

Main options:
-C creates a new profile. If the user wants to back up a directory or some files, select this option.

-R appends files to archive to the end of the file. For example, users have done backup files, and found that there is a directory or some files have forgotten to back up, you can use this option to append forgotten directories or files to the backup file.
-T lists the contents of the profile to see which files have been backed up.
-U update files. That is, replace the original backup file with the new file, and append it to the end of the backup file if the file you want to update cannot be found in the backup file.
-X releases the file from the profile.

Accessibility Options:
-B This option is set for the tape drive followed by a number indicating the size of the block, and the system preset is 20x512 bytes.
-F using an archive file or device, this option is usually required.
-K saves files that already exist. For example, if you restore a file, you will encounter the same file during the restore process without overwriting.
-M when the file is restored, set the time for all files to be modified to the present.
-M to create a multiple-volume profile for storage on several disks.
-V detailed report on the file information processed by tar. Without this option, TAR does not report file information.
-W each step requires confirmation.
-Z use gzip to compress/extract files, plus this option to compress the profile, but you must also use this option for decompression.

4. Application Instructions
Tar is an abbreviation for tape Archive (tape archive) that was originally designed to package files onto tape. If you downloaded the Linux source code, you may have encountered the tar file

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

5. Application examples
Tar is a command-line tool with no graphical interface. Use Konsole to open a terminal window, followed by a simple backup command (create a Back.tar file in the/temp directory, where all content in the/usr directory is included.) ):
$tar cvf-usr >/temp/back.tar

In addition, the TAR command supports the crontab command described in the previous third lecture, which can be set to run on a regular basis using the Crontab tool. For example, every 6 o'clock in the evening the/usr directory is backed up to the primary drive (always on the first hard drive) of the first IDE interface in hda-, as long as the following statement is added to the crontab of root:
$00 * * Tar cvf/dev/hda1/usrfiles.tar-/usr

In general, the following directories are required to be backed up:
/ETC contains all the core profiles, including network configuration, system name, firewall rules, users, groups, and other global system items.
/var contains information used by the System Daemon (service), including DNS configuration, DHCP lease, message buffering files, HTTP server files, dB2 instance configurations, and so on.
/home contains the home directory for all default users, including personal settings, downloaded files, and other information that users do not want to lose.
The home directory of the/root root (root) user.
/OPT is where you install many files that are not system-wide. IBM software is installed here. OpenOffice, JDK, and other software are also installed here by default.

Some directories may not be backed up:
/proc should never back up this directory. It is not a real file system, but rather a virtualized view of the kernel and environment, including files such as/proc/kcore, which is a virtual view of the entire running memory. Backing up these files is just a waste of resources.
/dev contains a 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, then backup/dev is not necessary.

Unzip

1. Role
The unzip commands are located in the/usr/bin directory, and they are the same as the WinZip software features in MS DOS, PKZIP, Pkunzip, and MS Windows. Compress the file into a. zip file to save hard disk space, and then unzip the compressed file with the unzip command when needed. This command uses permissions that are all users.

2. Format
Unzip [-cflptuvz][-agcjlmnoqsvx][-p < password >][.zip file] [file][-d < directory >][-x < file]

3. Main parameters
-C: Displays the uncompressed results to the screen and converts the characters appropriately.
-F: Update existing files.
-L: Displays the files contained within the compressed file.
-P: Similar to the-c parameter, the uncompressed results are displayed to the screen, but no conversions are performed.
-T: Check that the compressed file is correct.
-U: Similar to the-f argument, but in addition to updating an existing file, the other files in the compressed file are uncompressed to the directory.
-V: Displays detailed information when execution is performed.
-Z: Only notes text for compressed files is displayed.
-A: Make the necessary character conversions to the text file.
-B: Do not convert text files to characters.
-C: File names in compressed files are case-sensitive.
-J: Do not process the directory path in the compressed file.
-L: Change all file names in the compressed file to lowercase.
-M: Send output to more program processing.
-N: Do not overwrite the original file when extracting.
-O: Do not need to ask the user first, unzip overwrite the original file after execution.
-p< Password: Use the zip password option.
-Q: Do not display any information at execution time.
-S: Converts the whitespace character in the file name to the bottom line character.
-V: Preserves file version information for VMS.
-X: Back up the original uid/gid of the file while decompressing.
[. zip file]: Specifies a. zip compressed file.
[File]: Specifies which files in the. zip compressed file to process.
-d< Directory: Specifies the directory to be stored after the file is uncompressed.
-x<: Specifies which files in the. zip compressed file should not be processed.
-Z unzip:-z is equal to executing zipinfo directives. Linux also provides a tool called Zipinfo that can view the details of zip compressed files. The latest version of unzip is 5.50.

Gunzip

1. Role
The Gunzip command is to extract the files and use permissions for all users.

2. Format
Gunzip [-acfhllnnqrtvv][-s < compressed word tail string >][file ...]
Or
Gunzip [-acfhllnnqrtvv][-s < compressed word tail string >][directory]

3. Main parameters
-A or--ASCII: using ASCII text mode.
-C or--stdout or--to-stdout: To output the extracted files to the standard output device.
-F or-force: Forcibly unzip the compressed file 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: When uncompressed, if the compressed file contains the original file name and time stamp, then ignore it.
-N or--name: When uncompressed, if the compressed file contains the original file name and time stamp, it is saved to the unpacked file.
-Q or--quiet: Warning message not displayed.
-R or--recursive: recursively handles all files and subdirectories in the specified directory.
-s< compressed Word tail string > or--suffix< Compressed tail string: Change the compressed word tail string.
-T or--test: Tests whether the compressed file is correct.
-V or--verbose: Displays the instruction execution process.
-V or--version: Displays version information.

4. Notes
Gunzip is an extensive decompression program that is used to unlock files that are compressed by gzip, and these compressed files are preset with the last extension ". gz". In fact, Gunzip is a hard connection to gzip, so either compression or decompression can be done individually through the gzip instruction. The latest version of Gunzip is 1.3.3.

Unarj

1. Role
Unarj uncompressed files in the. arj format, using permissions for all users.

2. Format
UNARJ [Eltx][.arj Compressed file]

3. Main parameters
E: Extract the. arj file.
L: Displays the files contained within the compressed file.
T: Check that the compressed file is correct.
X: Preserves the existing path when decompressing.

4. Notes
Files with the. arj extension are created by the ARJ utility for MS DOS and Windows. Because ARJ is a shared piece program that doesn't get the source code for free,

Mtools

1. Role
Mtools is actually a collection of commands, a tool for the DOS file system that simulates many DOS commands and is easy to use. Use permissions are all users. Linux systems provide a set of portable tools called Mtools that allow users to easily read and write files and directories from a standard DOS floppy disk. They are useful for exchanging files between DOS and Linux environments. The use of Mtools is very simple, if you want to copy all the files on the floppy disk to the hard drive, then you can execute the following command:
Mcopy A:*.*

That is, you can complete the corresponding function by simply adding a letter "M" to the corresponding DOS command. This software is available in general Linux distributions and can be checked using the command below.
Rpm-qa|grep Mtools

If it is not installed, it does not matter, can be downloaded from the Internet (http://mtools.linux.lu/) A latest version to install. The latest mtools version available for download today is

2. Included orders
MCD Directory Name: Change the directory under MS DOS.
Mcopy source File Destination file: Copies files between MS DOS and UNIX.
Mdel FileName: Deletes the file under MS DOS.
Mdir Directory Name: Displays the directory under MS DOS.
Mformat Drive Letter: Creates the MS DOS file system on a low-level formatted floppy disk.
Rnlabel Drive Letter: produces the volume label under MS DOS.
MMD Directory Name: Create MS DOS directory.
MRD Directory Name: Deletes the directory under MS DOS.
Mren source file Target file: Renames an existing MS DOS file.
Mtype FileName: Displays the contents of the MS DOS file.

Please note that these commands are very similar to the corresponding MS DOS commands. In the Mtools command, "/" and "/" can be mixed. "CDE" and "CDE" are the same here because the file list is a DOS system document and is not case sensitive.

3. Application examples
(1) If the floppy disk is quickly formatted, you can use the command mformat:
Mformat A:

Mtools was originally developed to handle DOS file systems, so it can only be used on partitions in FAT file format. Note that if you mount the FAT16/32 partition with the Mount command, you cannot use the Mtools directive to process the files on those partitions. This is because once the FAT16/32 partition is attached to the Linux file directory, Linux treats it as part of the filesystem itself, and if you want to operate on it, you must use the instruction set that comes with the Linux itself.

(2) Copy the file htca.c in the DOS disk to the current directory and verify with the LS command.

$ mcopy A:/HTCA.C
$ ls-l HTCA.C
-rw-r--r--1 xxq xxq 27136 1 01:80 htca.c

Mans

1. Role

The man command is used to provide online help, and permissions are available to all users. A manual for online use is stored in a Linux system for users to find on the terminal. Use the man command to access the Help information, 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. Parameter
-C Config_file: Specifies the settings file man.conf, the default value is/etc/man.conf.
-M Path: Specifies the search path for the online manual, if not specified, uses the setting of the environment variable Manpath, or if Manpath is not used, the setting in/usr/lib/man.conf, or the default value if Manpath is a null string.
-P Pager: Specifies which Pager.man will be used preferentially for this option setting, followed by the environment variable Manpager, then the environment variable Pager;man default use/usr/bin/less-is.
-S Section_list man: the list of chapters searched (separated by colons), which overrides the setting of the environment variable mansect.
-A man: The default is to stop the search after displaying the first found manual, and using this option forces man to continue displaying all online manuals that match the name.
-C: Even with the latest cat page, you continue to rearrange the online manuals, which is especially useful when the number of rows on the screen changes or when the published online manuals are damaged.
-D: Do not actually display the online manuals, only display the error message.
-D: Both online manuals and error messages are displayed.
-H: Displays the help message and then ends the program.
-K: Searches all online manuals for the specified string. Note that this feature may be slow to respond, and if you specify a section (area) it can be helpful for speed.
-M System: Specifies an online manual for another group, depending on the system name you specify.
Man: is the abbreviation of Manual (manual). You can get this document immediately when you have difficulty in entering commands. For example, if you are having trouble using the PS command, you can enter the man PS to get help, and you will see the PS man page.

Because the man page is in the less program (it's easy to flip and flip the screen), you can use all of less's options in the man page.

The more important function keys in less are:
[Q] Exit;
[Enter] A line of the underground turn;
[Space] A page of the underground turn;
[b] turn up a page;
[/] followed by a string and [Enter] to find the string;
[n] finds the next match for the last lookup.

4. Read the book page
The man page provides a lot of information in very little space, and here is a brief introduction to most of the pages of the book. The Linux man page has nine main sections: User directives, system calls, libraries, device descriptions, file formats, games, miscellaneous, system directives, kernels, and a man page snapshot as shown in Figure 1.

Figure 1 PS Command manual page snapshot

The Linux man page layout is shown in table 1.

5. Application examples
Linux commands have some basic, important commands, such as PS, find, cat, and LS. Here's an example of a comprehensive application that shows that man's position is critical in Linux. However, the information displayed by man is not plain text, and if you redirect the text directly to a text file, you will find that the text highlighted in man becomes two, and there are countless tabs that make printing and editing all the more inconvenient. However, you can get the PS command to print using one of the following statements.
# Man PS | Col-b | Lpr

This command also uses output redirection and pipeline two techniques to print the Help information for the PS command directly. More man files to view Linux man

Unencode

1. Role
The Unencode command can encode a binary file table as a text file with permissions for all users.

2. Format
Uuencode [-HV] [source] destination file

3. Main parameters
-H: Lists instructions using format (Help).
-V: Lists version information.

4. Application Instructions
The UUENCODE directive converts a binary file into an ASCII-encoded form that can be sent using e-mail. The uuencode encoded data begins with the beginning, ends with end, and usually the beginning of each row is "M", the middle part is the encoded file, and 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 encoded data between the begin and end tags, and the program skips data outside the tag. It has permission to use for all users.

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

3. Main parameters
-H: Lists instructions using format (Help).
-V: Lists version information.

4. Application examples
Use the following command to restore several files at once:
Uuencode File1.uud File2.uud File3.uud

Hands-on practice

1. Send a message under the Linux command line
Although Linux desktop applications are growing fast, the command line (Shell) still has a strong life in Linux. If you can confirm that your e-mail server supports 8bit of bytes, you can use the following command directly:
Cat "Attachment filename" | Mail address

The Cat (Cat is abbreviated for CONCATENATE) command is to process several files into a single file and save the results of this processing to a separate output file, which we use to combine the text of the message.

Write a message name, such as Cjkmail, and then use the following command:
$uuencode attachment file name > >>cjkmail

So you can use VI Editor to write Cjkmail file, and write the letter in front of the body, and then send out.

The other party received the letter, the letter belongs to the contents of the Cjkmail copy out, save as Themail.uue. If the other side is under Windows, you can extract it using WinRAR or WinZip, so you can see the attachment.

If the other side also uses Linux, you can use the Undecode command to restore:
$ uudencode-o< Attachment filename > Themail.uue

2. To achieve the tar of the sub-volume
The author wants to compress a 378MB file into several 63MB files (the author's USB is 64MB), using the following command:
$tar Czvf-dir | Split-d-B 63m

Then merge the commands:
$cat x* > Dir.tgz

The above example is actually done by a combination of three commands, which are packaged with tar, split by splits, and combined with cat. "Tar Czvf-dir" means to package the Dir directory and output it to standard output (argv) so that it can be piped directly to split.

3. Continuous execution of a command
Using the Watch command, you can execute commands repeatedly. If you cooperate with LS, you can observe the effect of changing the size of a file.
$watch ls-l File.name

4. Export a file with the tar command
There is a tar format of the DVD file Glvpro6.4_linux.tar, because the file is very large (4.7GB), if all decompression is more troublesome, you can use the following command pilot out Readme.txt see.
Tar xvf Glvpro6.4_linux.tar Readme.txt

So the Readme.txt is exported alone.

5. Back up only a few subdirectories when packing a directory with tar
Tar CF--exclude Home/cjh Home/cao

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

So far, the 60 commands that Linux will learn are all covered. Linux command line is powerful, if you have mastered the common Linux commands, often only through a variety of skills can be combined to form a complex command to complete the user task. There are so many commands in the Linux system that it is not possible to remember all the commands and parameters in MS DOS. Linux systems provide a number of methods, such as "Help" and "man" to query name orders.

Go to Unixchina

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.