linux file management 03 and 04--2week

1.linux system, everything is a file:
the file system and directory structure:
linux file management 03 and 04--2week
/ the Boot: boot file storage directory, kernel file (vmlinuz), the boot loader (bootloader, grub) are stored in this directory
 / bin: all users of basic commands; can not be associated to a separate partition, OS boot program will be used namely
 / sbin: management of basic commands; can not be associated to a separate partition, OS boot program will be used namely
 / lib: start program dependent substantially shared libraries and kernel module files (/ lib / modules)
 / the lib64: dedicated to the x86_64 system auxiliary shared library file location
 / etc: configuration file directory
 / home / USERNAME: general user home
 / root : the administrator's home directory
 / media: a portable mobile device mount point
/ mnt: temporary file system mount points
 / dev: device special file storage and file location
 / tmp: temporary file storage location
#

2.lsblk- lists the system's hard disk du -sh view the file size pwd- display the current directory
--echo '- - -'> / sys / class / scsi_host / host0 (host2) / scan - to increase virtual machine hard disk commands
- - / proc / sys - process directory
Catalog colors: blue - catalog, yellow- hardware catalog, pink - socket, brown - pipe files, l green - executable file, red - packed or compressed files
- define the color file path: / etc / DIR_COLORS
- except slash and NUL, all the characters are effective, the use of special characters in directory names and file is not recommended, some characters need to use quotation marks to refer to them.
- standard Linux file system (such as ext4), file names are case-sensitive, for example: mAIL, mail, mail, mAIL
-> Linux file type: (-) rw- --- ---: parentheses represents the file type

  • Trivial File
    d directory file
    b block device
    c character device
    l symbolic link file
    p pipe file pipe
    s socket socket file
    absolute path: Also known as the complete path from the root relative path: relative to the current working directory path
    ..: ll ../issue on a directory:. ll ./network current directory
    --basename- before removing relatively ignored before the file name directory dirname- removed without removing the last file name relative file name (variable represents a string)
    #

    3.
    Check the status file: stat
    file has two types of data: metadata ,: metadata definition - the data (the Metadata), also known as meta data, the relay data, is described in the data (data about data), mainly data describing attributes (property) information to support functions such as indicating the storage location, historical data, resource discovery, documentation and so on. Metadata regarded as a kind of electronic catalog, in order to achieve the purpose of cataloging, and must describe the content or characteristics of data collection, and thus help to achieve the purpose of data retrieval, metadata is data data.
    the Data:
     three timestamp:
    Access Time Access time, atime, read the contents of the file
    modify time modification times, mtime, change the contents of the file (data)
    Change Time to change the time, ctime, metadata change
    linux file management 03 and 04--2week
    file: filename size: File size (B)
    blocks: file number area occupied by a multiple of 8 (typically Linux-sector size is 512 B, eight successive sectors a block)
    the IO block: the size of each data block (units: B )
    Regular file: regular files (file type displayed here)
    device: where the equipment;
    inode: inode number of the file - the file storage area information is called meta inode
    Links: hard times link
    access: access
    id :( owner id / owner name)
    Gid :( is a group id / is a group name)
    access: the last access time
    Modify: the data change time
    Change: metadata change time
    Change timestamp:
    Change access time:
    linux file management 03 and 04--2week
    Review Modify time:
    linux file management 03 and 04--2week
    Review change time (change time metadata):
    linux file management 03 and 04--2week
    -> Change atime can also touch -a /data/1.xt, empathy mtime can also touch -m / data / 1.xt to change, if the contents of the file to be modified, the modified file mtime will be updated, inode information file updates back to lead ctime update.
    -> atime: access time: read the contents of a file, this time will be updated. For example, more, cat commands. ls, stat command does not modify atime
    mtime: Modified: Modified content of the document was last modified. For example: vim after the operation to save the file. This is the time ls -l listed
    ctime: the status change time. Is the inode of the file was last modified time, by chmod, chown command to modify a file attribute, this time will be updated.
    linux file management 03 and 04--2week
    #

    4.
    chkconfig iptables OFF -centos6 turn off the firewall
    systemctl disable fireewalld -centos7
    vi / etc / selinux / config - Change: disable setenforce 0 - can temporarily turn off selinux getenforce - to view the status selinux
    file wildcards:

    • 匹配零个或多个字符 -ls .txt ls x*
      ? 匹配任何单个字符 ls a?.log
      ~- 前一个工作目录 ls ~-/af.log
      [0-9] 匹配数字范围
       [a-z]:字母(包含大写字母)
       [A-Z]:字母(包含小写字母)
       [wang] 匹配列表中的任何的一个字符
       [^wang] 匹配列表中的所有字符以外的字符
      预定义的字符类:man 7 glob
      [:digit:]:任意数字,相当于0-9
      [:lower:]:任意小写字母
      [:alnum:]:任意数字或字母
      -->列出当前目录命令:
      ls -a 包含隐藏文件
      ls -l 显示额外的信息
      ls -R 目录递归
      ls -ld 目录和符号链接信息
      ls -1 文件分行显示
      ls –S 按从大到小排序
      ls –t 按mtime排序
      ls –u 配合-t选项,显示并按atime从新到旧排序
      ls –U 按目录存放顺序显示
      ls –X 按文件后缀排序
      touch命令:
      touch [OPTION]... FILE...
      -a 仅改变 atime和ctime
      -m 仅改变 mtime和ctime -t [[CC]YY]MMDDhhmm[.ss]
      指定atime和mtime的时间戳
      -c 如果文件不存在,则不予创建
      linux file management 03 and 04--2week
      用法描述:
      touch修改每个指定文件file的存取(access)和/或修改(modification)时间戳记.除非使用-r或-t选项,这些时间戳记都将修改为当前的时间.使用-r选项时,这些戳记将按照文件 ref_file 的时间戳记来修改(即变得和ref_file时间戳记值相同).使用-t选项,则这些戳记将按照给定的时间值 time进行修改.同时使用或同时不使用选项-a和-m,存取和修改两个戳记都将被更改.若只使用选项-a,则只修改存取戳记.同样,只使用选项-m,则只修改修改戳记.若要修改戳记的文件尚不存在,除非使用-c选项,touch 将创建它(作为空文件,并赋予0666的模式且受umask值的限制).
      -->POSIX标准定义的选项
      -a 修改文件 file 的存取时间.
      -c 不创建文件 file.
      -m 修改文件 file file
      -r ref_file 将参照文件 ref_file 相应的时间戳记的数值作为指定文件 file 时间戳记的新值.
      -t time 使用指定的时间值 time 作为指定文件 file 相应时间戳记的新值.此处的 time 规定为如下形式的十进制数∶
      [[CC]YY]MMDDhhmm[.SS]
      #

      5.
      复制文件cp命令:
      cp:复制普通文件 -- 复制特殊文件需要增加选项
      多个文件夹复制到一个文件里(文件报错不支持) --多次操作一个命令会产生幂等性
      \cp:原始命令不用别名(多个文件复制时)
      linux file management 03 and 04--2week

CP选项:
-i 覆盖前提示
linux file management 03 and 04--2week
alias-采用的是别名:替代cp -i
-r, -R 递归复制目录及内部的所有内容
linux file management 03 and 04--2week
-a 归档,相当于-dR --preserv=all
-d --no-dereference --preserv=links 不复制原文件,只复制链接名
--preserv[=ATTR_LIST] -p 等同--preserv=mode,ownership,timestamp
mode: 权限
ownership: 属主属组
timestamp:时间戳
links
xattr
context
all cp /etc/fstab ~wang
-v --verbose
-f --force
-u --update 只复制源比目标更新文件或目标不存在的文件
-b 目标存在,覆盖前先备份,形式为 filename~
--backup=numbered 目标存在,覆盖前先备份加数字后缀
例:每天将/etc/目录下所有文件,备份到/data独立的子目录下,并要求子目录格式为 backupYYYY-mm-dd
linux file management 03 and 04--2week
#

6.
mv命令:mv - 移动 (改名) 文件
改“源文件”名到“目标文件”名, 或移动“源文件”(可以不只一个)到一个“目录
linux file management 03 and 04--2week
linux file management 03 and 04--2week
#

7.
rm删除:
常用选项:
-i 交互式
-f 强制删除
-r 递归
--no-preserve-root 删除/
linux file management 03 and 04--2week
linux file management 03 and 04--2week
rm -f :强制删除的时候不会有任何提示
linux file management 03 and 04--2week
rm -r:在删除文件目录的字母时会递归提示
mkdir 创建目录:
-p: 存在于不报错,且可自动创建所需的各目录
-v: 显示详细信息
linux file management 03 and 04--2week
-m MODE: 创建目录时直接指定权限
linux file management 03 and 04--2week
#

8.
rmdir 删除空目录
-p: 递归删除父空目录
-v: 显示详细信息
rm -r 递归删除目录树
linux file management 03 and 04--2week
-使用> 命令重新建立文件并且删除文件内的数据
linux file management 03 and 04--2week
linux file management 03 and 04--2week
-- 使用>> + 文件 -创建文件(不清空文件数据)
linux file management 03 and 04--2week
rename批量更改文件名:
linux file management 03 and 04--2week
索引节点:inode(index node)表中包含文件系统所有文件列表
一个节点 (索引节点)是在一个表项,包含有关文件的信息( 元数据 ),包括:
文件类型,权限,UID,GID
链接数(指向这个文件名路径名称个数)
该文件的大小和不同的时间戳
指向磁盘上文件的数据块指针
有关文件的其他数据
保存文件是通过节点表来保存的
linux file management 03 and 04--2week
命令参数个数是有限的
节点编号用光会导致磁盘未满,但是报错:no space left to device
linux file management 03 and 04--2week
例:
拿/boot来说所用的索引节点总共524288个,没创建一个文件就会增加一个节点,当所有的节点数大于总的节点数时会导致节点数不够,但是磁盘利用率并未满;
#

9.
ln -硬链接:ln 硬链接等于cp -p 加 同步更新。
本质:同一文件多个名称,不能跨分区和设备
linux file management 03 and 04--2week
更改文件名但属性和inode节点名完全不变
linux file management 03 and 04--2week
--硬链接不支持文件夹
linux file management 03 and 04--2week
-->软连接:也称为符号链接
ln -s :创建软连接 软连接依赖于原始文件
创建软连接原始文件要写相对路径是相对于软连接路径 而不是当前路径
针对文件夹也可以创建 跨分区也可以
软链接可以理解成快捷方式。它和windows下的快捷方式的作用是一样的。
linux file management 03 and 04--2week
区别: 软链接文件的大小和创建时间和源文件不同。软链接文件只是维持了从软链接到源文件的指向关系
硬链接文件和源文件的大小和创建时间一样。硬链接文件的内容和源文件的内容一模一样,相当于copy了一份
linux file management 03 and 04--2week
跨分区也可以实现软连接:
linux file management 03 and 04--2week

删除软硬链接:
--删除硬链接其中的一个并不影响数据,indoe是目录文件的唯一标识,而软连接相当于windows快捷方式,删除了快捷方式并不会影响原数据。
linux file management 03 and 04--2week
硬链接和软连接区别总结;
--硬链接:同一个文件多个名字 软连接:不同文件
--硬:不支持跨分区 软:支持跨分区
--硬:不支持目录创建 软:支持
--相互关系:相互平等关系 软:相互依赖
--inode(索引节点):硬-相同 软:不同
--硬链接连接数会增长 软连接不会增长
--路径问题:硬-原始文件路径是相对当前工作路径 软:原始文件要写相对路径是相对于软连接路径而不是当前路径
--文件类型:硬;不变 软连接表现为:L
--具体命令实现方式也不同:硬-ln 软:ln -s
-->
file命令:检查文件的类型,然后确定适当的打开命令或应用程序使用
常用选项:
-b 列出文件辨识结果时,不显示文件名称
-f filelist 列出文件filelist中文件名的文件类型
-F 使用指定分隔符号替换输出文件名后默认的”:”分隔符
-L 查看对应软链接对应文件的文件类型
--help 显示命令在线帮助
linux file management 03 and 04--2week
#
10.
vim:文本编辑器
vi和vim区别:vi是系统自带的,VIM是vi的增强版
+# 打开文件后,让光标处于第#行的行首,+默认行尾
文本编辑种类:
行编辑器: sed
全屏编辑器:nano, vi
vim - Vi Improved
配置文件:永久有效
全局:/etc/vimrc
个人:~/.vimrc
使用vi:
linux file management 03 and 04--2week
使用vim命令:
linux file management 03 and 04--2week
linux file management 03 and 04--2week
使用vim命令来打开相对应的文件可以有行数和颜色等之间的增强。
三种主要模式:
命令(Normal)模式:默认模式,移动光标,剪切/粘贴文本
插入(Insert)或编辑模式:修改文本
扩展命令(extended command )模式:保存,退出等
命令模式 --> 插入模式
i insert, 在光标所在处输入
I 在当前光标所在行的行首输入
a append, 在光标所在处后面输入
A 在当前光标所在行的行尾输入
o 在当前光标所在行的下方打开一个新行
O 在当前光标所在行的上方打开一个新行
扩展命令模式:
:q 退出
:q! 强制退出,丢弃做出的修改
:wq 保存退出
:x 保存退出
#

11.
Copy the / etc / profile to the / tmp / directory, delete the blank beginning of the line / tmp / profile file with the Find and Replace command.
linux file management 03 and 04--2week
linux file management 03 and 04--2week
--grep name order: Grep search to a file named FILE input (or standard input if no file name or file name is given - words), looking for content contains the given pattern to match the PATTERN Row. By default, grep will contain the contents of the print line match out, corresponding GREP options command to see: man grep

Guess you like

Origin blog.51cto.com/14688684/2471801