Linux命令練習第二關(2)

2021-07-22 04:43:27 字數 2207 閱讀 7531

(2)假如當前目錄是

[root@ianlinux iantest]# pwd

/data/iantest

現在因為需要進入到了/tmp目錄下進行操作,執行命令如下:

[root@ianlinux iantest]# cd /tmp

[root@ianlinux tmp]# pwd

/tmp

操作完畢後,希望快速返回上一次進入的目錄,即/data/iantest目錄,該如何做呢?

解答:

[root@ianlinux iantest]# pwd

/data/iantest

[root@ianlinux iantest]# cd /tmp

[root@ianlinux tmp]# pwd

/tmp

[root@ianlinux tmp]# cd - #回到進入/tmp之前的目錄

/data/iantest

[root@ianlinux iantest]#

cd -能回到上一次訪問的目錄

[root@ianlinux iantest]# pwd

/data/iantest

[root@ianlinux iantest]# cd /tmp

#此時系統環境變數oldpwd的變化

[root@ianlinux tmp]# env|grep -i oldpwd

oldpwd=/data/iantest

[root@ianlinux tmp]# cd -

/data/iantest

[root@ianlinux iantest]# pwd

/data/iantest

#此時系統環境變數oldpwd的變化

[root@ianlinux iantest]# env|grep -i oldpwd

oldpwd=/tmp

環境變數oldpwd始終記錄當前路徑的前乙個路徑的內容,而執行cd -命令返回進入此目錄之前所在的目錄。

補充:

(3)乙個目錄中有很多檔案(ls檢視時好多屏),想最快速度檢視到最近更新的檔案(前提:不知道檔案是什麼)。

解答:

[root@ianlinux ~]# ls -l /etc

total 1684

drwxr-xr-x. 5 root root 4096 aug 2

10:32 consolekit

-rw-r--r--. 1 root root 4439 oct 17

2013 dir_colors

-rw-r--r--. 1 root root 5139 oct 17

2013 dir_colors.256color

...#省略很多很多

[root@ianlinux ~]# touch /etc/latest.txt

[root@ianlinux ~]# ls -lrt /etc

ls -lrt 目錄新建的檔案latest.txt 會出現在最後一列

man ls 檢視ls的引數

-r, --reverse

reverse order while sorting

# 反轉排序

-t sort

by modification time

# 按修改時間排序

-l use a

long listing format

# 使用乙個長的列**式

補充有關ls引數:

–color=auto 應用於grep。給匹配到的字串加顏色,注意不是整行。

Linux命令練習第二關(1)

解答 根據顏色區分檔案和目錄 藍色 ls l結果中以d開頭的就是目錄。通過給目錄加標識,然後通過過濾標識就過濾出目錄 ls f或ls p 通過find直接查詢指定型別的檔案 d 就是目錄 實驗資料 d開頭的是目錄 方法二 基礎正規表示式字元 表示以 開頭,如 ian,以ian開頭的那一行。過濾出以d...

Linux命令練習第二關(8)

14 如何檢視etc services檔案有多少行?法一 wc 列印行號,位元組數 l 行數。root ianlinux wc l etc services法二 root ianlinux cat n etc services tail 1法三 root ianlinux awk etc servi...

黑板客爬蟲闖關第二關

這一關相比第一關反而更容易,因為不需要進行複雜的正則判斷,只需要用迴圈嘗試密碼即可。這裡需要用到requests的post請求,並在請求裡加上使用者名稱和密碼即可。coding utf 8 import requests wrongnotify 您輸入的密碼錯誤,請重新輸入 website inde...