Linux directories, view and extract command (cat, more, etc.)

It is worth mentioning that today reads:
(1) directory tree structure
(2) using the View command
(3) compression, archive command

A number of shaped directory structure

1. The root of the
location of all partitions, directories, files, and so the starting point of
the entire directory tree structure, using a separate
2. The common subdirectory
/ the root / bin / Boot / dev / etc
/ Home / var / usr / sbin
. 3. subdirectories function:
² / root: root system administrator's home directory
 / home: general user's home directory
 / boot: kernel, startup files
 / dev: device file (CD-ROM, disk)
² / etc: configuration file, which is / passwd account information is
 / bin: executable commands all users
 / sbin: administrators can perform administrative command
 / usr: applications
 / var: variable-length files (log files, etc. )
² / proc: hardware information (memory, the CPU)
² / tmp: temporary directory
 / opt: empty file
Lib, lib64: library

Second, the view command

Cat Command
Purpose: To display the contents of the file
format: Cat [options] filename ...
Example:
Linux directories, view and extract command (cat, more, etc.)
Cons: only the last piece of content files, no flip function, the contents of any of it again in front of the wonderful and we can not see. Do not panic, we see there are other commands that allow us to explore next.
Ø
More View command
purposes: a full-screen page displays the contents of the file
more [options] filename ...
interactive methods of operation:
Enter: Scroll down line by line
 space: turning down a screen
B: scroll up ( the Back)
q: exit
Linux directories, view and extract command (cat, more, etc.)
disadvantages: easy to pop the last page, the last page of content can not be viewed. Unable to look up. It seems that the more command can not see all of the text, the last of the contents really do not see it? No, in this small series revealed in advance, see next command more powerful.
Ø
Less command
1. Usage: more same command, but more extensions
 Less [Option] File Name ...
2. interworking method
Page Up: Page_Up
Page Down: Down
 Press " / "key Find what:" n "next content," N "on a content
other functions are more basic command similar
Linux directories, view and extract command (cat, more, etc.)
with the help of this command, we finally see the entire contents of the text, really twists and turns.
Ø
head command
purposes: part of the beginning of the view files (the default is 10 lines)
Linux directories, view and extract command (cat, more, etc.)
tail command
Purpose: to view the file at the end of a small part (the default is 10 lines)
tail -n filename ... or tail -f filename ...
Linux directories, view and extract command (cat, more, etc.)

wc command
Purpose: Number of words in the document statistics (Word Count) information
wc [Option] ... ... target file
common command options
-l: Statistics rows
-w: count the number of words
-c: statistical bytes
-l: statistics (line) line
-w: statistics number of words (Word)
-C: statistics (char) bytes
expanded: only the default statistics only wc input line number, the number of words and the number of bytes.
Linux directories, view and extract command (cat, more, etc.)

grep command
Purpose: to find and display the line containing the specified string in the file
format: grep [option] ... the search criteria target file
1 commonly used command options.

  • i : 查找时忽略大小写
    -V : 反转查找,输出与查找条件不相符的行
    2.查找条件设置
    要查找的字符串以双引号括起来
    (1).“^.....” 表示以.......开头
    (2).“....$”表示以.....结尾
    (3).“^$” 表示空行

    正转查找(#为注释,只起描述作用,不具功能
    ):
    Linux directories, view and extract command (cat, more, etc.)
    特点:方便查找同一形式的数据

    反转查找,输出与查找条件不相符的行并导入home目录下的111文本中:
    Linux directories, view and extract command (cat, more, etc.)
    Tip:
    1.“>”重定向:把输出的数据全部复制到另一个文件中;
    2.当遇到要粘贴文本中有内容时,内容会覆盖文本中的源内容。
    3.可以捕捉在屏幕终端显示的信息,能导入到一个文件中生成

    我们用追加符号“>>”做一个文本测试,会出现什么惊喜吗?
    Linux directories, view and extract command (cat, more, etc.)
    总结:追加符号“>>”能使原来文本中内容不动,粘贴过来的内容往后添加。

    思考从一个文件中的内容导入到自身文本中,会发生什么有趣的事呢?
    Linux directories, view and extract command (cat, more, etc.)
    得到结论:操作失败,原因是它们共占用一个进程,导入导出的不能都是同一个文件。

最后增加一个知识点:管道符号“|”,它具体能干吗呢?让我们目光聚集到下面来。
Linux directories, view and extract command (cat, more, etc.)
原来它的功能是先执行“|”之前的命令,再把得出的结果送给管道“|”后用来执行命令(如同工厂流水线加工,一步步往后执行命令,)。这种结合命令大大方便我们进一步找到自己想要的数据,小伙伴们要牢牢记住哦!

三、压缩、归档命令

1.gzip命令、 bzip2命令
用途:制作压缩文件、解开压缩文件
gzip [-9] 文件名...
bzip2 [-9] 文件名...
gzip -d ...gz格式的压缩文件
bzip2 -d ...bz2格式的压缩文件
2.常用命令选项及其功能
-9 : 压缩文件
-d :解压文件
gzip压缩、解压:
Linux directories, view and extract command (cat, more, etc.)
bzip2压缩、解压:
Linux directories, view and extract command (cat, more, etc.)

可看出gzip和bzip2压缩、解压文件,源文件会消失。在windows系统中解压文件后源文件不会消失,那有什么办法能使源文件跟windows系统中一样,即不会消失呢?让我们来看接下来的tar命令。

Tar command
Purpose: Create archive file, release archive
Tar [option] ... archive file name of the source file or directory
or
Tar [option] ... the archive file name [-C target directory]
1. Common command options:
-c , the -X-, -v, -f, -p, -t, -C, the -Z, -j
2. each command option function:
²-C: creating the cabinet
-x: extracting
detailed information display: -v
-f: performing
-p: preserving permits
-t: View archive content
-C: decompression target path
-z: gzip format
-j: bzip2 format
gzip-compressed file:
Linux directories, view and extract command (cat, more, etc.)
with tar czvf 1111.txt .tar.gz command compress 1 .txt, A .txt files, source files will not disappear.
Ø
the gzip extracting file:
Linux directories, view and extract command (cat, more, etc.)
extract to a different directory, to add "-C"; not "-C", i.e. extract to the current directory.
Ø
bzip2 compression, decompression file:
Linux directories, view and extract command (cat, more, etc.)
visible with the tar command to compress files, source files are always present. This command is very practical to use.
Ø
² Today's focus:
. 1 remember the role of Linux common subdirectory;
2 master and rational use of the view commands;.
3 skilled use of compression, decompression command.

Guess you like

Origin blog.51cto.com/14475593/2429341