zoukankan      html  css  js  c++  java
  • 系统的目录结构

    1.在/目录下,用ls查看根目录的所有目

    /: 所有linux操作系统的顶点目录,不像windows,每个分区都有一个顶点目

    /boot     存放系统启动时相关的文件,比如kernel内核,grub引导菜单.(不要删除)

    /bin       存放的都是命令,但仅普通用户能执行

    /sbin     超级管理员能执行的命令.
    /home      存放普通用户的家目录
    /root      超级管理员的家目录,普通用户是无法进入
    /etc       存放配置文件的目录,
    /etc/hostname    主机名
    /etc/hosts      本地解析域名一种方式
    /etc/sysconfig/network-script/ifcfg-*   网卡的配置文件
    /dev         设备目录,硬盘硬盘的分区光盘.....
    /dev/null        黑洞,接收所有的东西,只进不出
    /dev/zero       摇钱树,可以生产源源不断的数据
    /dev/random      产生随机数的一个设备
    /dev/pts/0        虚拟的Bash Shell终端,提供给远程用户使用 0,代表一个终端 1代表2个终端 以此类推
    /usr          类似于windows的C盘下面的windows目录
    /usr/lib           共享库文件,后缀都是so结尾, share object
    /usr/lib64          共享库文件64位,后缀都是so结尾, share object
    /usr/local        早起大家都把软件放在这个目录下,和windows C:ProgramFile

    /var          存放一些可变化的内容,比如/var/log日志,可以人为让其发生变化,也或者是随着时间推移产生变化
    /tmp           存放临时文件,无论哪个用户都可以放
    /proc           反馈当前运行的进程的状态信息.
    /run         存放程序运行后所产生的pid文件
    /media                         可移除的装置,媒体,DvD之类的挂载区

    mnt         提供挂载的一个目录
    /opt          早期第三方厂商的软件存放的目录.
    /srv           物理设备产生的一些文件


    路径就是对文件进行定位的一种方式。

    [root@www ~]# cd /usr
    [root@www usr]# cd ../
    [root@www /]# pwd
    /

    [root@www /]# cd /usr/       #进入到/usr目录下
    [root@www usr]# #cd lib64/    #进入到当前usr目录下lib64目录(这种常用)
    [root@www usr]# cd ./lib64/    #进入到当前usr目录下lib64目录
    [root@www lib64]# pwd      #打印当前所在的工作目录
    /usr/lib64
    [root@www lib64]# cd .././      #..回退到上一级目录/usr .当前目录(所有不会发生变化)
    [root@www usr]# cd ./lib64/
    [root@www lib64]# cd ../../      #../../ 连续回退两次目录
    [root@www /]# pwd           #打印当前所在的工作目录
    /

    2.那什么是绝对路径,什么又是相对路径呢?
    绝对路径永远都是相对于根文件夹的。它们的标志就是第一个字符永远都是“/”。
    相对路径永远都是相对于我们所处的文件夹位置。它们的第一个字符没有“/”。

    绝对路径: 只要从/开始的路径,比如ls /home/alice/file
    相对路径: 相对于当前目录来说,比如 a.txt ./a.txt ../bob/a.mp3 [加入: 此时在目录/home/alice]
    [root@www /]# ls /etc/sysconfig/ #绝对路径
    [root@www /]# cd etc/sysconfig/ #相对路径

    [root@www sysconfig]# pwd    #查看我当前在哪
    /etc/sysconfig
    [root@www sysconfig]# #cd /var/log/    #如果我要进入/var/log目录,可以使用相绝对路径
    [root@www sysconfig]# cd ../../var/log/
    [root@www log]# pwd
    /var/log
    小结: 所谓的(.)和(..)目录实际上属于相对路径的一种表示形式。

    ------------------------------------------------------
    1.定位: 确定文件的位置
    2.路径: 需要一个明确的路径才能定位到对应的文件
    3. : 代表当前所在的目录(取决于我当前在哪)
    4.. : 当前目录的上一级目录(取决于我当前在哪)
    5.绝对路径 只要以/开始,都算绝对路径(能够精准定位文件所在的位置)
    6.相对路径 取决于当前所在的位置(需要看在哪,具体情况具体分析)

     

    示例
    [root@bgx /]# useradd alice
    [root@bgx /]# ls /home/alice/file1
    [root@bgx /]# ls ~/file2 #/root/file2
    [root@bgx /]# ls ~alice/file3 #/root/alice/file3

    [root@bgx /]# ls abc
    [root@bgx usr]# ls ../file3
    [root@bgx /]# ls file4
    [root@bgx /]# ls abc/file5


    cd改变目录,常见的使用方法
    # cd 绝对路径 cd /etc/hostname
    # cd 相对路径 cd test/abc cd . cd ..
    -------------------------------------
    # cd      #切换目录,例: cd /etc
    # cd ~     #切换回当前用户的家目录,注意:root和普通用户是否有所不同吗?
    # cd -      #切换回上一次所在的目录
    # cd .      #代表当前目录,一般在拷贝、移动等情况下使用 cp /etc/hostname ./
    # cd ..     #切换回当前目录的上级目录

    ~ 当前用户的家目录
    -----------------------cd和cd ~
    [long@www ~]$ cd /etc/sysconfig/network-scripts/
    [long@www network-scripts]$ pwd
    /etc/sysconfig/network-scripts
    [long@www network-scripts]$ cd
    [long@www ~]$ pwd
    /home/long
    ---------------------------------------------------------------
    [long@www ~]$ cd /etc/sysconfig/network-scripts/
    [long@www network-scripts]$ pwd
    /etc/sysconfig/network-scripts
    [long@www network-scripts]$ cd ~
    [long@www ~]$ pwd
    /home/long


    -----------------------------------------------touch创建文件
    # touch file #无则创建,有则修改时间
    # touch file2 file3
    # touch file5 /home/long/file4
    # touch file{a,b,c} #a和b和c {}集合,等价 touch filea fileb filec
    # touch file{1..10} #touch file1 file2 file3 file..Number
    # touch file{a..z} #a-z


    [root@www ~]# touch /home/tt/file.txt #报错提示,代表/home/没有tt这个目录
    touch: cannot touch '/home/tt/file.txt': No such file or directory

    -----------------------------------------------mkdir创建目录
    2.目录创建命令mkdir ->make directory
    # 选项:-v 显示详细信息 -p 递归创建目录
    # mkdir dir1
    # mkdir /home/od/dir1 /home/od/dir2 -pv
    # mkdir -v /home/od/{dir3,dir4}
    # mkdir -pv /home/od/dir5/dir6
    # mkdir -pv /home/{od/{diu,but},boy}


    [root@www ~]# mkdir /home/oldboyedu/tt/dir1 #在/home/oldboyedu/tt/目录不存在
    mkdir: cannot create directory '/home/oldboyedu/tt/dir1': No such file or directory

    [root@www ~]# mkdir -pv /home/oldboyedu/tt/dir1 #-p递归 -v:显示创建的效果
    mkdir: created directory '/home/oldboyedu/tt'
    mkdir: created directory '/home/oldboyedu/tt/dir1'

    [root@www ~]# mkdir /home/oldboyedu/tt/dir1 #如果目录已经存在,重复执行会报错
    mkdir: cannot create directory '/home/oldboyedu/tt/dir1': File exists
    [root@www ~]# mkdir -p /home/oldboyedu/tt/dir1 #如果希望重复创建文件不提示,加上-p选项即可


    题:
    /home/bob
    /home/bob/test1/tt1
    /home/bob/test2/tt1
    /home/alice
    /home/alice/tt1
    /home/alice/tt2
    /tmp/boy
    /tmp/girl
    /root/test/test1
    /root/test/test2
    /root/tset
    /backup

    [root@www ~]# mkdir -pv /{home/{bob/test{1,2}/tt1,alice/tt{1,2}},tmp/{boy,girl},root/{test/{test1,test2},tset},backup}


    ----------------------------------------------tree以目录树显示
    [root@www ~]# yum install tree -y

    选项: -L level级别 -d 只看目录,不看其他
    [root@www ~]# tree -L 1 / tree /home/boy -L 2 -d
    /
    |-- backup
    |-- bin -> usr/bin
    |-- boot
    |-- dev
    |-- etc
    |-- home
    |-- lib -> usr/lib
    |-- lib64 -> usr/lib64
    |-- media
    |-- mnt
    |-- opt
    |-- proc
    |-- root
    |-- run
    |-- sbin -> usr/sbin
    |-- srv
    |-- sys
    |-- tmp
    |-- usr
    `-- var


    -------------------------------------------------复制copy --->cp
    #选项: -v:详细显示命令执行的操作 -r: 递归处理目录与子目录 -p: 保留源文件或目录的属性

    [root@www ~]# cp --help
    Usage: cp [OPTION]... [-T] SOURCE DEST
    or: cp [OPTION]... SOURCE... DIRECTORY
    or: cp [OPTION]... -t DIRECTORY SOURCE...
    Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

    # cp file /tmp/file_copy
    # cp name /tmp/name #不修改名称
    # cp file /tmp/ #不修改名称
    # cp -p file /tmp/file_p #-p保持原文件或目录的属性
    # cp -r /etc/ /tmp/ #复制目录需要使用-r参数, 递归复制
    # cp -v /etc/hosts /etc/hostname /tmp #拷贝多个文件至一个目录
    # cp -v /etc/{hosts,hosts.bak}
    # cp -v /etc/hosts{,-org}


    1.修改了一下这个文件属性
    [root@www ~]# chown adm file.txt
    [root@www ~]# ll file.txt
    -rw-r--r--. 1 adm root 0 Apr 1 20:20 file.txt

    2.没有添加任何参数时,使用root用户拷贝该文件的效果
    [root@www ~]# cp file.txt /tmp/
    cp: overwrite '/tmp/file.txt'? y
    [root@www ~]# ll /tmp/file.txt
    -rw-r--r--. 1 root root 0 Apr 1 23:58 /tmp/file.txt

    2.添加-p参数,此时在进行拷贝,会保留这个文件原因的属性
    [root@www ~]# cp -p file.txt /tmp/
    cp: overwrite '/tmp/file.txt'? y
    [root@www ~]# ll /tmp/file.txt
    -rw-r--r--. 1 adm root 0 Apr 1 20:20 /tmp/file.txt

    如果希望重复拷贝,以及拷贝目录
    [root@www ~]# /bin/cp -r /etc/ /tmp/
    [root@www ~]# cp -r /etc/ /tmp/

    [root@www ~]# cp -v /etc/{hosts,hostname} /tmp/
    [root@www ~]# cp -v /etc/hosts /etc/hostname /tmp/
    '/etc/hosts' -> '/tmp/hosts'
    '/etc/hostname' -> '/tmp/hostname'

    [root@www ~]# cp -v /etc/{hosts,hosts.bak}
    '/etc/hosts' -> '/etc/hosts.bak'

    [root@www ~]# cp -v /etc/hosts{,-org}
    '/etc/hosts' -> '/etc/hosts-org'

    扩展
    [root@www ~]# cp -v -t /tmp/ /etc/hosts
    '/etc/hosts' -> '/tmp/hosts'
    [root@www ~]# cp -vt /tmp/ /etc/hosts
    '/etc/hosts' -> '/tmp/hosts'

    错误示例
    [root@www ~]# cp -v /etc/{hostss,hostname} /tmp/
    cp: cannot stat '/etc/hostss': No such file or directory
    '/etc/hostname' -> '/tmp/hostname'


    ----------------------------------------------------------move移动 -->mv
    [root@www ~]# mv --help
    Usage: mv [OPTION]... [-T] SOURCE DEST
    or: mv [OPTION]... SOURCE... DIRECTORY
    or: mv [OPTION]... -t DIRECTORY SOURCE..

    # mv file file1 #原地移动算改名,可以修改文件或者修改目录
    # mv file1 /tmp/ #移动文件至tmp目录
    # mv /tmp/file1 ./ #移动tmp目录的文件至当前目录
    # mv dir/ /tmp/ #移动目录至/tmp目录下
    # touch file{1..3}
    # mv file1 file2 file3 /opt/ #移动多个文件或至同一个目录 mv file{1..3} /opt

    # mkdir dir{1..3}
    # mv dir1/ dir2/ dir3/ /opt/ #移动多个目录至同一个目录


    -------------------------------------------------------示例
    [root@www ~]# mv file3 file4 file5 /tmp/ #将当前/root目录下的file3 4 5 移动到/tmp
    [root@www opt]# mv /tmp/file1 ./ #移动/tmp目录下面的file1至当前用户所在的/opt目录下

    [root@www opt]# cd /home/long/
    [root@www long]# mv /tmp/file3 ../
    [root@www long]# ls /home/

    [root@www ~]# mv -t /tmp/ filea fileb ./filec
    [root@www ~]# ls /tmp/file{a..c}
    /tmp/filea /tmp/fileb /tmp/filec

    [root@www ~]# mv file2 /tmp123 #如果目录的目录没有在结尾增加/,同时这个目录页不存在,移动文件到/目录改名
    [root@www ~]# ls /tmp123
    /tmp123
    [root@www ~]# mv file3 /tmp123/ #如果移动的目录目录结尾增加了/ 那么系统始终会认为目标是一个目录
    mv: failed to access '/tmp123/': Not a directory


    ----------------------------------------------------删除rm remove
    #选项:-r: 递归 -f: 强制删除(alias别名,默认会提示是否删除) -v: 详细过程

    # rm file.txt #删除文件, 默认rm存在alias别名,rm -i所以会提醒是否删除文件
    # rm -f file.txt #删除文件, 不提醒

    # rm -r dir/ #递归删除目录,会提示
    # rm -rf dir/ #强制删除目录,不提醒(慎用)

    --------------------------------------------------------------------示例
    #1.rm删除示例
    # mkdir /home/dir10
    # touch /home/dir10/{file2,file3,.file4}
    # rm -f /home/dir10/file* //不包括隐藏文件 *代表所有的意思
    # ls /home/dir10/ -a
    . .. .file4

    #2.rm删除示例2
    # touch file{1..10}
    # touch {1..10}.pdf
    # rm -rf file*
    # rm -rf *.pdf


    删除不提示的方法
    [root@www ~]# /bin/rm file9
    [root@www ~]# m file10
    [root@www ~]# rm -f filed

    注意:
    1.删文件,最好不要添加-r参数, 比如: rm -f file
    2.删文件时,使用* 需要注意,尽可能先用ls 取精确匹配要删除的文件,然后再使用rm -f删除

  • 相关阅读:
    flume sink两种类型 file_rool 自定义sing com.mycomm.MySink even if there is only one event, the event has to be sent in an array
    为什么引入进程20年后,又引入线程?
    As of Flume 1.4.0, Avro is the default RPC protocol.
    Google Protocol Buffer 的使用和原理
    Log4j 2
    统一日志 统一订单
    网站行为跟踪 Website Activity Tracking Log Aggregation 日志聚合 In comparison to log-centric systems like Scribe or Flume
    Percolator
    友盟吴磊:移动大数据平台的架构、实践与数据增值
    Twitter的RPC框架Finagle简介
  • 原文地址:https://www.cnblogs.com/longren/p/10725835.html
Copyright © 2011-2022 走看看