鍍金池/ 教程/ Python/ 附錄 A-練習(xí) 6:列出當(dāng)前路徑 (ls)
附錄 A-練習(xí) 9:生成一個(gè)空文件(Touch, New-Item)
附錄 A-練習(xí) 10:復(fù)制文件 (cp)
exercise44.繼承 Vs.包含
附錄 A-練習(xí) 14:刪除文件 (rm)
附錄 A-練習(xí) 11:移動(dòng)文件 (mv)
exercise46.項(xiàng)目骨架
附錄 A-練習(xí) 3:如果你迷路了
exercise37.復(fù)習(xí)符號(hào)
exercise47.自動(dòng)化測(cè)試
exercise3.數(shù)字和數(shù)學(xué)計(jì)算
附錄 A-練習(xí) 1:安裝
exercise32.循環(huán)和列表
exercise31.做出決定
exercise42.對(duì)象、類、以及從屬關(guān)系
exercise48.更復(fù)雜的用戶輸入
下一步
簡(jiǎn)介
附錄 A-練習(xí) 7:刪除路徑 (rmdir)
exercise49.寫代碼語句
exercise18.命名, 變量, 代碼, 函數(shù)
exercise12.提示別人
exercise14.提示和傳遞
exercise40.模塊, 類和對(duì)象
附錄 A-練習(xí) 12:查看文件 (less, MORE)
exercise9.打印, 打印, 打印
exercise13.參數(shù), 解包, 變量
exercise30. Else 和 If
exercise28. 布爾表達(dá)式
附錄 A-練習(xí) 4:創(chuàng)建一個(gè)路徑 (mkdir)
附錄 A-練習(xí) 15:退出命令行 (exit)
exercise25. 更多更多的練習(xí)
exercise6.字符串和文本
exercise2.注釋和井號(hào)“#”
exercise21. 函數(shù)的返回值
附錄 A-下一步
exercise1.第一個(gè)程序
exercise23. 閱讀代碼
附錄 A-練習(xí) 5:改變當(dāng)前路徑 (cd)
exercise17.更多文件操作
exercise24. 更多的練習(xí)
exercise19.函數(shù)和變量
exercise51.從瀏覽器獲取輸入
exercise22. 到目前為止你學(xué)到了什么?
exercise41.學(xué)會(huì)說面向?qū)ο?/span>
exercise52.開始你的 web 游戲
exercise20. 函數(shù)和文件
exercise15.讀文件
exercise45.你來制作一個(gè)游戲
exercise10.那是什么?
exercise8.打印, 打印
exercise35.分支和函數(shù)
exercise26. 恭喜你,可以進(jìn)行一次考試了
exercise33.while 循環(huán)
exercise29. IF 語句
exercise36.設(shè)計(jì)和調(diào)試
exercise0.安裝和準(zhǔn)備
exercise50.你的第一個(gè)網(wǎng)站
附錄 A-練習(xí) 2:路徑, 文件夾, 名錄 (pwd)
exercise38.列表操作
附錄 A-練習(xí) 6:列出當(dāng)前路徑 (ls)
exercise16.讀寫文件
exercise4.變量和命名
exercise34.訪問列表元素
exercise11.提問
exercise43.基本的面向?qū)ο蟮姆治龊驮O(shè)計(jì)
附錄 A-簡(jiǎn)介
附錄 A-練習(xí) 8:目錄切換(pushd, popd)
來自老程序員的建議
exercise27. 記住邏輯
exercise5.更多的變量和打印
exercise7.更多的打?。ㄝ敵觯?/span>
附錄 A-練習(xí) 13:輸出文件 (cat)
exercise39.字典,可愛的字典

附錄 A-練習(xí) 6:列出當(dāng)前路徑 (ls)

這節(jié)練習(xí)中你將學(xué)習(xí)如何使用 ls 命令列出一個(gè)目錄下的所有內(nèi)容。

做到這些

開始之前,確認(rèn)你已經(jīng) cd 回到 temp 的上一層目錄。.如果你不知道你在哪里,使用 pwd 找到你的位置,然后移動(dòng)到正確的目錄下。

Linux/OSX

$ cd temp
$ ls
stuff
$ cd stuff
$ ls
things
$ cd things
$ ls
frank
$ cd frank
$ ls
joe
$ cd joe
$ ls
alex
$ cd alex
$ ls
$ cd john
$ ls
$ cd ..
$ ls
john
$ cd ../../../
$ ls
frank
$ cd ../../
$ ls
stuff
$

Windows

> cd temp
> ls

    Directory: C:\Users\zed\temp

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        12/17/2011   9:03 AM            stuff

> cd stuff
> ls

    Directory: C:\Users\zed\temp\stuff

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        12/17/2011   9:03 AM            things

> cd things
> ls

    Directory: C:\Users\zed\temp\stuff\things

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        12/17/2011   9:03 AM            frank

> cd frank
> ls

    Directory: C:\Users\zed\temp\stuff\things\frank

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        12/17/2011   9:03 AM            joe

> cd joe
> ls

    Directory: C:\Users\zed\temp\stuff\things\frank\joe

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        12/17/2011   9:03 AM            alex

> cd alex
> ls

    Directory: C:\Users\zed\temp\stuff\things\frank\joe\alex

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        12/17/2011   9:03 AM            john

> cd john
> ls
> cd ..
> ls

    Directory: C:\Users\zed\temp\stuff\things\frank\joe\alex

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        12/17/2011   9:03 AM            john

> cd ..
> ls

    Directory: C:\Users\zed\temp\stuff\things\frank\joe

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        12/17/2011   9:03 AM            alex

> cd ../../..
> ls

    Directory: C:\Users\zed\temp\stuff

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        12/17/2011   9:03 AM            things

> cd ..
> ls

    Directory: C:\Users\zed\temp

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        12/17/2011   9:03 AM            stuff

>

你應(yīng)該學(xué)到的

ls 能列出你當(dāng)前目錄中的所有內(nèi)容。你可以看到我用 cd 切換到不同的目錄下,然后列出該目錄下的所有內(nèi)容,這樣,我就知道我接下來要到哪個(gè)目錄中去了。

ls 命令有很多的命令選項(xiàng),當(dāng)我們學(xué)習(xí) help 命令之后,你將會(huì)學(xué)習(xí)如何得到這些命令選項(xiàng)的幫助信息。

更多練習(xí)

  • 輸入這里的每一個(gè)命令!你必須親手輸入這些命令來學(xué)習(xí)他們。只是讀他們并不夠。
  • 在 Unix 中, 在 temp 目錄下試試命令 ls -lR。
  • 在 Windows 中也可以試試 dir -R.
  • 使用 cd 進(jìn)入到你計(jì)算機(jī)上的其他目錄,然后使用 ls 看看當(dāng)前目錄里有什么。
  • 將你遇到的新問題更新到你的筆記本中。我知道你可能已經(jīng)有一些問題了,因?yàn)槲也]有覆蓋這些命令的所有點(diǎn)。
  • 記住,如果你迷路了,使用 ls 和 pwd 找到你在哪里,然后使用 cd 去到你要去的目錄。