- ls -- 列出當(dāng)前目錄下的文件(不包含隱藏文件)
- ls -l -- 列出當(dāng)前目錄下文件的詳細(xì)信息
- ls -a -- 列出當(dāng)前目錄下的文件(包含隱藏文件)
效果如下:
? ~ ls
anyang Documents IdeaProjects Public wget-log
configuration Downloads Music Templates
Desktop examples.desktop Pictures Videos
? ~ ls -l
total 56
drwxr-xr-x 3 anyang anyang 4096 12月 2 19:50 anyang
drwxr-xr-x 3 anyang anyang 4096 11月 29 22:27 configuration
drwxr-xr-x 2 anyang anyang 4096 11月 29 11:56 Desktop
drwxr-xr-x 2 anyang anyang 4096 11月 29 11:56 Documents
drwxr-xr-x 5 anyang anyang 4096 11月 29 20:45 Downloads
-rw-r--r-- 1 anyang anyang 8980 11月 29 03:47 examples.desktop
drwxr-xr-x 2 anyang anyang 4096 11月 29 22:26 IdeaProjects
drwxr-xr-x 2 anyang anyang 4096 11月 29 11:56 Music
drwxr-xr-x 2 anyang anyang 4096 12月 2 21:44 Pictures
drwxr-xr-x 2 anyang anyang 4096 11月 29 11:56 Public
drwxr-xr-x 2 anyang anyang 4096 11月 29 11:56 Templates
drwxr-xr-x 2 anyang anyang 4096 11月 29 11:56 Videos
-rw-r--r-- 1 anyang anyang 0 11月 28 22:03 wget-log
? ~ ls -a
. .fonts.conf Public
.. .gconf .ssh
.adobe .gitconfig .sudo_as_admin_successful
anyang .gnome Templates
.bash_history .gradle Videos
.bash_logout .ICEauthority .viminfo
.bashrc IdeaProjects .WebStorm2016.3
.cache .IntelliJIdea2016.3 wget-log
.compiz .java .Xauthority
.config .local .xinputrc
configuration .macromedia .xsession-errors
Desktop .mozilla .xsession-errors.old
.dmrc Music .zcompdump
Documents .oh-my-zsh .zcompdump-anyang-5.2
Downloads Pictures .zsh_history
examples.desktop .pki .zshrc
.fonts .profile .zsh-update
- cd directory -- 切換目錄
- cd .. -- 切換到當(dāng)前目錄的上一級(jí)目錄
- cd - -- 切換到最近一次所在的目錄
- cd ~ 或 cd -- 切換到當(dāng)前用戶的家目錄
效果如下:
? ~ cd anyang
? anyang ls
file1 file2 learngit
? anyang cd ..
? ~ cd -
~/anyang
? anyang cd ~
? ~ cd anyang
? anyang cd
? ~
- mkdir directory -- 創(chuàng)建目錄
- rmdir directory -- 刪除空目錄
效果如下:
? anyang ls
file1 file2 learngit
? anyang mkdir test
? anyang ls
file1 file2 learngit test
? anyang rmdir test
? anyang ls
file1 file2 learngit
- touch file -- 新建文件(輸入多個(gè)文件名實(shí)現(xiàn)多文件創(chuàng)建)
- rm file -- 刪除文件(輸入多個(gè)文件名實(shí)現(xiàn)多文件刪除)
效果如下:
? anyang touch newfile1 newfile2 newfile3
? anyang ls
file1 file2 learngit newfile1 newfile2 newfile3
? anyang rm file1 file2
? anyang ls
learngit newfile1 newfile2 newfile3
- rm -r directory -- 遞歸刪除非空目錄(刪除目錄和目錄下的內(nèi)容)
- rm -fr directory -- 強(qiáng)制遞歸刪除非空目錄(刪除目錄和目錄下的內(nèi)容)
效果如下:
? anyang mkdir test
? anyang ls
learngit newfile1 newfile2 newfile3 test
? anyang cd test
? test touch file1 file2 file3
? test ls
file1 file2 file3
? test cd ..
? anyang ls
learngit newfile1 newfile2 newfile3 test
? anyang rmdir test
rmdir: failed to remove 'test': Directory not empty
? anyang rm test // 此處如果不加 -r 參數(shù),則會(huì)報(bào)錯(cuò)色罚,因?yàn)樵撃夸洖榉强漳夸?rm: cannot remove 'test': Is a directory
? anyang rm -r test
? anyang ls
learngit newfile1 newfile2 newfile3
- mv file/directory path -- 移動(dòng)文件位置(默認(rèn)移動(dòng)整個(gè)文件夾,包含文件夾下的內(nèi)容)
- mv file1 file2 -- 文件 file1 重命名為 file2
效果如下:
? anyang ls
file1 learngit test
? anyang ls test
? anyang mv file1 test
? anyang ls test
file1
? anyang ls
learngit test
? anyang cd test
? test mv file1 test1
? test ls
test1
- cp file1 file2 -- 拷貝 file1 到 file2
- cp -R 或 cp -r -- 遞歸拷貝目錄(默認(rèn)不會(huì)移動(dòng)目錄下的所有內(nèi)容,除非加上參數(shù) -R 或 -r)
效果如下:
? anyang ls
learngit test
? anyang touch file1
? anyang ls
file1 learngit test
? anyang cp file1 test/test1
? anyang cd test
? test ls
test1
? anyang mkdir newtest
? anyang ls
file1 learngit newtest test
? anyang cp test newtest // 如不加 -r 或 -R 參數(shù)則會(huì)報(bào)錯(cuò)辅肾,因?yàn)閠est目錄非空
cp: omitting directory 'test'
? anyang cp -r test newtest
? anyang cd newtest
? newtest ls
test
- cat file -- 輸出全部文件內(nèi)容
- cat > file -- 將標(biāo)準(zhǔn)輸入重定向到 file盾戴,且只能創(chuàng)建新文件, 不能編輯已有文件埠对。
效果如下:
? anyang ls
file1 learngit test
? anyang cat file1
Hello, anyang!
? anyang cat > file2
Add some words!
^C
? anyang cat file2
Add some words!
- more file -- 輸出文件內(nèi)容术健,顯示滿一個(gè)屏幕時(shí)暫停汹碱,此時(shí)可按空格健繼續(xù)顯示下一頁(yè),或按Q鍵停止顯示苛坚。
- less file -- 輸出文件內(nèi)容比被,顯示滿一個(gè)屏幕時(shí)暫停色难,此時(shí)除了可以按空格鍵向下顯示文件外泼舱,還可以利用上下鍵來(lái)顯示文件,當(dāng)結(jié)束時(shí)只需在:后輸入Q即可枷莉。
- head file -- 輸出文件前10行
- tail file -- 輸出文件后10行
- tail -f file -- 輸出文件內(nèi)容娇昙,參數(shù) -f 使 tail 不停地去讀文件最新的內(nèi)容,可用于監(jiān)控文件變化笤妙,Ctrl+c 終止監(jiān)控冒掌。
- ln -s file link -- 為文件 file 在另外一個(gè)位置建立一個(gè)同步的軟鏈接 link。
效果如下:
? anyang ls
file1 learngit test
? anyang cat file1
Hello, anyang!
? anyang ls test
? anyang ln -s file1 test/file1
? anyang ls test
file1
? anyang cd test
? test ls -l
total 0
lrwxrwxrwx 1 anyang anyang 5 12月 7 10:44 file1 -> file1
- stat file -- 查看文件狀態(tài)
- pwd -- 顯示當(dāng)前工作目錄
效果如下:
? anyang stat file1
File: 'file1'
Size: 15 Blocks: 8 IO Block: 4096 regular file
Device: 809h/2057d Inode: 402603 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ anyang) Gid: ( 1000/ anyang)
Access: 2016-12-07 10:10:58.987863942 +0800
Modify: 2016-12-07 10:10:45.947557464 +0800
Change: 2016-12-07 10:10:45.975558132 +0800
Birth: -
? anyang pwd
/home/anyang/anyang
相關(guān)資料:
- 29個(gè)你必須知道的Linux命令: http://www.imooc.com/article/1285
- 常用命令行介紹: https://github.com/iamcoach/console/blob/master/COMMANDS.md
- 常用命令行cheet sheet: https://bbs.excellence-girls.org/topic/167
- 書(shū)籍《鳥(niǎo)哥的Linux私房菜》: https://book.douban.com/subject/4889838/
- Ubuntu各種技巧:http://wiki.ubuntu.org.cn/UbuntuSkills