Linux文件及目录管理命令基础,


1、命令基础

1.1、命令操作语法

  • 命令 [参数] [文件]

    • 参数,可有可无

    • 文件,可有可无

2、基础命令

2.1、查看当前工作目录

  • pwd

    • print name of current/workin directory

    • 打印 名字 或 工作 目录

      [root@oldboyedu ~]# pwd
      /root
      [root@oldboyedu ~]# cd /opt/
      [root@oldboyedu /opt]# pwd
      /opt
      [root@oldboyedu /opt]# cd /etc/
      [root@oldboyedu /etc]# pwd
      /etc
      [root@oldboyedu /etc]# 
      

2.2、切换目录

  • cd

    • cd 目录

      [root@oldboyedu /etc]# cd -   返回上一次所在目录
      /opt
      [root@oldboyedu /opt]# cd ..  去上一级目录
      [root@oldboyedu /]# cd .  去当前目录
      [root@oldboyedu /]# 
      [root@oldboyedu /]# cd ~ 去当前用户家目录
      
      

相对路径与绝对路径:

  • 相对路径:
    • 不从/开始的路径是相对路径
  • 绝对路径
    • 从/开始的路径

2.3、以树形结构显示

  • tree (大树)

    • -L 制定层数

      [root@oldboyedu ~]# tree -L 1 /
      /
      ├── 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
      
    • -d 显示目录

      [root@oldboyedu ~]# tree -L 1 -d /etc/
      /etc/
      ├── abrt
      ├── alternatives
      ├── audisp
      ├── audit
      ├── bash_completion.d
      ├── binfmt.d
      ├── chkconfig.d
      ├── cron.d
      
      

2.4、创建目录

  • mkdir

    [root@oldboyedu ~]# ls
    anaconda-ks.cfg
    [root@oldboyedu ~]# mkdir oldboy
    [root@oldboyedu ~]# ls
    anaconda-ks.cfg  oldboy
    [root@oldboyedu ~]# ls /
    bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
    boot  etc  lib   media  opt  root  sbin  sys  usr
    [root@oldboyedu ~]# mkdir /oldboy
    [root@oldboyedu ~]# ls
    anaconda-ks.cfg  oldboy
    [root@oldboyedu ~]# ls /
    bin   dev  home  lib64  mnt     opt   root  sbin  sys  usr
    boot  etc  lib   media  oldboy  proc  run   srv   tmp  var
    
    
    • -p 递归创建

      [root@oldboyedu ~]# mkdir sun/yu
      mkdir: cannot create directory ‘sun/yu’: No such file or directory
      #mkdir:无法创建目录“sun/yu”:没有这样的文件或目录
      [root@oldboyedu ~]# mkdir -p sun/yu
      [root@oldboyedu ~]# ls
      anaconda-ks.cfg  oldboy  sun
      [root@oldboyedu ~]# ls sun/
      yu
      

2.5、创建文件

  • touch

    [root@oldboyedu ~]# touch 1
    [root@oldboyedu ~]# ls
    1  anaconda-ks.cfg  oldboy  sun
    
    • {} 生成序列
    #我想要一下创建出100个txt文件怎么办?
    [root@oldboyedu ~]# touch {1..100}.txt
    [root@oldboyedu ~]# ll
    total 0
    -rw-r--r--. 1 root root 0 Apr  5 09:04 100.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 10.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 11.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 12.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 13.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 14.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 15.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 16.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 17.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 18.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 19.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 1.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 20.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 21.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 22.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 23.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 24.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 25.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 26.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 27.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 28.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 29.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 2.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 30.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 31.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 32.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 33.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 34.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 35.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 36.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 37.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 38.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 39.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 3.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 40.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 41.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 42.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 43.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 44.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 45.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 46.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 47.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 48.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 49.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 4.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 50.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 51.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 52.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 53.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 54.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 55.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 56.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 57.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 58.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 59.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 5.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 60.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 61.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 62.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 63.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 64.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 65.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 66.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 67.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 68.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 69.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 6.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 70.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 71.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 72.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 73.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 74.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 75.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 76.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 77.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 78.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 79.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 7.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 80.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 81.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 82.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 83.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 84.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 85.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 86.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 87.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 88.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 89.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 8.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 90.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 91.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 92.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 93.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 94.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 95.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 96.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 97.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 98.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 99.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:04 9.txt
    
    #如果我在当前目录创建了a b c d四个目录,再创建a b c d四个文件会不会成功
    [root@oldboyedu ~]# mkdir a b c d
    [root@oldboyedu ~]# ls
    a  b  c  d
    [root@oldboyedu ~]# touch a b c d
    [root@oldboyedu ~]# ll
    total 0
    drwxr-xr-x. 2 root root 6 Apr  5 09:06 a
    drwxr-xr-x. 2 root root 6 Apr  5 09:06 b
    drwxr-xr-x. 2 root root 6 Apr  5 09:06 c
    drwxr-xr-x. 2 root root 6 Apr  5 09:06 d
    这是为什么呢? 因为在Linux系统中一切皆文件,目录也是文件
    

2.5、显示目录下的内容

  • ls (list)

    [root@oldboyedu ~]# ls
    a  b  c  d
    
    
    • -l (long)当前目录下的内容以长格式显示

      [root@oldboyedu ~]# ls -l
      total 0
      drwxr-xr-x. 2 root root 6 Apr  5 09:06 a
      drwxr-xr-x. 2 root root 6 Apr  5 09:06 b
      drwxr-xr-x. 2 root root 6 Apr  5 09:06 c
      drwxr-xr-x. 2 root root 6 Apr  5 09:06 d
      
      
    • -d 只显示本身目录

      [root@oldboyedu ~]# touch {1..5}.txt
      [root@oldboyedu ~]# ls
      1.txt  2.txt  3.txt  4.txt  5.txt  a  b  c  d
      [root@oldboyedu ~]# ls -d
      .
      
      
    • -a 显示所有文件,包含隐藏文件(以.开头的文件)

      [root@oldboyedu ~]# ls -la
      total 24
      dr-xr-x---.  6 root root 213 Apr  5 09:10 .
      dr-xr-xr-x. 17 root root 224 Apr  5 09:03 ..
      -rw-r--r--.  1 root root   0 Apr  5 09:10 1.txt
      -rw-r--r--.  1 root root   0 Apr  5 09:10 2.txt
      -rw-r--r--.  1 root root   0 Apr  5 09:10 3.txt
      -rw-r--r--.  1 root root   0 Apr  5 09:10 4.txt
      -rw-r--r--.  1 root root   0 Apr  5 09:10 5.txt
      drwxr-xr-x.  2 root root   6 Apr  5 09:06 a
      drwxr-xr-x.  2 root root   6 Apr  5 09:06 b
      -rw-------.  1 root root 554 Apr  4 18:35 .bash_history
      -rw-r--r--.  1 root root  18 Dec 29  2013 .bash_logout
      -rw-r--r--.  1 root root 176 Dec 29  2013 .bash_profile
      -rw-r--r--.  1 root root 176 Dec 29  2013 .bashrc
      drwxr-xr-x.  2 root root   6 Apr  5 09:06 c
      -rw-r--r--.  1 root root 100 Dec 29  2013 .cshrc
      drwxr-xr-x.  2 root root   6 Apr  5 09:06 d
      -rw-r--r--.  1 root root 129 Dec 29  2013 .tcshrc
      
    • -A 显示所有文件,不包含. .. 开头的文件

      [root@oldboyedu ~]# ls -lA
      total 24
      -rw-r--r--. 1 root root   0 Apr  5 09:10 1.txt
      -rw-r--r--. 1 root root   0 Apr  5 09:10 2.txt
      -rw-r--r--. 1 root root   0 Apr  5 09:10 3.txt
      -rw-r--r--. 1 root root   0 Apr  5 09:10 4.txt
      -rw-r--r--. 1 root root   0 Apr  5 09:10 5.txt
      drwxr-xr-x. 2 root root   6 Apr  5 09:06 a
      drwxr-xr-x. 2 root root   6 Apr  5 09:06 b
      -rw-------. 1 root root 554 Apr  4 18:35 .bash_history
      -rw-r--r--. 1 root root  18 Dec 29  2013 .bash_logout
      -rw-r--r--. 1 root root 176 Dec 29  2013 .bash_profile
      -rw-r--r--. 1 root root 176 Dec 29  2013 .bashrc
      drwxr-xr-x. 2 root root   6 Apr  5 09:06 c
      -rw-r--r--. 1 root root 100 Dec 29  2013 .cshrc
      drwxr-xr-x. 2 root root   6 Apr  5 09:06 d
      -rw-r--r--. 1 root root 129 Dec 29  2013 .tcshrc
      

2.6、复制文件和目录

  • cp (copy)

    • cp [OPTION]... SOURCE... DIRECTORY
      选项 源 目录

      • -r 递归,复制目录

        [root@oldboyedu ~]# ls
        1.txt  2.txt  3.txt  4.txt  5.txt  a  b  c  d
        [root@oldboyedu ~]# cp a /opt/
        cp: omitting directory ‘a
        cp:省略目录'a
        [root@oldboyedu ~]# cp -r a /opt/
        [root@oldboyedu ~]# ll /opt/
        total 0
        drwxr-xr-x. 2 root root 6 Apr  5 09:14 a
        
        
      • -p 保持文件属性

        [root@oldboyedu ~]# cp -p 2.txt /opt/
        [root@oldboyedu ~]# ll 2.txt /opt/2.txt 
        -rw-r--r--. 1 root root 0 Apr  5 09:10 2.txt
        -rw-r--r--. 1 root root 0 Apr  5 09:10 /opt/2.txt
        
        
      • -a 保持文件属性和链接

        [root@oldboyedu ~]# ll /etc/system-release
        lrwxrwxrwx. 1 root root 14 Apr  4 18:05 /etc/system-release -> centos-release
        [root@oldboyedu ~]# cp -a /etc/system-release ./
        [root@oldboyedu ~]# ll /etc/system-release system-release 
        lrwxrwxrwx. 1 root root 14 Apr  4 18:05 /etc/system-release -> centos-release
        lrwxrwxrwx. 1 root root 14 Apr  4 18:05 system-release -> centos-release
        
        
      • -i 确认

        [root@oldboyedu ~]# ls
        1.txt  2.txt  3.txt  4.txt  5.txt  a  b  c  d  system-release
        [root@oldboyedu ~]# cp 1.txt /opt/
        [root@oldboyedu ~]# cp 1.txt /opt/
        cp: overwrite ‘/opt/1.txt’? y
        这是因为alias cp='cp -i'搞的鬼
        
        

2.7、查看或设置别名

  • alias

    [root@oldboyedu ~]# alias
    alias cp='cp -i'
    alias egrep='egrep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias grep='grep --color=auto'
    alias l.='ls -d .* --color=auto'
    alias ll='ls -l --color=auto'
    alias ls='ls --color=auto'
    alias mv='mv -i'
    alias rm='rm -i'
    alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
    
    • 设置别名

      alias cp='cp -i'
      

怎么不使用别名:

2.8、删除文件或目录

  • rm

    • -f 强制删除(只能删除文件)

      [root@oldboyedu ~]# rm -f 1.txt 
      [root@oldboyedu ~]# ll
      total 0
      -rw-r--r--. 1 root root  0 Apr  5 09:10 2.txt
      -rw-r--r--. 1 root root  0 Apr  5 09:10 3.txt
      -rw-r--r--. 1 root root  0 Apr  5 09:10 4.txt
      -rw-r--r--. 1 root root  0 Apr  5 09:10 5.txt
      drwxr-xr-x. 2 root root  6 Apr  5 09:06 a
      drwxr-xr-x. 2 root root  6 Apr  5 09:06 b
      drwxr-xr-x. 2 root root  6 Apr  5 09:06 c
      drwxr-xr-x. 2 root root  6 Apr  5 09:06 d
      lrwxrwxrwx. 1 root root 14 Apr  4 18:05 system-release -> centos-release
      [root@oldboyedu ~]# rm -f a
      rm: cannot remove ‘a’: Is a directory
      rm:无法删除“a”:是一个目录
      
    • -r 递归删除,删除目录和文件

      [root@oldboyedu ~]# rm -rf a
      [root@oldboyedu ~]# ll
      total 0
      -rw-r--r--. 1 root root  0 Apr  5 09:10 2.txt
      -rw-r--r--. 1 root root  0 Apr  5 09:10 3.txt
      -rw-r--r--. 1 root root  0 Apr  5 09:10 4.txt
      -rw-r--r--. 1 root root  0 Apr  5 09:10 5.txt
      drwxr-xr-x. 2 root root  6 Apr  5 09:06 b
      drwxr-xr-x. 2 root root  6 Apr  5 09:06 c
      drwxr-xr-x. 2 root root  6 Apr  5 09:06 d
      lrwxrwxrwx. 1 root root 14 Apr  4 18:05 system-release -> centos-release
      
      
    • -i 确认

      alias rm='rm -i'
      

注意:

  • 尽量不要是用rm,如果要用使用find代替
  • 设置rm别名如:alias rm='echo 请使用find'
  • 删除前备份
  • 把要删除的文件先移动到/tmp,在删除
  • 进到要删除文件的上一级目录下在删除文件

2.9、取消别名

  • unalias

    [root@oldboyedu ~]# alias 
    alias cp='cp -i'
    alias egrep='egrep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias grep='grep --color=auto'
    alias l.='ls -d .* --color=auto'
    alias ll='ls -l --color=auto'
    alias ls='ls --color=auto'
    alias mv='mv -i'
    alias rm='rm -i'
    alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
    [root@oldboyedu ~]# unalias cp
    [root@oldboyedu ~]# alias 
    alias egrep='egrep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias grep='grep --color=auto'
    alias l.='ls -d .* --color=auto'
    alias ll='ls -l --color=auto'
    alias ls='ls --color=auto'
    alias mv='mv -i'
    alias rm='rm -i'
    alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
    
    [root@oldboyedu ~]# unalias cp
    [root@oldboyedu ~]# 
    [root@oldboyedu ~]# cp 2.txt /opt/
    [root@oldboyedu ~]# cp 2.txt /opt/
    [root@oldboyedu ~]# cp 2.txt /opt/
    

2.10、移动文件或目录(相当于剪切)

  • mv

    [root@oldboyedu ~]# ll
    total 0
    -rw-r--r--. 1 root root  0 Apr  5 09:10 2.txt
    -rw-r--r--. 1 root root  0 Apr  5 09:10 3.txt
    -rw-r--r--. 1 root root  0 Apr  5 09:10 4.txt
    -rw-r--r--. 1 root root  0 Apr  5 09:10 5.txt
    drwxr-xr-x. 2 root root  6 Apr  5 09:06 b
    drwxr-xr-x. 2 root root  6 Apr  5 09:06 c
    drwxr-xr-x. 2 root root  6 Apr  5 09:06 d
    lrwxrwxrwx. 1 root root 14 Apr  4 18:05 system-release -> centos-release
    [root@oldboyedu ~]# mv a /opt/
    mv: cannot stat ‘a’: No such file or directory
    [root@oldboyedu ~]# mv -r a /opt/
    mv: invalid option -- 'r'
    Try 'mv --help' for more information.
    [root@oldboyedu ~]# 
    [root@oldboyedu ~]# ll
    total 0
    -rw-r--r--. 1 root root  0 Apr  5 09:10 2.txt
    -rw-r--r--. 1 root root  0 Apr  5 09:10 3.txt
    -rw-r--r--. 1 root root  0 Apr  5 09:10 4.txt
    -rw-r--r--. 1 root root  0 Apr  5 09:10 5.txt
    drwxr-xr-x. 2 root root  6 Apr  5 09:06 b
    drwxr-xr-x. 2 root root  6 Apr  5 09:06 c
    drwxr-xr-x. 2 root root  6 Apr  5 09:06 d
    lrwxrwxrwx. 1 root root 14 Apr  4 18:05 system-release -> centos-release
    [root@oldboyedu ~]# mv b /opt/
    [root@oldboyedu ~]# ll /opt/
    total 0
    -rw-r--r--. 1 root root 0 Apr  5 09:25 1.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:30 2.txt
    drwxr-xr-x. 2 root root 6 Apr  5 09:14 a
    drwxr-xr-x. 2 root root 6 Apr  5 09:06 b
    [root@oldboyedu ~]# ll
    total 0
    -rw-r--r--. 1 root root  0 Apr  5 09:10 2.txt
    -rw-r--r--. 1 root root  0 Apr  5 09:10 3.txt
    -rw-r--r--. 1 root root  0 Apr  5 09:10 4.txt
    -rw-r--r--. 1 root root  0 Apr  5 09:10 5.txt
    drwxr-xr-x. 2 root root  6 Apr  5 09:06 c
    drwxr-xr-x. 2 root root  6 Apr  5 09:06 d
    lrwxrwxrwx. 1 root root 14 Apr  4 18:05 system-release -> centos-release
    [root@oldboyedu ~]# mv 2.txt /opt/
    mv: overwrite ‘/opt/2.txt’? y
    #mv:覆盖“opt/2.txt”?
    #原因是别名存在alias mv='mv -i'
    [root@oldboyedu ~]# ll /opt/
    total 0
    -rw-r--r--. 1 root root 0 Apr  5 09:25 1.txt
    -rw-r--r--. 1 root root 0 Apr  5 09:10 2.txt
    drwxr-xr-x. 2 root root 6 Apr  5 09:14 a
    drwxr-xr-x. 2 root root 6 Apr  5 09:06 b
    [root@oldboyedu ~]# ll
    total 0
    -rw-r--r--. 1 root root  0 Apr  5 09:10 3.txt
    -rw-r--r--. 1 root root  0 Apr  5 09:10 4.txt
    -rw-r--r--. 1 root root  0 Apr  5 09:10 5.txt
    drwxr-xr-x. 2 root root  6 Apr  5 09:06 c
    drwxr-xr-x. 2 root root  6 Apr  5 09:06 d
    lrwxrwxrwx. 1 root root 14 Apr  4 18:05 system-release -> centos-release
    
    
    • -i 确认

      alias mv='mv -i'
      

2.11、输出和打印

  • echo

    [root@oldboyedu ~]# echo "sun"
    sun
    
    
    • -n 不换行输出

      [root@oldboyedu ~]# echo -n "sunsun"
      sunsun[root@oldboyedu ~]# 
      
    • -e 支持转义字符

      • \n 换行

        [root@oldboyedu ~]# echo -e "sun\nsun"
        sun
        sun
        
      • \t tab

        [root@oldboyedu ~]# echo -e "sun\tsun"
        sun	sun
        
        

2.12、输出

  • printf

    [root@oldboyedu ~]# printf sun
    sun[root@oldboyedu ~]# printf sunsss
    sunsss[root@oldboyedu ~]# 
    

相关内容

    暂无相关文章