基本知識(shí)——文件的路徑
- 絕對(duì)路徑:第一個(gè)以/開頭讲岁,自根目錄開始。如/var/log
- 相對(duì)路徑:以其他字符開頭,指定從工作目錄到達(dá)該文件的路徑吗冤。如log/messages
文件目錄導(dǎo)航
pwd # pwd命令顯示當(dāng)前位置的完整路徑名
ls Downloads # ls命令列出指定目錄的內(nèi)容,可以使用絕對(duì)路徑或相對(duì)路徑九府。不指定目錄時(shí)列出當(dāng)前目錄的內(nèi)容
ls -l # ls選項(xiàng)的常用選項(xiàng):-l(長列表格式)椎瘟,-a(包含隱藏文件),-R(遞歸方式侄旬,包含子目錄)
cd Videos #cd命令更改目錄
cd - # 將目錄更改到進(jìn)入當(dāng)前目錄之前所處的目錄
cd .. # 進(jìn)入父目錄(無需知道父目錄名稱)
cd ~ # 進(jìn)入主目錄
touch a.txt #touch命令可將文件的時(shí)間戳更新為當(dāng)前的日期和時(shí)間肺蔚,不作其他修改±芨幔可用于創(chuàng)建空文件宣羊。
文件管理——?jiǎng)?chuàng)建璧诵、復(fù)制、移動(dòng)仇冯、刪除文件或目錄
命令 | 含義 |
---|---|
touch filename |
創(chuàng)建空文件之宿,或 vim file 進(jìn)入vim編輯文件內(nèi)容 |
cp source_file dest_file |
復(fù)制文件 |
mv source_file dest_file |
移動(dòng)文件(即重命名) |
rm filename |
刪除文件 |
mkdir dirname |
創(chuàng)建目錄,-p指定創(chuàng)建不存在的父目錄 |
cp -r source_dir dest_dir |
復(fù)制目錄苛坚。若dest_dir存在則為移動(dòng)澈缺,否則是重命名 |
mv source_dir dest_dir |
移動(dòng)目錄 |
rm -r dirname |
刪除目錄(遞歸方式),或rmdir dirname 刪除空目錄 |
以上命令都可以有對(duì)應(yīng)的多來源形式炕婶,即
cp source_file1 source_file2 source_file3 dest_dir
mv source_file1 source_file2 source_file3 dest_dir
rm -f filename1 filename2 filename3
mkdir -p par1/par2/dirname # -p選擇指定同時(shí)創(chuàng)建確實(shí)的父目錄
cp -r source_dir1 source_dir2 source_dir3 dest_dir
mv source_dir1 source_dir2 source_dir3 dest_dir
rm -rf dirname1 dirname2 dirname3