60 required commands for Linux [6] Other commands

Source: Internet
Author: User
Tags zipinfo
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 the same

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.
The permission is granted to 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, which tells tar what to do, and the auxiliary option is 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 already backed up the file, you can find that
If you forget to back up a directory or file, you can use this option to append the directory or file you forgot to back up.
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.
The new file is appended 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, to restore a file, the same file is encountered during restoration.
Will be overwritten.
-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/decompress the file. With this option, you can compress the file, but the file is also compressed during restoration.
You must use this option for decompression.

4. Application Description
Tar is the abbreviation of Tape Archive. it was originally designed to package files on Tape. If
Linux source code, or tar files. Tar is a file-based command, which is essentially a connection
Stack files at the beginning and end of the stack. 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 on a tape device. Files can be redirected during restoration so that they can be replaced to a directory that stores them initially.
(Or system) different directories (or systems ). Tar has nothing to do with the file system. it can be used in ext2, ext3, JFS,
Reiser and other file systems. It supports various backup media, including floppy disks, disc writers, rewritable discs,
JazZip, tape, and high-end tape. Files ending with .tar in linuxare all created with tar. Its usage exceeds
Simple backup can be used to put many different files together to form a file that is easy to separate. If you use a Linux source
The code installer must have used the tar file. This is a file-based command, which is essentially continuous, beginning and end
Stack files in different locations. 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
The names can be case-sensitive in combination, and are case-sensitive just like the command and command line switch.

5. application instance
Tar is a command line tool without a graphical interface. Use Konsole to open a terminal window.
Simple backup commands (create a back.tar file in the/tempdirectory, and all contents in the/usr directory contain
.) :
$ 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
Time runs regularly. For example, back up the/usr directory to the hda-primary drive of the first IDE interface (
Always in the first hard disk), just 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,
Group, and other global system items.
◆/Var contains the information used by the system daemon (service), including DNS configuration, DHCP lease period, and email delay.
Dash files, HTTP server files, and dB2 instance configurations.
◆/Home contains the home directories of all default users, including personal settings, downloaded files, and users who do not want to lose
.
◆/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 its
The software is also 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 runs the kernel and
Virtualization view of the environment, including files such as/proc/kcore, which is the virtual view of the entire running memory
Graph. 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 commands are located in the/usr/bin directory. they are used in the pkzip, pkunzip, and MS Windows
The winzipsoftware features the ability to compress files into. zip files to save hard disk space.
The unzip command is used to unbind the file. This command has the permission of all users.

2. Format
Unzip [-cflptuvz] [-agCjLMnoqsVX] [-P <密码> [[.Zip file] [file] [-d <目录> ] [-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 existing files, it also decompress other files in the compressed file
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 <密码> : 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 <目录> : Specifies the directory to be stored after the file is decompressed.
-X <文件> : Specifies which files in the. zip compressed file are not processed.
-Z unzip:-Z is equivalent to executing the zipinfo command. In Linux, a tool called zipinfo is also provided, which can
Check the details of the zip file. 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 <压缩字尾字符串> ] [File...]
Or
Gunzip [-acfhlLnNqrtvV] [-s <压缩字尾字符串> ] [Directory]

3. main parameters
-A or-ascii: uses 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
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: if the compressed file contains the original file name and time stamp
Not processed.
-N or-name: during decompression, if the compressed file contains the original file name and time stamp, it is saved back
On 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 <压缩字尾字符串> Or-suffix <压缩字尾字符串> : 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
Gunzip is a widely used decompression program used to unbind files compressed by gzip.
The last extension name is 2.16.gz ". In fact, gunzip is the hard connection of gzip, so whether it is compression or decompression
, Can be completed separately through the gzip command. 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
Shared-Ware programs that cannot obtain source code for free, so there is almost no tool that matches the 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
The ability to smoothly extract most. arj files. Unarj can only extract files to the current working directory and list file content,
Or test files. Download from the site of ARJ Software or the FTP server that carries the required Linux release version
Unarj source code. In addition, unarj is usually part of the basic Linux release, so you can
Find it on the CD-ROM. If you want to download the ARJ software from the list of all Linux releases, the URL is http:
// Www.arjsoft.com. the download page of ARJ is http://www.arjsoft.com/files.htm. Unarj latest version
The value 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.
. The permission is granted to all users. The Linux system provides a set of mtools
Allows you to easily read and write files and directories from standard DOS floppy disks. Between the DOS and Linux environments
It is very useful to swap files. Mtools is very easy to use. if you want to copy all the files in the floppy disk to the hard disk,
Then 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 not installed, it does not matter, you can download a latest version from the Internet (http://mtools.linux.lu /)
. 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 "" are optional
To be mixed. Because the file list contains documents in the DOS system and is not case sensitive, "CDE" and "cde"
"It is 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
To process files in these partitions. This is because once the FAT16/32 partition is mounted to the Linux file directory
Will regard it as part of the file system itself, if you want to operate on it, you must use
Set.

(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. Stores an online user in Linux.
To be searched 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, use the MANPATH setting of the environment variable;
If MANPATH is not used, the setting in/usr/lib/man. conf is used. if MANPATH is a null string
The default value is used.
-P pager: specifies which pager. man will be set with this option given priority, followed by environment variables
Set MANPAGER, followed by 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 environment variable.
MANSECT settings.
-A man: by default, the search will stop after the first found manual is displayed. using this option will force
Man continues to display all name-compliant online manuals.
-C: even if the latest cat page exists, retypeset the couplet Manual. this option is used to change the number of rows and columns on the screen.
It is particularly meaningful when the online manual is changed or damaged.
-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.
A specific section (region) is helpful for speed.
-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, enter man ps to get help information. the ps manual page is displayed (
Man page ).

Because the man page on the manual page is viewed by the less program (it can be easily used to flip the screen up and down ),
All the less options can be used in the 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 is a brief introduction to most of the manual pages.
Some content. The Linux manual page consists of nine parts: User instructions, system calls, libraries, device instructions, and files.
Format, game, miscellaneous, system commands, and Kernel. for details about the manual page snapshot, see.
Ps command manual page snapshot
The Linux manual page is shown in Table 1.

 

5. application instance
Linux commands include basic and important commands, such as ps, find, cat, and ls. The following is an example:
An example of a comprehensive application shows that man's position is crucial in Linux. However, the message displayed by man
Text. if you directly redirect the text to a text file, you will find highlighted in man.
The displayed text is changed into two tabs, which make 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 directly use the help information of the ps command.
Print it out. For more Man files, see The Linux Man Pages simplified Chinese homepage. the link is
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.
After uuencode encoding, all data starts with begin and ends with end. Generally, 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.
. 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 file and processes
The result is saved to a separate output file. here we use it to merge the mail text.

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 ).
Output to split in 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.
Effect.
$ Watch ls-l file. name

4. use the tar command to export a file
There is a tarlike dvdfile glvpro6.4_linux.tar, because the file is very large (4.7 GB), if all
To solve this problem, you can use the following command to first export readme.txt.
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. Linux has powerful command line functions,
If you are familiar with common Linux commands, you can combine them to form a complex command.
To complete user tasks. There are too many commands in Linux, and it is impossible to remember all the commands and parameters in ms dos. The Linux system provides some methods, such as "help" and "man.

Related Article

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.