Linux文件及目錄管理命令基礎

来源:https://www.cnblogs.com/sunyuhang1/archive/2020/04/05/12636078.html
-Advertisement-
Play Games

1、命令基礎 1.1、命令操作語法 命令 [參數] [文件] 參數,可有可無 文件,可有可無 2、基礎命令 2.1、查看當前工作目錄 pwd print name of current/workin directory 列印 名字 或 工作 目錄 2.2、切換目錄 cd cd 目錄 相對路徑與絕對路 ...


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'
      

怎麼不使用別名:

  1. [root@oldboyedu ~]# \cp 1.txt /opt/
  2. [root@oldboyedu ~]# /bin/cp 1.txt /opt/

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 ~]# 
    

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1.RabbitMQ簡介 消息中間件也可以稱消息隊列,是指用高效可靠的消息傳遞機制進行與平臺無關的數據交流,並基於數據通信來進行分散式系統的集成。通過提供消息傳遞和消息隊列模型,可以在分散式環境下擴展進程的通信。 RabbitMQ是使用Erlang語言開發的開源消息隊列系統, 基於AMQP協議來實現 ...
  • 最近被shell里的各種括弧弄的有點暈了,又是小括弧又是中括弧,有時又有花括弧,小括弧和中括弧還有雙層寫法,用途各不一樣,我搞混了多次,對它們的用法有些迷糊了,於是我在這裡整理一下。如有錯誤,望諸君指正。 小括弧系列 [toc] () 用途:數組初始化 $() 用途:引用命令的運行結果 (()) 用 ...
  • 每日一句英語學習,每天進步一點點: 前言 不管面試 Java 、C/C++、Python 等開發崗位, TCP 的知識點可以說是的必問的了。 任 TCP 虐我千百遍,我仍待 TCP 如初戀。 遙想小林當年校招時常因 TCP 面試題被刷,真是又愛又狠…. 過去不會沒關係,今天就讓我們來消除這份恐懼,微 ...
  • 顯示目錄和文件的命令 Ls:用於查看所有文件夾的命令。 Dir:用於顯示指定文件夾和目錄的命令 Tree: 以樹狀圖列出目錄內容 Du:顯示目錄或文件大小 查找文件 locate a.txt :在系統全局範圍內查找文件名包含a.txt字樣的文件(比find快) find /home -mtime - ...
  • 本文主要是本人對 unix 操作系統中的數據緩衝區高速緩衝設計以及其演算法思路的一些理解,可能由於水平有限,文中難免會有錯誤,如若發現,懇請支持,謝謝! ...
  • SpringBoot系列(二)入門知識 往期推薦 "SpringBoot系列(一)idea新建springboot項目" 引言 本來新建springboot項目應該放在入門知識這一章的,但是由於新建springboot的第一篇文章只介紹了一種新建項目的方法,所以在這一章講解一下springboot的 ...
  • 因項目需要申請了新伺服器,故要重新配置環境。 nginx安裝: 一鍵安裝四個依賴: yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel 進入/usr/local/src目錄,創建nginx文件夾 cd /usr/lo ...
  • 良許在工作中,寫過一個 Shell 腳本,這個腳本可以從 4 個 NTP 伺服器輪流獲取時間,然後將最可靠的時間設置為系統時間。 因為我們對於時間的要求比較高,需要在短時間內就獲取到正確的時間。所以我們就需要對這個腳本運行時間進行測試,看看從開始運行到正確設置時間需要花費多少時間。 其實在工作中,還 ...
一周排行
    -Advertisement-
    Play Games
  • GoF之工廠模式 @目錄GoF之工廠模式每博一文案1. 簡單說明“23種設計模式”1.2 介紹工廠模式的三種形態1.3 簡單工廠模式(靜態工廠模式)1.3.1 簡單工廠模式的優缺點:1.4 工廠方法模式1.4.1 工廠方法模式的優缺點:1.5 抽象工廠模式1.6 抽象工廠模式的優缺點:2. 總結:3 ...
  • 新改進提供的Taurus Rpc 功能,可以簡化微服務間的調用,同時可以不用再手動輸出模塊名稱,或調用路徑,包括負載均衡,這一切,由框架實現並提供了。新的Taurus Rpc 功能,將使得服務間的調用,更加輕鬆、簡約、高效。 ...
  • 本章將和大家分享ES的數據同步方案和ES集群相關知識。廢話不多說,下麵我們直接進入主題。 一、ES數據同步 1、數據同步問題 Elasticsearch中的酒店數據來自於mysql資料庫,因此mysql數據發生改變時,Elasticsearch也必須跟著改變,這個就是Elasticsearch與my ...
  • 引言 在我們之前的文章中介紹過使用Bogus生成模擬測試數據,今天來講解一下功能更加強大自動生成測試數據的工具的庫"AutoFixture"。 什麼是AutoFixture? AutoFixture 是一個針對 .NET 的開源庫,旨在最大程度地減少單元測試中的“安排(Arrange)”階段,以提高 ...
  • 經過前面幾個部分學習,相信學過的同學已經能夠掌握 .NET Emit 這種中間語言,並能使得它來編寫一些應用,以提高程式的性能。隨著 IL 指令篇的結束,本系列也已經接近尾聲,在這接近結束的最後,會提供幾個可供直接使用的示例,以供大伙分析或使用在項目中。 ...
  • 當從不同來源導入Excel數據時,可能存在重覆的記錄。為了確保數據的準確性,通常需要刪除這些重覆的行。手動查找並刪除可能會非常耗費時間,而通過編程腳本則可以實現在短時間內處理大量數據。本文將提供一個使用C# 快速查找並刪除Excel重覆項的免費解決方案。 以下是實現步驟: 1. 首先安裝免費.NET ...
  • C++ 異常處理 C++ 異常處理機制允許程式在運行時處理錯誤或意外情況。它提供了捕獲和處理錯誤的一種結構化方式,使程式更加健壯和可靠。 異常處理的基本概念: 異常: 程式在運行時發生的錯誤或意外情況。 拋出異常: 使用 throw 關鍵字將異常傳遞給調用堆棧。 捕獲異常: 使用 try-catch ...
  • 優秀且經驗豐富的Java開發人員的特征之一是對API的廣泛瞭解,包括JDK和第三方庫。 我花了很多時間來學習API,尤其是在閱讀了Effective Java 3rd Edition之後 ,Joshua Bloch建議在Java 3rd Edition中使用現有的API進行開發,而不是為常見的東西編 ...
  • 框架 · 使用laravel框架,原因:tp的框架路由和orm沒有laravel好用 · 使用強制路由,方便介面多時,分多版本,分文件夾等操作 介面 · 介面開發註意欄位類型,欄位是int,查詢成功失敗都要返回int(對接java等強類型語言方便) · 查詢介面用GET、其他用POST 代碼 · 所 ...
  • 正文 下午找企業的人去鎮上做貸後。 車上聽同事跟那個司機對罵,火星子都快出來了。司機跟那同事更熟一些,連我在內一共就三個人,同事那一手指桑罵槐給我都聽愣了。司機也是老社會人了,馬上聽出來了,為那個無辜的企業經辦人辯護,實際上是為自己辯護。 “這個事情你不能怪企業。”“但他們總不能讓銀行的人全權負責, ...