檔案目錄管理命令
-----------------------------------------------------------------------------------------
touch命令用于創建空白檔案或設定檔案的時間,語法格式為:“touch [引數] 檔案名稱
[root@localhost mnt]# ls
[root@localhost mnt]# touch bing
[root@localhost mnt]# ls
bing
# vim linux 使用vim編輯一個不存在的檔案,修改保存后,該會自動建立
[root@localhost mnt]# vim linux
[root@localhost mnt]# ls
bing linux
--------------------------------------------------------------------------------------------------------------
mkdir命令用于創建空白的目錄,英文全稱為:“make directory”,語法格式為:“mkdir [引數] 目錄名稱”
[root@localhost mnt]# mkdir linux-b
[root@localhost mnt]# ls
bing linux linux-b
mkdir -p /mnt/linux-c/bing/geely/7dct 創建遞增層次的檔案
[root@localhost mnt]# mkdir -p /mnt/linux-c/bing/geely/7dct
[root@localhost mnt]# ls
bing linux linux-b linux-c
[root@localhost mnt]# cd /mnt/linux-c/bing/geely/7dct
[root@localhost 7dct]# pwd
/mnt/linux-c/bing/geely/7dct
--------------------------------------------------------------------------------
cp命令用于復制檔案或目錄,英文全稱為:“copy”,語法格式為:“cp [引數] 源檔案名稱 目標檔案名稱”
語法: cp 源… 目的
復制目錄時,多個-r 選項:
# cp -r newdir/ /tmp/ 目標目錄存在,則將源目錄放在該目錄下
# cp -r newdir /tmp/olddir 目標目錄不存在,類似復制過去后重命名
# cp -r /run/media/admin/RHEL-7.0Server.x86_64/. /mnt/redhat7/ 復制/run/media/admin/RHEL-7.0Server.x86_64/下所有檔案到/mnt/redhat7/下
[root@localhost mnt]# ls
bing linux linux-b linux-c
[root@localhost mnt]# cp bing bing1
[root@localhost mnt]# ls
bing bing1 linux linux-b linux-c
[root@localhost mnt]# cp -r linux-b /mnt/linux-c
[root@localhost mnt]# cd linux-c
[root@localhost linux-c]# ls
bing linux-b
--------------------------------------------------------------------------------
mv命令用于剪切或重命名檔案,英文全稱為:“move”,語法格式為:“mv [引數] 源檔案名稱 目標檔案名稱”
[root@localhost mnt]# ls
bing bing1 linux linux-b linux-c
[root@localhost mnt]# mv bing1 bing2
[root@localhost mnt]# ls
bing bing2 linux linux-b linux-c
[root@localhost mnt]# mv bing2 /mnt/linux-b
[root@localhost mnt]# cd linux-b
[root@localhost linux-b]# ls
bing2
--------------------------------------------------------------------------------
rm命令用于洗掉檔案或目錄,英文全稱為:“remove”,語法格式為:“rm [引數] 檔案名稱”
rm -f 強制洗掉檔案
rm -rf 強制洗掉目錄檔案
[root@localhost mnt]# rm linux
rm: remove regular file 'linux'? y
[root@localhost mnt]# ls
bing linux-b linux-c
[root@localhost mnt]# rm -f bing
[root@localhost mnt]# ls
linux-b linux-c
[root@localhost mnt]# rm -rf linux-b
[root@localhost mnt]# ls
linux-c
--------------------------------------------------------------------------------
dd命令用于按照指定大小的資料塊個數來復制檔案或轉換檔案
if input file 輸入檔案
of output file 輸出檔案
bs 設定每個“塊”的大小
count 設定要復制“塊”的個數
語法格式為:“dd if=引數值 of=引數值 count=引數值 bs=引數值”
--------------------------------------------------------------------------------
file命令用于查看檔案的型別,語法格式為:“file 檔案名稱”
[root@localhost mnt]# file linux-c/
linux-c/: directory
--------------------------------------------------------------------------------
(考試命令tar)
tar命令用于對檔案進行打包壓碩訓解壓,語法格式為:“tar 引數 檔案名稱
[root@localhost mnt]# tar czvf etc.tar.gz /etc
[root@localhost mnt]# ls
etc.tar.gz linux-c
z ---tar.gz
j ---tar.bz2
tar czvf 壓縮包.tar.gz
tar xjvf 壓縮包.tar.bz2
引數 作用
-c 創建壓縮檔案
-x 解開壓縮檔案
-t 查看壓縮包內有哪些檔案
-z 用Gzip壓碩訓解壓
-j 用bzip2壓碩訓解壓
-v 顯示壓碩訓解壓的程序
-f 目標檔案名
-p 保留原始的權限與屬性
-P 使用絕對路徑來壓縮
-C 指定解壓到的目錄
--------------------------------------------------------------------------------
grep命令用于在文本中執行關鍵詞搜索,并顯示匹配的結果,格式為“grep [選項] [檔案]”
[root@localhost mnt]# grep /sbin/nologin /etc/passwd
bin:x:1:1:bin:/bin:/sbin/nologin
........
[root@localhost mnt]# grep -c /sbin/nologin /etc/passwd
48
引數 作用
-b 將可執行檔案(binary)當作文本檔案(text)來搜索
-c 僅顯示找到的行數
-i 忽略大小寫
-n 顯示行號
-v 反向選擇——僅列出沒有“關鍵詞”的行,
--------------------------------------------------------------------------------
find命令用于按照指定條件來查找檔案,格式為“find [查找路徑] 尋找條件 操作”
[root@localhost mnt]# find /etc -name "host*" -print
/etc/opa/hosts
/etc/host.conf
/etc/hosts
/etc/hosts.allow
/etc/hosts.deny
/etc/avahi/hosts
/etc/hostname
---------------------------------------------------
重定向符(<、<<、>、>>) 命令與檔案的關系
管道符 ( | ) 命令與命令的關系
輸入重定向(檔案到命令)
命令 < 檔案 將檔案作為命令的標準輸入
命令 << 分界符 從標準輸入中讀入,直到遇見分界符才停止
-------------------------------
輸出重定向(命令到檔案)
符號 作用
命令 > 檔案 將標準輸出重定向到一個檔案中(清空寫入 )
命令 2> 檔案 將錯誤輸出重定向到一個檔案中(追加寫入)
命令 >> 檔案 將標準輸出重定向到一個檔案中(清空寫入 )
命令 2>> 檔案 將錯誤輸出重定向到一個檔案中(追加寫入)
命令 &> 檔案 將標準輸出與錯誤輸出共同寫入到檔案中(清空寫入 )
命令 &>> 檔案 將標準輸出與錯誤輸出共同寫入到檔案中(追加寫入 )
[root@localhost mnt]# ls -l > test
[root@localhost mnt]# cat test
total 6548
-rw-r--r--. 1 root root 6701472 Apr 10 12:49 etc.tar.gz
drwxr-xr-x. 4 root root 33 Apr 10 12:31 linux-c
-rw-r--r--. 1 root root 0 Apr 10 13:12 test
[root@localhost mnt]# ls -l bing > test
ls: cannot access 'bing': No such file or directory
[root@localhost mnt]# ls -l bing 2> test
[root@localhost mnt]# cat test
ls: cannot access 'bing': No such file or directory
[root@localhost mnt]# ls -l 2> test
total 6548
-rw-r--r--. 1 root root 6701472 Apr 10 12:49 etc.tar.gz
drwxr-xr-x. 4 root root 33 Apr 10 12:31 linux-c
-rw-r--r--. 1 root root 0 Apr 10 13:14 test
[root@localhost mnt]# cat test
[root@localhost mnt]#
[root@localhost mnt]# ls -l &>> test
[root@localhost mnt]# ls -l geely &>> test
[root@localhost mnt]# cat test
ls: cannot access 'geely': No such file or directory
total 6552
-rw-r--r--. 1 root root 6701472 Apr 10 12:49 etc.tar.gz
drwxr-xr-x. 4 root root 33 Apr 10 12:31 linux-c
-rw-r--r--. 1 root root 53 Apr 10 13:18 test
ls: cannot access 'geely': No such file or directory
------------------------------------------------------------
管道符
grep /sbin/nologin /etc/passwd | wc -l
grep搜索命令的輸出值傳遞給wc統計命令,即把原本要輸出到螢屏的用戶資訊串列再交給wc命令作進一步的加工
[root@localhost mnt]# grep -c /sbin/nologin /etc/passwd
48
[root@localhost mnt]# grep /sbin/nologin /etc/passwd | wc -l
48
把管道符和passwd命令的--stdin引數相結合,可以用一條命令來完成密碼重置操作
echo "root" | passwd --stdin root
[root@localhost mnt]# echo "root" | passwd --stdin root
Changing password for user root.
passwd: all authentication tokens updated successfully.
----------------------------------------------------------------
命令列的通配符
[root@localhost ~]# ls -l /dev/sda
brw-rw----. 1 root disk 8, 0 Apr 10 12:24 /dev/sda
[root@localhost ~]# ls -l /dev/sda1
brw-rw----. 1 root disk 8, 1 Apr 10 12:24 /dev/sda1
[root@localhost ~]# ls -l /dev/sda2
brw-rw----. 1 root disk 8, 2 Apr 10 12:24 /dev/sda2
[root@localhost ~]# ls -l /dev/sda3
ls: cannot access '/dev/sda3': No such file or directory
[root@localhost ~]#
[root@localhost ~]# ls -l /dev/sd*
brw-rw----. 1 root disk 8, 0 Apr 10 12:24 /dev/sda
brw-rw----. 1 root disk 8, 1 Apr 10 12:24 /dev/sda1
brw-rw----. 1 root disk 8, 2 Apr 10 12:24 /dev/sda2
[root@linuxprobe ~]# ls -l /dev/sda?
brw-rw----. 1 root disk 8, 1 May 4 15:55 /dev/sda1
brw-rw----. 1 root disk 8, 2 May 4 15:55 /dev/sda2
[root@localhost ~]# ls -l /dev/sd?
brw-rw----. 1 root disk 8, 0 Apr 10 12:24 /dev/sda
[root@localhost ~]# ls -l /dev/sd??
brw-rw----. 1 root disk 8, 1 Apr 10 12:24 /dev/sda1
brw-rw----. 1 root disk 8, 2 Apr 10 12:24 /dev/sda2
通配符 含義
* 任意字符
? 單個任意字符
[a-z] 單個小寫字母
[A-Z] 單個大寫字母
[a-Z] 單個字母
[0-9] 單個數字
[:alpha:] 任意字母
[:upper:] 任意大寫字母
[:lower:] 任意小寫字母
[:digit:] 所有數字
[:alnum:] 任意字母加數字
[:punct:] 標點符號
----------------------------------------------------------------------
轉義字符
單個轉義--反斜杠(\):使反斜杠后面的一個變數變為單純的字符,
全部轉義--單引號(''):轉義其中所有的變數為單純的字串,
有空格加--雙引號(""):保留其中的變數屬性,不進行轉義處理,
執行命令--反引號(``):把其中的命令執行后回傳結果,
[root@localhost ~]# PRICE=5
[root@localhost ~]# echo "Price is $PRICE"
Price is 5
[root@localhost ~]# echo "Price is \$$PRICE"
Price is $5
[root@localhost ~]# echo `uname -a`
Linux localhost.localdomain 4.18.0-80.el8.x86_64 #1 SMP Wed Mar 13 12:02:46 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]#
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/274651.html
標籤:其他
上一篇:Linux學習筆記(第三課)
