您好,登錄后才能下訂單哦!
linux的目錄結(jié)構(gòu)是倒樹狀
1、二進(jìn)制程序目錄 (就是那些可執(zhí)行文件,可執(zhí)行程序,比如:ls mkdir touch...)
/bin /sbin 啟動(dòng)系統(tǒng)必要的程序(僅僅是啟動(dòng)系統(tǒng))
/usr/bin /usr/sbin 為了完成系統(tǒng)的特定功能(完成功能)
/usr/local/bin /usr/local/sbin 和系統(tǒng)功能無(wú)關(guān)的程序(第三方程序)
bin:binary (二進(jìn)制)全部用戶都可以執(zhí)行
sbin:system binary 系統(tǒng)二進(jìn)制,管理系統(tǒng)的命令
/bin/install 只有管理員用戶可以執(zhí)行的程序
2、配置文件目錄
存放各個(gè)程序的配置文件
/etc/sysconfig/network-scripts/ifcfg-eth0 網(wǎng)卡配置文件
/etc/sysconfig/network 主機(jī)名配置文件
/etc/passwd 用戶配置文件(系統(tǒng)中的全部用戶都保存在這個(gè)文件,每一行是一個(gè)用戶)
/etc/shadow 用戶密碼
需求,統(tǒng)計(jì)當(dāng)前系統(tǒng)共有多少用戶?
[root@7 home]# cat /etc/passwd |wc -l
22
3、用戶的家目錄
/root: 管理員用戶的家目錄
/home: 普通用戶的家目錄在home下和用戶名相同的那個(gè)目錄就是普通用戶的家目錄
/tmp : 臨時(shí)文件目錄 (這個(gè)目錄下的文件,如果在30天內(nèi)沒有被重復(fù)的訪問或修改過(guò),那么該文件被自動(dòng)刪除,所有用戶都可以在這個(gè)目錄下創(chuàng)建文件,每個(gè)用戶都可以在這個(gè)目錄下讀取自己或者別的用戶的文件,但是只能刪除自己的,不能刪除別人的)
普通用戶只能在自己的家目錄下創(chuàng)建文件
[zhangsan@7 ~]$ pwd
/home/zhangsan
[zhangsan@7 ~]$ touch a.txt
[zhangsan@7 ~]$ ls
a.txt
[zhangsan@7 tmp]$ rm -rf a.txt
[zhangsan@7 tmp]$ ls
注意:linux中的管理員root不受權(quán)限約束
4、存放內(nèi)容經(jīng)常變化的文件的目錄/var
/var/log/messages 記錄系統(tǒng)日志信息(經(jīng)常產(chǎn)生新信息)
/var/log/secure 記錄用戶登錄失敗的信息(登錄的用戶名,客戶的ip地址)
lastb:用來(lái)顯示登錄失敗的信息
如果發(fā)現(xiàn),在短時(shí)間內(nèi)有人頻繁用相同或者不同的用戶嘗試登錄系統(tǒng),說(shuō)明有人在暴力破解服務(wù)器,可以用防火墻封堵該IP
/var/log/lastlog 記錄系統(tǒng)中每個(gè)用戶上一次登錄時(shí)間和IP,以及登錄方式,用lastlog可以查看
/var/log/wtmp 顯示每個(gè)用戶的登錄狀態(tài)和最后的關(guān)機(jī)操作
命令:last
[root@7 home]# last
root pts/2 111.197.230.203 Sun Apr 14 21:55 still logged in
zhangsan pts/0 111.197.230.203 Sun Apr 14 21:46 still logged in
root pts/0 111.197.230.203 Sun Apr 14 21:46 - 21:46 (00:00)
root pts/1 111.197.230.203 Sun Apr 14 11:16 still logged in
root pts/0 111.197.230.203 Sun Apr 14 11:16 - 11:17 (00:00)
reboot system boot 3.10.0-957.5.1.e Sun Apr 14 18:37 - 22:27 (03:49)
useradd lisi
[root@7 home]# passwd lisi
tail /var/log/secure
pr 14 21:59:13 AliYun useradd[14157]: new group: name=lisi, GID=1001
Apr 14 21:59:13 AliYun useradd[14157]: new user: name=lisi, UID=1001, GID=1001, home=/home/lisi, shell=/bin/bash
Apr 14 21:59:20 AliYun passwd: pam_unix(passwd:chauthtok): password changed for lisi
5、共享文件目錄
注意:該目錄下的文件有特點(diǎn),只有讀權(quán)限
/usr
/usr/share/include
/usr/share/man/man5
/usr/share/fonts
6、啟動(dòng)系統(tǒng)相關(guān)文件目錄
/boot
boot分區(qū)不要太小 建議大于等于500M
7、設(shè)備文件目錄(設(shè)備文件不能直接使用,需要將文件掛在到一個(gè)目錄中才能使用,這個(gè)目錄就是掛載點(diǎn))
/dev
/dev/sda 第一個(gè)硬盤sda
/dev/sdb 第二個(gè)硬盤sdb
/dev/sr0 光盤
/dev/null 黑洞文件(任務(wù)文件和內(nèi)容放到null中就自動(dòng)消失)
/dev/zero 泡泡機(jī)
例子:將ls執(zhí)行的結(jié)果屏蔽掉
#ls >/dev/null
例子:將ls執(zhí)行結(jié)果的錯(cuò)誤信息屏蔽掉
#ls /tmpa/ /home/ 2>/dev/null
例子:將正確和錯(cuò)誤信息屏蔽掉
#ls /tmpa/ /home/ &>/dev/null
or
#ls /tmpa/ /home/ 2>1 1>/dev/null
8、庫(kù)文件目錄 (和軟件安裝相關(guān))
/lib
/lib64
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
9、掛載點(diǎn)目錄(設(shè)備文件需要掛載才能使用)
/mnt
/media
[root@localhost dev]# mount /dev/sr0 /mnt/
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@localhost dev]# ls /mnt/
CentOS_BuildTag isolinux RPM-GPG-KEY-CentOS-Debug-6
EFI Packages RPM-GPG-KEY-CentOS-Security-6
EULA RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Testing-6
GPL repodata TRANS.TBL
images RPM-GPG-KEY-CentOS-6
10、偽文件系統(tǒng)
/proc: 系統(tǒng)硬件和內(nèi)核信息的映射
/sys: 外圍設(shè)備的映射
注意: 此兩個(gè)目錄中的內(nèi)容是空的,開機(jī)的時(shí)候,系統(tǒng)會(huì)掃描硬件,將硬件信息保存到這兩個(gè)目錄下。在關(guān)機(jī)的時(shí)候,這些信息消失,因此這兩個(gè)文件下的信息就沒有了。
/proc/cpuinfo 記錄cpu信息
/proc/meninfo 記錄內(nèi)存信息
11、編譯軟件安裝目錄
/opt
linux中的文件類型
一般文件:-
目錄文件:-d
套接字文件: s
命令管道文件:p
設(shè)備文件:
字符設(shè)備 (線性設(shè)備):c(character)內(nèi)容必須是順序讀寫:例如:鍵盤
塊設(shè)備 :b (block)內(nèi)容是可以隨機(jī)讀寫:例如:硬盤
鏈接文件:
這里的鏈接文件其實(shí)指的是文件的快捷方式
[root@localhost tmp]# ln -s 1.txt nee1.txt
[root@localhost tmp]# ls -l nee1.txt
lrwxrwxrwx 1 root root 5 Apr 15 21:32 nee1.txt -> 1.txt
1、cd命令
全稱:change Directory
作用:修改所在的目錄
格式:cd /etc/sysconfig
pwd
特殊操作:
cd / :直接切換到根目錄下
cd ~ :返回到當(dāng)前用戶家目錄
cd ..:返回到當(dāng)前所在位置的上一級(jí)目錄
cd - :返回到上一次所在的目錄(返回切換目錄之前的那個(gè)目錄)
補(bǔ)充:
家目錄本質(zhì)上就是一個(gè)目錄而已,linux中每個(gè)用戶都有一個(gè)自己的專屬,
這個(gè)目錄就是用戶的家目錄,用戶可以在家目錄下執(zhí)行任意操作
用戶家目錄有兩種情況
例如:用戶zhangsan,家目錄/home/zhangsan目錄
例如:用戶zhangsan執(zhí)行命令cd ~,就切換到了/home/zhangsan
用戶sy執(zhí)行命令cd ~,就切換到了/home/sy
useradd zhangsan
passwd
cd ~
pwd
useradd lisi
passwd
cd ~
pwd
練習(xí):
1、切換到目錄/etc/sysconfig
[root@localhost ~]# cd /etc/sysconfig
[root@localhost sysconfig]# pwd
/etc/sysconfig
2、切換到/home 目錄下
[root@localhost ~]# cd /home/
[root@localhost home]# pwd
/home
3、切換到目錄/etc/sysconfig
[root@localhost ~]# cd /etc/sysconfig
[root@localhost sysconfig]# pwd
/etc/sysconfig
4、查看當(dāng)前所在位置
[root@localhost ~]# su zs
[zs@localhost root]$ cd /etc/
[zs@localhost etc]$ cd ~
[zs@localhost ~]$ pwd
/home/zs
5、返回到系統(tǒng)的根目錄
[zs@localhost /]$ su root
Password:
[root@localhost /]# cd /
[root@localhost /]# pwd
/
2、pwd命令
全稱:Print Working Directory
作用:打印所在目錄(工作目錄)
linux中全部的文件都在根目錄存放
/:就表示linux的根目錄(目錄名是/)
linux 是單根系統(tǒng)
windows 是多根系統(tǒng)
3、mkdir命令
全稱:make Directory
作用:創(chuàng)建目錄
格式:mkdir [OPTION]... DIRECTORY...
例子:創(chuàng)建三個(gè)目錄bajie wukong guodegang
[root@localhost ~]# mkdir bajie wukong guodegang
[root@localhost ~]# ls
bajie guodegang test1 wukong
例子:創(chuàng)建三個(gè)目錄/yunwei/linux/python
[root@localhost ~]# mkdir yunwei/linux/python
mkdir: cannot create directory `yunwei/linux/python': No such file or directory
報(bào)錯(cuò)、沒有父目錄
選項(xiàng):
-p:創(chuàng)建目錄的時(shí)候先創(chuàng)建父目錄,再創(chuàng)建子目錄。
-v:顯示創(chuàng)建目錄的過(guò)程信息
[root@localhost ~]# mkdir -p yunwei/linux/python
[root@localhost ~]# ls
bajie guodegang test1 wukong yunwei
例子:創(chuàng)建目錄/a1/a2/a3并顯示創(chuàng)建目錄的過(guò)程信息
[root@localhost ~]# mkdir -pv a1/a2/a3
mkdir: created directory `a1'
mkdir: created directory `a1/a2'
mkdir: created directory `a1/a2/a3'
[root@localhost ~]# ls
a1 bajie guodegang test1 wukong yunwei
例子:在home下創(chuàng)建yw1
#mkdir -p/home/yw1
例子:在根目錄下創(chuàng)建目錄yw1
#mkdir /yw1
例子:在當(dāng)前用戶的家目錄下創(chuàng)建目錄yw1
#mkdir /root/yw1
#mkdir ~/yw1
例子:在當(dāng)前位置下創(chuàng)建目錄yw1
#mkdir yw1
#mkdir ./yw1
例子:在上一級(jí)目錄下創(chuàng)建目錄yw1
#cd ..
#mkdir yw1
或者
#mkdir ../yw1
補(bǔ)充:表示路徑的時(shí)候
? ./: 表示當(dāng)前位置(如果不指定路徑也是表示當(dāng)前位置)
? ../: 表示上一級(jí)目錄
? mkdir abc >>> 在當(dāng)前位置下創(chuàng)建目錄abc
mddir ./abc >>>在當(dāng)前位置下創(chuàng)建目錄abc
echo "mkdir abc" 輸出mkdir abc
[root@localhost tmp]# echo "mkdir abc"
mkdir abc
[root@localhost tmp]# ls
yw1
4、touch命令
作用:創(chuàng)建空白文件
例子:創(chuàng)建三個(gè)文件 a.txt b.doc c.ppt
touch a.txt b.doc d.ppt
[root@localhost ~]# ls
a.txt b.doc d.ppt
例子:根創(chuàng)建文件1.txt
touch /1.txt
例子:在根下創(chuàng)建三個(gè)文件1.txt 2.txt 3.txt
[root@localhost ~]# touch /1.txt /2.txt /3.txt
[root@localhost ~]# cd /
[root@localhost /]# ls
1.txt 2.txt bin cgroup etc lib lost+found misc net proc sbin srv tmp var
1.xtx 3.txt boot dev home lib64 media mnt opt root selinux sys usr
補(bǔ)充:花括號(hào)展開
需求:三個(gè)目錄a b c ,在三個(gè)目錄中分別創(chuàng)建文件1.txt 2.txt 3.txt
#mkdir a b c
#touch a/1.txt a/2.txt a/3.txt
#touch b/1.txt a/2.txt a/3.txt
#touch c/1.txt a/2.txt a/3.txt
或者
#mkdir a b c
#touch {a,b,c}/{1.txt,2.txt,3.txt}
或者
#mkdir a b c
#touch {a,b,c}/{1,2,3}.txt
#touch file.{doc,ppt,txt} = touch file.doc file.ppt file.txt
#touch {1,2,3}.txt = touch 1.txt 2.txt 3.txt
例子:創(chuàng)建三個(gè)目錄 a b c,在每個(gè)目錄下創(chuàng)建文件a.txt
#mkdir a b c
#touch a/a.txt b/a.txt c/a.txt
或者
touch {a,b,c}/a.txt
需求:創(chuàng)建一個(gè)文件,文件名是 年-月-日-小時(shí):分鐘:秒.log
[root@localhost ~]# touch `date +%F-%H:%M:%S`.log
[root@localhost ~]# touch `date +%F-%H:%M:%S`.log
[root@localhost ~]# ls
2019-04-12-04-21:55.log 2019-04-12-04:22:35.log
2019-04-12-04:22:33.log 2019-04-12-04:22:36.log
需求:創(chuàng)建一個(gè)文件,文件名是 主機(jī)名-小時(shí):分鐘:秒
[root@localhost ~]# hostname
zs
[root@localhost ~]# touch `hostname`-`date +%H:%M:%S`.log
[root@localhost ~]# ls
zs-04:34:52.log
補(bǔ)充:linux 中的變量和輸出
echo
補(bǔ)充:linux中的引號(hào)
單引號(hào):'' 弱引用,會(huì)將變量中的內(nèi)容原樣輸出
[root@localhost ~]# name="I love python"
[root@localhost ~]# echo '$name'
$name
雙引號(hào):"" 強(qiáng)引用,是將變量名替換成變量值
[root@localhost ~]# name="I love linux"
[root@localhost ~]# echo "$name"
I love linux
反引號(hào):命令替換成命令的執(zhí)行結(jié)果
5、history命令
作用:查看和使用歷史命令(最多紀(jì)錄1000條)
保存位置:~/.bash_history
1、在啟動(dòng)終端的時(shí)候,會(huì)自動(dòng)從~/.bash_history中讀取歷史命令,加載到內(nèi)存中
2、在終端中執(zhí)行命令,命令的歷史記錄是保存在內(nèi)存中
3、在關(guān)閉終端的時(shí)候,會(huì)將內(nèi)存中的歷史命令自動(dòng)保存到~/bash_history中
history的快捷操作
!num:執(zhí)行歷史命令中編號(hào)為num的歷史命令
!string:在歷史命令中找以指定字符串為開頭的命令執(zhí)行一次,從下向上進(jìn)行查找
?。。簣?zhí)行的是上一個(gè)命令
!-num:執(zhí)行歷史命令中倒數(shù)第num條命令
如果保留了歷史命令,******了我們的系統(tǒng),通過(guò)歷史命令,知道服務(wù)器進(jìn)行了哪些操作。有些時(shí)候需要對(duì)歷史命令進(jìn)行控制。
-c:清空歷史命令 (內(nèi)存中的)
在啟動(dòng)終端的時(shí)候,會(huì)從~/.bash_history讀取歷史命令
[root@localhost ~]# history -c
[root@localhost ~]#
[root@localhost ~]# history
1 history
-a:手動(dòng)將內(nèi)存中的歷史命令保存到文件中
-r:重新從~/.bash_history中讀取歷史命令
-d: num:刪除指定編號(hào)的歷史命令(***別人系統(tǒng)的時(shí)候,抹掉自己的操作命令)
6、ls命令
作用:顯示當(dāng)前或者指定目錄下的文件
選項(xiàng)
-a:顯示目錄下的全部文件(包括隱藏文件)
-l:顯示文件和目錄的詳細(xì)屬性
-d:顯示目錄自身(如果不使用-d則是顯示目錄中的文件)
-h:結(jié)合-l使用,以易讀的方式顯示目錄的大小,(只顯示
文件的大小,不顯示目錄的大?。? -t: 按照文件的修改時(shí)間排序,將最后修改的文件排在前邊
-r:結(jié)合-l -t使用,倒序排序
例子:顯示跟下有哪些文件
[root@localhost ~]# ls /
1.txt 2.txt bin cgroup etc lib lost+found misc net proc sbin srv tmp var
1.xtx 3.txt boot dev home lib64 media mnt opt root selinux sys usr
黑白顏色是一般文件,藍(lán)顏色的是目錄
例子:顯示當(dāng)前目錄下有哪些文件
#ls ./
#ls
(當(dāng)前位置是./,但是可以省略)
例子:創(chuàng)建文件并查看文件的詳細(xì)信息
[root@localhost tmp]# mkdir book
[root@localhost tmp]# touch book/{linux,python,go}
[root@localhost tmp]# ls book/
go linux python
[root@localhost tmp]# ls -l book/
total 0
-rw-r--r-- 1 root root 0 Apr 12 18:03 go
-rw-r--r-- 1 root root 0 Apr 12 18:03 linux
-rw-r--r-- 1 root root 0 Apr 12 18:03 python
例子:顯示a.txt的詳細(xì)屬性
#ls -l a.txt
例子:顯示book目錄的詳細(xì)屬性
[root@localhost tmp]# ls -ld book
drwxr-xr-x 2 root root 4096 Apr 12 18:03 book
[root@localhost tmp]# cd book/
[root@localhost book]# ls
go linux python
[root@localhost book]# vi go
[root@localhost book]# vi linux
[root@localhost book]# vi python
[root@localhost book]# ls -l
total 12
-rw-r--r-- 1 root root 164 Apr 12 18:11 go
-rw-r--r-- 1 root root 83 Apr 12 18:13 linux
-rw-r--r-- 1 root root 165 Apr 12 18:13 python
ls -lh
total 45M
-rw-r--r-- 1 root root 164 Apr 12 18:11 go
-rw-r--r-- 1 root root 45M Apr 12 19:01 linux
-rw-r--r-- 1 root root 98K Apr 12 18:48 python
-h只顯示文件的大小,不顯示目錄的大小
例:
[root@localhost book]# cd ..
[root@localhost tmp]# ls -l -h
total 4.0K
drwxr-xr-x 2 root root 4.0K Apr 12 19:04 book
顯示目錄的大小用du命令,此處不過(guò)多解釋。講解磁盤的時(shí)候會(huì)詳情講解。
-t將最后修改的文件排在前面
[root@localhost tmp]# cd book/
[root@localhost book]# ls
go linux python
[root@localhost book]# ls -l
total 45676
-rw-r--r-- 1 root root 164 Apr 12 18:11 go
-rw-r--r-- 1 root root 46661650 Apr 12 19:01 linux
-rw-r--r-- 1 root root 99824 Apr 12 18:48 python
[root@localhost book]# vi linux
[root@localhost book]# ls -l -t
total 45676
-rw-r--r-- 1 root root 46661656 Apr 12 22:27 linux
-rw-r--r-- 1 root root 99824 Apr 12 18:48 python
-rw-r--r-- 1 root root 164 Apr 12 18:11 go
[root@localhost book]# vi go
[root@localhost book]# ls -l -t
total 45676
-rw-r--r-- 1 root root 167 Apr 12 22:27 go
-rw-r--r-- 1 root root 46661656 Apr 12 22:27 linux
-rw-r--r-- 1 root root 99824 Apr 12 18:48 python
絕對(duì)路徑和相對(duì)路徑
絕對(duì)路徑:就是從根目錄下開始查找
相對(duì)路徑:相對(duì)當(dāng)前位置的路徑
在home目錄下的a中創(chuàng)建一個(gè)文件a.txt
[root@localhost home]# mkdir a
[root@localhost home]# touch /home/a/a.txt 絕對(duì)路徑
[root@localhost home]# touch ./a/a.txt 相對(duì)路徑(前提必須在home之下)
[root@localhost home]# touch a/a.txt 相對(duì)路徑(前提必須在home之下)
touch ./a/a.txt(前提必須在home之下)
touch a/a.txt (前提必須在home之下)
例子:切換到/etc/init.d目錄下
要求1:在init.d下新建目錄abc
要求2:在/etc下新建目錄abc
1:方法1:相對(duì)路徑
[root@localhost home]# cd /etc/init.d
[root@localhost init.d]# mkdir abc
[root@localhost init.d]# ls
abc autofs cups kdump netconsole ntpdate rdisc
[root@localhost ~]# mkdir /etc/init.d/abc
[root@localhost ~]# .ls /etc/init.d/
abc autofs cups kdump netconsole ntpdate rdisc rpcsvcgssd sssd
絕對(duì)路徑:mkdir /etc/abc
相對(duì)路徑:mkdir ../abc
7、cat命令
全稱:concatenate(連接并顯示:拼接多個(gè)文件)
作用:顯示一個(gè)文本文件中的內(nèi)容
格式:cat [選項(xiàng)] 文件
選項(xiàng):
-n:在每行的前面顯示行號(hào)
361 cat /etc/init.d/halt
362 cat -n /etc/init.d/halt
-E:顯示出來(lái)行結(jié)束符
補(bǔ)充:windows中的文件的換行符:\n
linux中的文件的換行符:$
(這樣的符號(hào)都是隱性符號(hào)-都是默認(rèn)不可見的)
8、tac命令
作用:將一個(gè)文件中的內(nèi)容倒序顯示出來(lái)
最后一行變成第一行)
[root@localhost tmp]# vi 1.txt
11111
2222
3333
444
555
[root@localhost tmp]# tac 1.txt
555
444
3333
2222
11111
9、head
作用:顯示一個(gè)文件的前若干行(默認(rèn)是10行)
格式:
head -n file
選項(xiàng):
-n NUM:指定顯示前NUM行
例子:顯示文件1.txt的前10行
# head 1.txt
例子:顯示文件1.txt的前3行
# head -n 3 1.txt
10、tail
作用:顯示一個(gè)文件的末尾若干行(默認(rèn)是10行)
格式:tail 選項(xiàng)file
選項(xiàng):
-n: 指定顯示末尾n行
-f:動(dòng)態(tài)監(jiān)控一個(gè)文件中的內(nèi)容變化
例子:顯示文件1.txt的末尾10行
#tail 1.txt
例子: 顯示文件1.txt的末尾3行
#tail -n 3 1.txt
監(jiān)控1.txt中的內(nèi)容變化情況
[root@localhost tmp]# tail -f 1.txt
退出監(jiān)控ctrl+c
只要文件1.txt中的內(nèi)容發(fā)生改變,會(huì)立刻顯示在終端之上。
11、more
作用:顯示一個(gè)文件中的內(nèi)容(分屏顯示)
12、less
作用:顯示一個(gè)文件中的內(nèi)容(分屏顯示)
操作
回車:顯示下一行
空格:顯示下一屏幕
b:向上翻一屏
q:退出more或者less
補(bǔ)充:more和less的區(qū)別只有一個(gè)
more當(dāng)?shù)竭_(dá)文件末尾的時(shí)候,會(huì)自動(dòng)退出
less是不會(huì)自動(dòng)退出的
補(bǔ)充: cat 、tac: 顯示比較內(nèi)容較少的文件
head、tail: 顯示文件的一部分
more、less: 顯示一個(gè)內(nèi)容很大文件的全部
在文件中檢索內(nèi)容
13、rm命令
全稱:remove(移除)
作用:刪除文件或者目錄
格式:rm 選項(xiàng) 文件1 文件2
例子:刪除文件1.txt 2.txt 3.txt
root@7.4 ~# touch 1.txt 2.txt 3.txt
root@7.4 ~# ls
1.txt 2.txt 3.txt Readme y.sh
選項(xiàng):
-f --force 強(qiáng)制刪除
-r 刪除目錄
rm -f 1.txt 2.txt 3.txt
root@7.4 ~# mkdir book1 book2 book3
root@7.4 ~# rm -f book1 book2 book3
rm: cannot remove ‘book1’: Is a directory
rm: cannot remove ‘book2’: Is a directory
rm: cannot remove ‘book3’: Is a directory
root@7.4 ~# ls
book1 book2 book3 Readme y.sh
root@7.4 ~# rm -f -r book1 book2 book3
root@7.4 ~# ls
Readme y.sh
或者 rm -rf book1 book2 book3
通配符介紹
*:表示任意長(zhǎng)度的任意字符(可以表示任何東西)
*abc 表示文件名的后三位是abc的情況,順序要嚴(yán)格匹配
例子:刪除文件名的結(jié)尾是.txt的文件
root@7.4 ~# touch 2.txt 3.txt a.txt a.conf b.conf
root@7.4 ~# ls
2.txt 3.txt a.conf a.txt b.conf Readme y.sh
root@7.4 ~# rm -rf *.txt
root@7.4 ~# ls
例子:刪除文件名開頭是a的文件
root@7.4 ~# ls
a.conf b.conf Readme y.sh
root@7.4 ~# rm -rf a*
root@7.4 ~# ls
b.conf Readme y.sh
例子:刪除文件名中包含a的文件
root@7.4 test# touch a.txt abad.txt b.txt bag.xt 3.txt dk vb
root@7.4 test# ls
3.txt abad.txt a.txt bag.xt b.txt dk vb
root@7.4 test# rm -rf *a*
root@7.4 test# ls
3.txt b.txt dk vb
例子:刪除當(dāng)前目錄下的全部文件
rm -rf ./*
或者
rm -rf *
例子:刪除homo下全部以a為開頭,字母b為結(jié)尾的文件
rm -rf /home/a*b
例子:刪除home下全部以a為開頭,字母b為結(jié)尾的文件,文件名中包含c的文件
rm -rf /home/a*c*b
注意:刪除之前一定要確定要?jiǎng)h除的文件 ,切記:自己創(chuàng)建的
可以刪除,系統(tǒng)自帶的不要?jiǎng)h除,確認(rèn)系統(tǒng)是不是有快照。
rm -rf / * 刪除系統(tǒng)中所有的文件
刪除后,系統(tǒng)不能啟動(dòng),有些文件刪除不掉,是偽文件。
系統(tǒng)啟動(dòng)時(shí)按esc可以看系統(tǒng)啟動(dòng)過(guò)程中的詳細(xì)信息
14、mv
全稱:move
作用:移動(dòng)文件和目錄
例子:將tmp下的1.txt移動(dòng)到home下
# mv /tmp/1.txt /home
例子:將tmp下的2.txt移動(dòng)到home下,并改名為new2.txt
# mv /tmp/2.txt /home/new2.txt
工作中不建議使用mv命令,從一個(gè)磁盤復(fù)制到另一個(gè)磁盤
復(fù)制過(guò)程中斷電數(shù)據(jù)丟失,文件會(huì)崩潰先把文件復(fù)制過(guò)去,
確定數(shù)據(jù)完整性后,刪除源文件。
例子:將tmp下3.txt移動(dòng)到tmp下并改名new3.txt
# mv/tmp/3.txt /tmp.new3.txt
mv/tmp/3.txt /tmp/new3.txt
#mv /tmp/book2 /home/newbook2 (對(duì)于目錄的移動(dòng))
此命令是將命令book2移動(dòng)到home下
如果home下沒有目錄book2,此時(shí)會(huì)將book2復(fù)制到home下并改名newbook2
如果home下已經(jīng)有newbook2,那此時(shí)將book2移動(dòng)到newbook2的下面
[root@7 tmp]# mv /tmp/book2 /home/newbook2
[root@7 tmp]# ls /home
newbook2
[root@7 tmp]# mkdir book2
[root@7 tmp]# mv /tmp/book2 /home/newbook2
[root@7 tmp]# ls /home
newbook2
[root@7 tmp]# ls /home/newbook2/
book2
mv /tmp/1.txt /home/new1.txt
(移動(dòng)命令)
此命令是將1.txt移動(dòng)到home下
如果home下有new1.txt,此時(shí)會(huì)提示覆蓋
如果home下沒有new1.txt,會(huì)將1.txt復(fù)制到home下并改名為new1.txt
15、cp命令
作用:復(fù)制文件和目錄
格式:cp 選項(xiàng) 原始文件 目標(biāo)文件
選項(xiàng):-a: 復(fù)制過(guò)程中保留文件的屬性不變
如果復(fù)制的目的是備份系統(tǒng)文件,通常要使用-a來(lái)保留文件的屬性不變
直接備份會(huì)導(dǎo)致文件的屬性改變直接備份會(huì)導(dǎo)致文件的屬性改變
-f: 復(fù)制過(guò)程中如果需要覆蓋,則強(qiáng)制執(zhí)行(不詢問)
-i: 在執(zhí)行覆蓋操作前詢問用戶,如果使用該選項(xiàng),則-f無(wú)效
-r: 復(fù)制目錄(復(fù)制目錄必須用上此選項(xiàng))
先復(fù)制目錄到目標(biāo)位置,然后將目錄中的全部?jī)?nèi)容復(fù)制過(guò)去
[root@7 home]# cp -r -v /tmp/book3 /home/
‘/tmp/book3’ -> ‘/home/book3’
-v: 顯示復(fù)制過(guò)程信息(分析命令怎么執(zhí)行)
注意:系統(tǒng)默認(rèn)為cp命令設(shè)置了別名,別名中已經(jīng)使用了選項(xiàng)-i
例子:將tmp下的1.txt復(fù)制home下
[root@7 tmp]# cp 1.txt /home/
[root@7 tmp]# ls /home
1.txt
注意:如果再次復(fù)制,會(huì)提示覆蓋,如果想自動(dòng)強(qiáng)制覆蓋需要使用
cp的原意
# \cp /tmp/1.txt /home
例子:將tmp下的2.txt復(fù)制到home并改名為new2.txt
[root@7 tmp]# cp /tmp/2.txt /home/new2.txt
[root@7 tmp]# ls /home
1.txt new2.txt
例子:將目錄book2復(fù)制到home下并改名為newbook2
[root@7 tmp]# cp -r /tmp/book1 /home/
[root@7 tmp]# ls /home/
1.txt book1 new2.txt
例子:將目錄book1復(fù)制到home下并改名為newbook1
cp -r /tmp/book1 /home/newbook1
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。