Directory and file management theory to explain

[TOC]

Foreword

A: Linux directory structure

1.1: tree directory structure

Directory tree structure, generally refers to a range of interrelated or for a particular group has the upper and lower body a dominant performance impact body composition and execution of a tree structure of distribution, such as about coordination and cooperation, leadership and a series of deployment the schematic structure.

1.2: root directory

  • Position all the partitions, directories, files, and so the starting point
  • The entire directory tree structure, using a separate "/" represents

1.3 Common subdirectories

table of Contents Note table of Contents Note
/root Management's home directory (home directory) /bin All users of the executable command file directory
/boot Boot partition (grub boot menu, compression system kernel, etc.) /dev The device file directory (disk, CD-ROM, etc.)
/etc Profile directory /home Average user's home directory
/where Variable-length file directory (log) /usr Application Directory
/sbin Administrator executable command file directory /lib Service management file (systemctl) / lib / systemed / system /
/opt Empty directory / mnt Empty directory
/tmp Temporary Files /proc Hardware information (CPU, memory)

Two: View and retrieve files

2.1: View the file contents cat command

mark

cat can only view files

yum intallhttpd -y install httpd plug at / mnt under

2.2 view file contents more command

more command

  • Uses: full screen page display file contents

more [options] filename ...

  • Interactive method of operation

Press Enter to scroll down line by line

Press the spacebar to turn down one screen

Press q to exit

Press b a look back

more Disadvantages: see the end will automatically exit, can not write

cat high limitations, if the file exceeds the screen, no scroll wheel, then see above

2.3 less command

Purpose: the more command the same, but more extensions

less [options] filename

Interactive method of operation

Page Up Page Up, Page Down Page Down

Press the "/" key to find the content, the next content on a content "n", "N"

Other features similar to the more command

Switch interface command:

init 0 shutdown representatives

init 1 Single user mode character interface (system maintenance, crack the administrator password)

initi 2 multi-user mode character interface, no network

init 3 Multi-mode networks have common character interface *

init 4 Reserved

init 5 multi-user mode graphical interface with a common network *

init 6 重启 (reboot)

2.4 查看文件内容head、tail命令

mark

-n查看开头部分n行,不写就是默认十行

通常用这个命令去查看帐号文件的首位

vim /etc/passwd,passwd是账号文件,这里是编辑paswd

mark

新创建的用户都会在后面

tail /etc/passwd 查看末尾十行

tail -2 /etc/passwd 查看末尾两行

useradd lisi 创建用户 lisi

passwd lisi 密码设置为lisi

mark

可以给账号文件加密,让别人无法访问,后期会学习到

vim mkdir 在mkdir中编辑文本

vim /etc/httpd/conf/httpd.conf 在 /etc/httpd/conf/的httpd.conf文件中编辑文本

mark

2.5:统计文件内容wc命令

mark

mark

行 单词 字节,选项处什么都不敲就是默认每个都有

2.6:检索和过滤文件内容grep命令

mark

应用于过滤掉注释性的文字(注释性的文字带有#)

mark

“>”重定向符号可以覆盖文件

mark

两个大于号不会覆盖

history

ctrl+r,然后就可以搜索命令

mark

mark

grep “^root” /etc/passwd 查找文件中以ROOT为开头的行

bin/bash 是用户后面所特有的

管道符号 | 的意思是,把上一个命令执行的结果,转交给后面的一个命令去处理

mark

不可以把查找文件所得到的内容输入到它原本的文件中,因为这个时候是进程占用状态

mark

三:备份及恢复目录

3.1:压缩命令gzip、bzip2命令mark

-9表示高压缩比,压缩之后的文件特别小,它执行的是压缩指令

解压缩使用-d

gzip -9 abc.conf 压缩abc.conf文件

这个命令会把abc.conf直接压缩,并不会产生另外一个文件,跟微软不同

gizp -d abc.conf.gz 解压abc.conf.gz 文件

bzip2 跟gzip的指令一样,他们之间的区别是bzip2的压缩效率更快,而gzip的压缩容量更小

mark

3.2压缩命令gunzip、bunzip2命令

mark

3.3归档命令tar命令

mark

-c 创建压缩包

x 解压

-v详细过程

-f execution (must be)

-p preserving permits compression packing

-t View archive content

-C extract to where to go

-z refers GZ format

-j refers bzip2 format

Archive file name is the name of the archive

Use tar archive files will not let disappear, extract the archive will not let disappear, just like Microsoft's command is very similar to the compression rar

rm -rf /home/*.conf delete followed by .conf file

mark

Options file format to be consistent with the format later in the file, otherwise it will fail

mark

Four: vi text editor

4.1: Text editor vi commandmark

vim can distinguish grammar, vi can not distinguish grammar

Operating mode 4.2vi editor

mark

a, i, o, O four letters,

A represents a cursor position after insertion,

Where i represents inserted before the cursor position

O represents where the next line is inserted in the cursor position

O represents an insertion cursor position where the next line

ESC, to command mode, press the colon, enter line mode

Line mode: w save, q exit, enter OK

4.3 Basic Operation command mode

mark

mark

#dd delete the line that includes the cursor begin deleting

dw delete word deleted the word

shift + r replaces the current text

P is small at the cursor next line paste, opposite a large P

Command mode operation in

mark

: Set nu! Also cancel the operation line number

mark

The vertical position of the line exchange, ddp, not large P

q! Forced to exit without saving

mark

zz can use lowercase

Basic operation mode is the last line 4.4

mark

mark

Guess you like

Origin blog.51cto.com/14558445/2445566