Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)

A, Linux directory structure

FHS specification defines two layers: the first layer is a respective directory of "/" directory what documents should be placed, for example: / placement system configuration files etc directory, and / bin and / sbin placement programs and system commands. The second layer is defined for the subdirectory / user and / var two directories, for example: placement system log file in / var / log like.
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)
Here's a brief introduction to the common subdirectory and the role therein.
/ boot: This directory is stored in the system kernel, file storage directory is also required when starting the system, such as vmlinuz and initrd.img. When installing CentOS, create a partition for the boot directory, it is conducive to back up the system.
/ bin: bin abbreviation when the binary. This directory contains all the user can execute commands and frequently used.
/ sbin: the most basic storage system management commands, users generally only administrators have permission to perform.
/ dev: Ibaraki saved in the file interface device.
/ etc: this directory to save the file on the system setup and management.
/ home: general store all the user's default working folder.
/ root: The root directory is the system administrator's home directory, by default only the root user's home directory in the root directory and no longer under "/ home" directory.
/ usr: storage of other user applications, typically further divided into many sub-directory, for storing different types of applications.
/ var: Some file storage systems often need to change, such as system log files, user mailboxes catalog.

Two, view, and retrieve the file
1, view the contents of the file
cat command
cat command is used to connect a plurality of files present content, but more in practical use for viewing the contents of the file. The cat command is the most widely used file content view commands. When you use this command, just need to see the file path as a parameter.
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)

more和less命令
在使用cat命令时可以非常简单地直接显示出整个文件的内容,但是当文件中的内容较多时,很可能因为不能滑动而只能看到最后一部分信息,却无法看到文件前面的大部分信息。这时候我们就可以用到more和less这两种命令了,这两种命令可以采用全屏的方式分页显示文件,便于我们从头到尾仔细阅读文件内容。
more命令
使用more命令查看超过一屏的文件时,将进行分屏显示,并在左下角显示当前内容在整个文件中所占的百分比。在阅读该页面时,可以按Enter键向下逐行滚动查看,按空格键可以向下翻一屏,按b键向上翻一屏,按q键退出并返回原来的命令环境。
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)
从下面两幅图左下角的文件内容百分比我们可以看出,在使用了more命令后我们的界面已经可以翻屏查看了
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)

less命令
less命令是较晚出现的分页显示命令,提供了比早期more命令更多的一些拓展功能。与more命令不同的是,查看超过一屏的文件时,虽然也进行分屏显示,但是在左下角并不显示当前的内容在整个文件中的百分比,而是显示被查看文件的文件名。在less命令中,向上翻页是Page Up,向下翻页是Page Down,按“/”键查找内容,“n”显示下一个内容,“N”显示上一个内容,其他功能基本与more相似。
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)

head与tail命令
head与tail是一对作用相反的命令,前者用于显示文件开头的一部分内容,后者用于显示文件末尾的一部分内容。可以使用“-n”选项指定需要显示多少行内容,若未指定则默认显示十行。
这是我们正常查看某个文件
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)
如果我们想要之查看开头或结尾,这时就需要head和tail命令了。
这是我们用head命令查看的,如果不加选项那么就默认显示前十行。
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)
如果我们不想查看这么多,可以使用“-n”选项(n为具体数字)指定需要显示的行数。例如这里我们查看用户帐号文件/etc/passwd的前五行。
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)
tail命令则相反,用于查看文件末尾部分。例如这里我们查看用户帐号文件/etc/passwd的后五行。
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)

2、统计和检索文件内容
wc命令
wc命令用于统计文件内容包含的行数、单词数、字节数等信息,使用文件名作为参数,可以同时统计多个文件。
wc命令常用的选项
-c:统计文件内容的字节数。
-l:统计文件内容的行数。
-w:统计文件内容的单词数。
如果使用wc命令是没有加选项他会默认行数、单词数、字节数一起统计。这里我们对/etc/httpd/conf/httpd.conf进行统计。
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)
若是我们想要对某个特定选项进行统计,就需要用到选项了。例如我们对/etc/httpd/conf/httpd.conf的的行数进行统计。
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)

grep命令
grep命令用于在文件中查找并显示包含指定字符串的行,可以直接指定关键字符串作为查找条件,也可以使用复杂的条件表达式。
grep命令常用的选项
-i:查找内容时忽略大小写。
-v:反复查找,即输出与查找条件不相符的行。

这里我们把/etc/httpd/conf/httpd.conf中带#的过滤进行查找。
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)

三、备份与恢复文档
在linux系统中,最简单的备份文档的方式是cp,但当文档数目数量较多时,cp便显得力不从心,并且会占用过多的硬盘资源。在这种情况下,最好的方法便是压缩和归档。下面将详细的介绍压缩与归档两种方法。

1、使用压缩和解压缩工具
gzip和gunzip命令
使用gzip制作的压缩文件默认扩展名为“.gz”。制作压缩文件时,使用“-9”选项可以提高压缩的比率,但文件较大时会需要更多的时间。
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)

当需要解压缩经gzip压缩的文件时,只需要使用带“-d”选项的gzip命令即可,或直接使用gunzip命令。
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)

bzip2和bunzip2命令
buzip2和bunzip2命令用法基本与gzip和gunzip命令基本相同,使用bzip2所压缩的文件拓展名为“.bz2”。
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)

2, using the tar archive and release tool
tar command to archive the main role of directories and files. In actual backup job, the package will usually be compressed archive files to save disk space. When using the tar command, option before the "-" can be omitted.
tar common options
-c: Create a package file .tar format.
-C: developing released when extracting the destination folder.
-f: indication archive.
-j: call bzip2 compression or decompression program.
rights reserved files and directories when the package: -p.
-P: to retain the absolute path of the file and directory when packaging.
-t: View a list of files within the package.
-v: Enter details.
-x: unlock the file format .tar package.
-z: gzip program calls the compression or decompression.
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)
Take you through the basic Linux command of the second bomb (want to learn Linux for small partner)

Guess you like

Origin blog.51cto.com/14449528/2429944