Linux Day8: 目录管理

作者: 泥人吴 | 来源:发表于2018-10-09 23:39 被阅读5次

    学习寄言:时间相关函数在生信用的少,环境变量,还有目录路径需要加强理解。

    $ ls /
    bin   dev   initrd.img  lost+found  opt     root  snap  tmp   umac  vmlinuz
    boot  etc   lib     media       proc    run   srv   trainee   usr   wyx
    data  home  lib64   mnt     public  sbin  sys   trainee2  var
    
    • /boot:系统启动相关的文件,如内核,initrd,以及grub(bootloader)
    • /dev:设备文件
      1.块设备:随机访问,数据块(如有ABCD四个文件,想要访问C,可直接访问C,无需经过AB)
      2.字符设备:线性访问,按字符为单位
      3.设备号:主设备号,次设备号
    • /etc:配置文件
    • /home:用户的家目录;每个用户的家目录默认为/home/USERNAME。
    • /root:管理员的家目录。
    • lib:库文件
      1.静态库:.a
      2.动态库:.dll,
      3./lib/modules:内核模块文件
    • media:挂载点目录,移动设备
    • /mnt:挂载点目录,额外的临时文件系统
    • /opt:可选目录,第三方程序的安装目录。
    • /proc:伪文件系统,内核映射文件。
    • /sys:伪文件系统,跟硬件设备相关的属性映射文件。
    • /tmp:临时文件
    • /var:可变化的文件。
    • /bin:可执行文件,用户命令
    • /sbin:管理命令
    • /usr:shared,read-only

    文件命令规则:

    1.长度不超过255个字符
    2.不能使用/当文件名
    3.严格区分大小写

    目录管理:

    • ls
    • cd
    • pwd
    • mkdir:创建空目录,/root/x/y/z创建z目录,只有x/y路径存在时才能创建z文件。
    mkdir -pv test/m/n/1
    $ tree test
    test
    └── m
        └── n
            └── 1
    
    3 directories, 0 files
    
    $ #创建a_b,a_c,d_b,d_c
    $ #思想为:(a+b)(b+c)=ab+ac+db+dc
    $ mkdir -pv test/test2/{a,d}_{b,c}
    mkdir: created directory 'test/test2'
    mkdir: created directory 'test/test2/a_b'
    mkdir: created directory 'test/test2/a_c'
    mkdir: created directory 'test/test2/d_b'
    mkdir: created directory 'test/test2/d_c'
    
    $ mkdir test/test1/{x/m,y} -pv
    mkdir: created directory 'test/test1'
    mkdir: created directory 'test/test1/x'
    mkdir: created directory 'test/test1/x/m'
    mkdir: created directory 'test/test1/y'
    # { }展开作用。
    
    • rmdir:删除空文件
    $ rmdir test/test1
    rmdir: failed to remove 'test/test1': Directory not empty
    

    文件创造

    • touch:可用来创作空文件
    $ touch a
    $ file a
    a: empty
    
    NAME
           touch - change file timestamps
    
    SYNOPSIS
           touch [OPTION]... FILE...
    
    DESCRIPTION
           Update the access and modification times of each FILE to the current time.
    
           A  FILE argument that does not exist is created empty, unless -c or -h is sup‐
           plied.
    
           A FILE argument string of - is handled specially and causes  touch  to  change
           the times of the file associated with standard output.
    
           Mandatory arguments to long options are mandatory for short options too.
    
           -a     change only the access time
    
           -c, --no-create
                  do not create any files
    
    $ ls
    -aaa-  readme.txt  testtouch  tmp  wy
    $ touch a
    $ ls 
    a  -aaa-  readme.txt  testtouch  tmp  wy
    # 出现了a文件
    a  -aaa-  readme.txt  testtouch  tmp  wy
    $ touch -c c
    $ ls
    a  -aaa-  readme.txt  testtouch  tmp  wy
    # 未出现c文件
    

    touch是用来改时间窗的:

    $ stat a
      File: 'a'
      Size: 0           Blocks: 0          IO Block: 4096   regular empty file
    Device: fd71h/64881d    Inode: 27266337    Links: 1
    Access: (0664/-rw-rw-r--)  Uid: ( 1091/     ywu)   Gid: ( 1092/     ywu)
    Access: 2018-10-09 20:08:28.189589153 +0800
    Modify: 2018-10-09 20:08:28.189589153 +0800
    Change: 2018-10-09 20:08:28.189589153 +0800
     Birth: -
    $ touch a
    $ stat a
      File: 'a'
      Size: 0           Blocks: 0          IO Block: 4096   regular empty file
    Device: fd71h/64881d    Inode: 27266337    Links: 1
    Access: (0664/-rw-rw-r--)  Uid: ( 1091/     ywu)   Gid: ( 1092/     ywu)
    Access: 2018-10-09 20:11:24.229993592 +0800
    Modify: 2018-10-09 20:11:24.229993592 +0800
    Change: 2018-10-09 20:11:24.229993592 +0800
     Birth: -
    

    创建文件,可以使用文件编辑器:

    ASCII:美国国家信息交换代码

    • cp:复制:
    $ cp /etc/passwd /tmp/
    # 将passwd复制到tmp目录下
    $ cp /etc/passwd /tmp/test
    # 将passwd复制到tmp目录下:如果test不存在,那么passwd将更名为test;
    如果test为目录,那么psswd将放在test目录下;
    如果为文件,则覆盖test。
    
    $ cp /etc/init.d/ /tmp/
    cp: omitting directory '/etc/init.d/'
    # cp默认情况下是不会复制目录的
    # -R, -r, --recursive
                  copy directories recursively
    
    • mv:移动文件(原则基本类似cp);并更改文件名字
    • install:copy files and set attributes。
      -d:创建目录/文件;

    友情阅读推荐:

    生信技能树公益视频合辑:学习顺序是linux,r,软件安装,geo,小技巧,ngs组学!
    请猛戳下面链接
    B站链接:https://m.bilibili.com/space/338686099

    YouTube链接:https://m.youtube.com/channel/UC67sImqK7V8tSWHMG8azIVA/playlists

    生信工程师入门最佳指南:https://mp.weixin.qq.com/s/vaX4ttaLIa19MefD86WfUA

    学徒培养:https://mp.weixin.qq.com/s/3jw3_PgZXYd7FomxEMxFmw

    相关文章

      网友评论

        本文标题:Linux Day8: 目录管理

        本文链接:https://www.haomeiwen.com/subject/wbusaftx.html