• Day 4 文件管理 file management


    Day 4 文件管理 file management

    一 Linux系统单根目录结构 Single root directory

    一切皆文件的设计思想

    文件的时间 Time of the files

    访问时间 Access time

    Access time, shows the last time the content in the file was accessed. The ls and stat commands do not modify the access time of the file.

    修改时间 Modify time

    modify time, which shows the last time when the content of the file was changed.

    改变时间 Change time

    change time, which shows the permissions of the file, the owner, the group to which it belongs, and the time when the number of links changes.Of course, when the content changes, it also changes.

    文件的扩展名 Expanded name

    linux 文件没有扩展名

    No expanded name in Linux

    // 方法一:
    ls -l 文件名   //看第一个字符
    -   普通文件(文本文件,二进制,压缩文件,电影,图片。。。),例如:/bin/ls
    d   目录文件(蓝色),例如/home/
    b   设备文件(块设备)存储设备硬盘,U盘,例如:/dev/sda
    c   设备文件(字符设备)打印机,例如:终端/dev/tty1
    s   套接字文件,例如:/run/rpcbind.sock
    p   管道文件,例如:/run/systemd/initctl/fifo
    l   链接文件(淡蓝色),例如:/bin

    ps:通过颜色判断文件的类型是错误的!!!

    // 方法二:
    [root@xxx ~]# file /etc/grub.conf

    二 系统目录结构与作用 System directory structure and functions

    bin 命令相关目录

    sbin 命令相关目录(管理员)

    boot 启动目录

    usr 系统文件目录

    home 普通用户家目录

    root 管理员家目录

    etc 配置文件目录

    /etc/sysconfig/network-script/ifcfg-*,网络配置文件
    /etc/hostname,系统主机名配置文件
    /etc/resolv.conf,dns客户端配置文件
    /etc/hosts,本地域名解析配置文件
    /etc/fstab   系统挂载目录 开机自启动挂载列表
    /etc/passwd 系统用户文件

    dev 设备文件目录

    /dev/cdrom 和/dev/sr0,系统光盘镜像设备
    /dev/null,黑洞设备,只进不出。类似于垃圾回收站
    /dev/random,生成随机数的设备
    /dev/zero,能源源不断地产生数据,类似于取款机,随时随地取钱
    /dev/pts/0,虚拟的Bash Shell终端,提供给远程用户使用 0代表第一个终端 1代表第2个终端
    以此类推
    /dev/stderr,错误输出    
    /dev/stdin,标准输入
    /dev/stdout,标准输出

    存储设备挂载目录

    drwxr-xr-x.  2 root root  4096 Apr 11  2018 media # 移动设备默认的挂载点
    drwxr-xr-x. 2 root root 4096 Apr 11 2018 mnt # 手工挂载设备的挂载点
    drwxr-xr-x. 2 root root 4096 Apr 11 2018 opt # 早期第三方厂商的软件存放的目录.
    drwxrwxrwt. 10 root root 4096 Jul 9 15:16 tmp # 临时存放文件,类似于回收站,超过十天自动删除
       

    三 绝对路径和相对路径

    Absolute path and relative path

    An absolute path refers to the complete details needed to locate a file or folder, starting from the root element and ending with the other subdirectories. Absolute paths are used in websites and operating systems for locating files and folders. An absolute path is also known as an absolute pathname or full path.

    A relative path refers to a location that is relative to a current directory. Relative paths make use of two special symbols, a dot (.) and a double-dot (..), which translate into the current directory and the parent directory. Double dots are used for moving up in the hierarchy.

    相对路径:以引用文件之网页所在位置为参考基础,而建立出的目录路径。因此,当保存于不同目录的网页引用同一个文件时,所使用的路径将不相同,故称之为相对。

    绝对路径:以Web 站点根目录为参考基础的目录路径。之所以称为绝对,意指当所有网页引用同一个文件时,所使用的路径都是一样的。其实绝对路径与相对路径的不同处,只在于描述目录路径时,所采用的参考点不同。由于对网站上所有文件而言,根目录这个参考点对所有文件都是一样的,因此,运用以根目录为参考点的路径描述方式才会被称之为绝对路径。

    四 文件管理

    4.1 基本命令 basic commands

    1.查看当前所在的目录 View the current directory

    [root@localhost ~]# pwd 
    /root

    2.切换目录 switch directory

    cd 绝对路径 
    cd /home/alice
    cd ~alice cd
    cd 相对路径
    cd home/alice
    cd - 返回上次目录 return to the previous directory
    cd 直接回家,等同于cd ~ return to home directory
    cd . 保持当前目录不变
    cd .. 切换到当前目录的上一级目录 return to the parent directory

    3.查看目录树 view directory tree

    安装tree目录
    yum install tree -y
    tree -a
    tree -d
    tree -L 1
    tree -F

    4.2 创建/复制/移动/删除

    创建

    touch 文件
    mkdir 目录
    touch /root/aaa/{a,b,c}
    -v 显示提示信息
    -f 强制参数
    -p 包括父母的创建

    复制

    cp 旧路径 新路径
    -r 递归

    移动/重命名

    move 旧 新

    删除

    rm 

    4.3 查看文件内容

    cat 查看文件内容
    less 全部显示
    more 全部显示
    head 从头开始
    tail 从最后开始
    grep 过滤

     

    Day 4 Exercises

    1) 开启Linux操作系统,要求以root用户登录GNOME图形界面,右击桌面打开终端

    2) 使用命令切换到root用户的家目录

    cd /~

    3) 确定当前用户所在的工作目录

    pwd

    4) 创建目录wg

    mkdir wg

    5) 使用绝对路径的方法在wg目录下新建文件a.txt

    touch a.txt /root/wg

    6) 进入wg目录

    cd /root/wg

    7) 使用相对路径的方法在当前目录下新建wg01目录和b.txt文件

    mkdir wg01

    touch b.txt

    8) 以长列表格式列出当前目录下的内容

    ls -l

    9) 删除空目录wg01

    rm -r wg01

    yes

    10) 进入上一级工作目录

    cd ..

    11) 强制删除非空目录wg

    rm -rf wg

    12) 复制/etc/passwd到当前目录,名为file1

    cp /etc/passwd ~/file1

    13) 不停的以只读的方式查看file1文件的内容

    cat file1

    14) 查看file1文件的前3行内容

    head -3 file1

    15) 查看file1文件的后2行内容

    tail -2 file1

    16) 以百分比的方式分页查看file1文件的内容

    17) 以上下翻页的方法分页查看file1文件的内容

    less file1

    Day 4 Vim Exercises

    Exercise 1

    1) 使用vi编辑器编辑文件/1.txt进入编辑模式写入内 容“hello world”

    touch 1.txt

    vi 1.txt

    a

    hello world

    Esc

    2) 进入命令行模式复制改行内容,在下方粘贴80行

    光标移到 hello world 行 按 yy

    按 80p

    3) 快速移动光标到文件的最后一行

    cAPS lock

    G

    4) 快速移动光标到当前屏幕的中间一行

    Caps lock

    M

    5) 快速移动光标到文件的第五行

    5

    Caps lock

    G

    6) 在下方插入新的一行内容“welcome to beijing”

    o

    Welcome to Beijing

    7) 删除刚插入的一行

    Esc

    dd

    8) 撤销上一步的操作

    u

    9) 进入扩展模式,执行文件的保存退出操作

    :wq

    10) 修改相应文件,内容如下:

     

    Exercise 2

    1.将/etc/passwd 复制到/root/目录下,并重命名为 test.txt

    cp /etc/passwd /root/test.txt

    2.用vim打开test.txt并显示行号

    vi test.txt

    :set nu

    3.分别向下、向右、向左、向右移动5个字符,分别向下、 向上翻两页

    4.把光标移动到第10行,让光标移动到行末,再移动到行 首,移动到test.txt文件的最后一行,移动到文件的首行

    10 G

    End

    Home

    G

    gg

    5.搜索文件中出现的 root 并数一下一共出现多少个

    /root

    6.把从第一行到第三行出现的root 替换成admin,然后还 原上一步操作

    :1,3 s/root/admin/g

    u

    8.把整个文件中所有的root替换成admin

    :% s/root/admin/g

    9.把光标移动到20行,删除本行,还原上一步操作

    20G

    dd

    u

    11.删除从5行到10行的所有内容,还原上一步操作

    5G

    6dd

    u

    12.复制2行并粘贴到11行下面,还原上一步操作(按两次 u)

    2G

    YY

    11G

    p

    uu

    13.复制从11行到15行的内容并粘贴到8行上面,还原上一 步操作(按两次u)

    11G

    5YY

    8G

    P

    uu

    14.把13行到18行的内容移动文件的尾部,还原上一步操作 (按两次u)

    13G

    6YY

    G

    p

    uu

    15.将文件中所有的/sbin/nologin为/bin/bash

    :% s#/sbin/nologin#/bin/bash#g

    16.在第一行下面插入新的一行,并输入"# Hello!"

    gg

    o

    "# hello!"

    17.保存文档并退出

    :wq

     

  • 相关阅读:
    Hadoop学习笔记(九)HDFS架构分析
    Hadoop学习笔记(九)HDFS架构分析
    Hadoop学习笔记(八)MapReduce深入分析
    Hadoop学习笔记(八)MapReduce深入分析
    Hadoop学习笔记(七)
    Hadoop学习笔记(七)
    Hadoop学习笔记(六)启动Shell分析
    Hadoop学习笔记(六)启动Shell分析
    「2018-11-05模拟赛」T5 传送机 解题报告
    NOIP 2018 普及组 解题报告
  • 原文地址:https://www.cnblogs.com/fengshili666/p/14118855.html
Copyright © 2020-2023  润新知