跳轉到內容

LPI Linux 認證/LPI-101 練習結果

來自華夏公益教科書,開放的世界,開放的書籍
LPI logo

硬體和體系結構

[編輯 | 編輯原始碼]

配置基本 BIOS 設定

[編輯 | 編輯原始碼]

顯示可用物理記憶體量
free

cat /proc/meminfo | grep MemTotal
哪些裝置共享中斷線?
cat /proc/interrupts | more
有多少個 PCI 匯流排和橋接器?
lspci | wc -l
是否存在任何 PCI/ISA 橋接器?
lspci | grep 'PCI\|ISA'
lspci 的選項是什麼,用於列出所有 Intel PCI 裝置?
lspci -d 8086:*
將 IDE 硬碟設定為只讀模式的命令是什麼?
hdparm -r1 <裝置>
開啟/關閉硬碟快取的命令是什麼?
hdparm -W1 <裝置>    hdparm -W0 <裝置>
setpci 實用程式的作用是什麼?
setpci 是一款用於查詢和配置 PCI 裝置的實用程式。
在 PCI 裝置的暫存器 N 中寫入一個字的命令是什麼?
setpci -s 12:3.4 N.W=1
.

配置調變解調器和音效卡

[編輯 | 編輯原始碼]

設定 SCSI 裝置

[編輯 | 編輯原始碼]

設定不同的 PC 擴充套件卡

[編輯 | 編輯原始碼]

配置通訊裝置

[編輯 | 編輯原始碼]

配置 USB 裝置

[編輯 | 編輯原始碼]

Linux 安裝和軟體包管理

[編輯 | 編輯原始碼]

設計硬碟佈局

[編輯 | 編輯原始碼]

定期顯示虛擬記憶體使用情況
vmstat -n 1

安裝引導管理器

[編輯 | 編輯原始碼]

從原始碼建立和安裝程式

[編輯 | 編輯原始碼]

從原始碼編譯和安裝程式應遵循哪些步驟?
./configure
make
make install

管理共享庫

[編輯 | 編輯原始碼]

使用 Debian 軟體包管理

[編輯 | 編輯原始碼]
To see what will be installed on your computer, use the command:
 dpkg -c package_name.deb
If the package is already installed, you can see also what files were installed:
 dpkg -L package_name

dpkg-reconfigure <軟體包名稱>

使用 Red Hat 軟體包管理器 (RPM)

[編輯 | 編輯原始碼]
To see what will be installed on your computer, use the command:
 rpm -qpl package_name.rpm

GNU & Unix 命令

[編輯 | 編輯原始碼]

在命令列上操作

[編輯 | 編輯原始碼]

獲取有關 useradd 和 userdel 命令的資訊。
man useradd
man userdel
假設您的 $PAGER 設定為 less;使用空格鍵前進一頁,使用 B 返回。

建立兩個新帳戶 user1 和 user2,並使用 passwd 命令設定這些帳戶的密碼。 作為 root 鎖定帳戶,並檢查您是否仍然可以登入。

連線檔案的命令是什麼?
cat file1 file2

宣告並初始化以下環境變數 NAME 和 LASTNAME。 使用 echo 列印它們。
set NAME="Joe"
set LASTNAME="Bloggs"
echo "$NAME $LASTNAME"


啟動一個新的 bash(鍵入 bash)並檢查您是否仍然可以看到這些宣告的變數。
不能

使用 exec 啟動一個新的 bash 會話。 您是否仍然可以看到這些宣告的變數?
可以

使用 date 顯示月份。

新增一個名為 notroot 的新使用者,該使用者具有 root 的許可權並鎖定 root 帳戶。GNU 和 UNIX 命令

這是一個技巧問題。 唯一具有 root 許可權的帳戶是 UID 為零的帳戶。

可以修改 /etc/passwd,使“root”被稱為其他名稱,這將具有類似的效果;帳戶“root”將不再存在。 除非是翻譯成外語,否則我不明白這麼做的意義。

可以為檔案系統上的所有檔案設定 SUID 位,以獲得這種真正的“Redmond 風格”的安全措施,但同樣,為什麼要這樣做呢?



使用過濾器處理文字流

[編輯 | 編輯原始碼]
  1. Use wildcard characters and list all filenames that contain any character followed by 'in' in the /etc directory.
       ls /etc/in*
  2. Use wildcard characters and list all filenames that start with any character between 'a' and 'e' that have at least two more characters and do not end with a number.
       ls [a-e]?*[!0-9]
  3. Use wildcard characters and list all filenames of exactly 4 characters and all filenames starting with an uppercase letter. Do not descend into any directory found.
       ls -d [A-Z]???
  4. Use wildcard characters and list all files that contain 'sh' in /bin.
  5. Display your environment variable HOME preceded by the string "$HOME value is:"
  6. Display the contents of $SHELL with two asterisk characters before and after it.
  7. How would you display the following string of characters as is with echo using double quote and \.
         * @ # $ % ^ & * ( ) ' " \
  8. Compose echo commands to display the following two strings:
         * That's what he said!
         * 'Never Again!' he replied.
  9. Display the number of words in all files that begin with the letter 'h' in the /etc directory.
 10. How would you send a 2M (megabyte) file with two 1.44 M floppy. How would you put back together the split file?
 11. What is the command to translate the : delimiter in /etc/password by #?
         cat /etc/password | tr ":" "#"

執行基本檔案管理

[編輯 | 編輯原始碼]
  1. Compose an interactive command to remove all .tmp files in your home directory. Respond y to every prompt.

rm -i ~/*.tmp

  2. List all the files in the user's home directories ending with .pdf that are bigger than 50 blocks and have not been accessed for a month.

find /home -name "*.pdf" -atime +30 -size +50 -print

  3. Create a file file.h that will contain all the filenames ending with .h found in the /usr directory.

find /usr -name "*.h" > file.h

  4. Do a touch on all the c files found in /usr/src/packages directory.
  5. What are the default permissions when you create a new file and a new directory?
     new file --> 644
     new directory --> 755
  6. How would you create a new file or directory that contains a space in the filename? (Example: 'new dir')
     touch new\ file.txt
     mkdir new\ dir
      
  7. What is the command to remove all the files of types char and block in your home directory?
  8. How would you find the location of the program find?
  9. Delete all files in /tmp which are not owned by root and have not been accessed for a week.

使用流、管道和重定向

[編輯 | 編輯原始碼]

1. 建立一個名為 list.bin 的檔案,其中將包含 /bin 目錄中的所有檔名。

ls /bin > list.bin

2. 編寫一個命令,將 /usr/local/bin 中的檔案列表追加到名為 list.bin 的檔案中,並丟棄任何錯誤輸出。

ls /usr/local/bin >> list.bin 2>/dev/null

3. 將您的 list.bin 檔案拆分為 50 行長的檔案,並刪除 list.bin。

split -l 50 list.bin
rm -f list.bin

4. 從拆分後的檔案重新建立 list.bin(但以相反的順序)。

cat xab xaa > list.bin

7. 編寫一個命令,該命令將建立一個名為 list.sbin 的檔案,其中包含 /sbin 的內容,同時將其顯示到標準輸出。

ls /sbin | tee sbin.txt

8. 建立一個檔案,在檔名中包含建立時間。

ls -l /sbin > `date +%d_%m_%y.txt`

9. 建立一個檔案,該檔案將包含 /etc 目錄中所有以 .conf 為副檔名的檔名(以相反的順序)。 ls *.conf

ls /etc/*\.conf > first.txt
tac first.conf > end_list.txt
rm -f first.txt

建立、監視和殺死程序

[編輯 | 編輯原始碼]

1. 如何控制 PID 為 3196 的 CPU 使用率

top -p 3196
renice -20 3196

修改程序執行優先順序

[編輯 | 編輯原始碼]

使用正則表示式搜尋文字檔案

[編輯 | 編輯原始碼]

使用 vi 執行基本檔案編輯操作

[編輯 | 編輯原始碼]

以下所有 vi 命令都必須在命令模式下輸入。

  1. vi foo
  2. 最常用的是i,但還有其他方法可以進入命令模式。
  3. ZZ
  4. vi foo
  5. o在游標位置下方開啟一個新行,並將您置於命令模式。i直接將您置於命令模式,而不會建立新行,因此o更有效率。
  6. 按 esc 退出命令模式
  7. :q!

裝置、Linux 檔案系統、檔案系統層次結構標準

[編輯 | 編輯原始碼]

建立分割槽和檔案系統

[編輯 | 編輯原始碼]

維護檔案系統的完整性

[編輯 | 編輯原始碼]

控制檔案系統的掛載和解除安裝

[編輯 | 編輯原始碼]

管理磁碟配額

[編輯 | 編輯原始碼]

使用檔案許可權控制對檔案的訪問

[編輯 | 編輯原始碼]

管理檔案所有權

[編輯 | 編輯原始碼]

1.

 chmod u=rwx,g=rwx,o=rx <file>
 chmod u=rwx,g=r,o=r <file>
 chmod u=r,g=r,o= <file>
 chmod u=rwx,g=rx,o=rx <file>
 chmod u=rwx,g=rx,o=rx <file>
 chmod u=rx,g=x,o=x <file>
 chmod u=w,g=r,o=x <file>
 chmod u=,g=,o= <file>
 chmod u=,g=x,o=rwx <file>

2.

 chmod 777 <file>
 chmod 111 <file>
 chmod 421 <file>
 chmod 200 <file>
 chmod 640 <file>
 chmod 711 <file>

3.

 umaskː    0   0   2   7
 binaryː   000 000 010 111
 ̃invertedː 111 111 101 000

檔案許可權:邏輯與 0666

 ̃inverted maskː       111 111 101 000
 default permissionsː 000 110 110 110
 result of ANDː       000 110 100 000
 result in octalː     0   6   4   0
 resulting permissionsː   rw- r-- ---

目錄許可權:邏輯與 0777

 ̃inverted maskː       111 111 101 000
 default permissionsː 000 111 111 111
 result of ANDː       000 111 101 000
 result in octalː     0   7   5   0
 resulting permissionsː   rwx r-x ---


 umaskː    0   0   1   1
 binaryː   000 000 001 001
 ̃invertedː 111 111 110 110

檔案許可權:邏輯與 0666

 ̃inverted maskː       111 111 110 110
 default permissionsː 000 110 110 110
 result of ANDː       000 110 110 110
 result in octalː     0   6   6   6
 resulting permissionsː   rw- rw- rw-

目錄許可權:邏輯與 0777

 ̃inverted maskː       111 111 110 110
 default permissionsː 000 111 111 111
 result of ANDː       000 111 110 110
 result in octalː     0   7   6   6
 resulting permissionsː   rwx rw- rw-


 umaskː    0   5   4   1
 binaryː   000 101 100 001
 ̃invertedː 111 010 011 110

檔案許可權:邏輯與 0666

 ̃inverted maskː       111 010 011 110
 default permissionsː 000 110 110 110
 result of ANDː       000 010 010 110
 result in octalː     0   2   2   6
 resulting permissionsː   -w- -w- rw-

目錄許可權:邏輯與 0777

 ̃inverted maskː       111 010 011 110
 default permissionsː 000 111 111 111
 result of ANDː       000 010 011 110
 result in octalː     0   2   3   6
 resulting permissionsː   -w- -wx rw-


 umaskː    0   7   7   7
 binaryː   000 111 111 111
 ̃invertedː 111 000 000 000

檔案許可權:邏輯與 0666

 ̃inverted maskː       111 000 000 000
 default permissionsː 000 110 110 110
 result of ANDː       000 000 000 000
 result in octalː     0   0   0   0
 resulting permissionsː   --- --- ---

目錄許可權:邏輯與 0777

 ̃inverted maskː       111 000 000 000
 default permissionsː 000 111 111 111
 result of ANDː       000 000 000 000
 result in octalː     0   0   0   0
 resulting permissionsː   --- --- ---
[編輯 | 編輯原始碼]

1.

mkdir ~/etc ~/bin

2.

cp -r /etc/* ~/etc/
# or
cp -r /etc/ ~/
# or
rsync -a /etc/ ~/etc/

2.

# recursive variant using find
find -name '*.conf' -exec mv {} {}.bak \;
# non recursive variant using rename
rename 's/\.conf/\.conf\.bak/' *.conf

4.

ln -s ~/bin/ls ~/dir
~/dir

5.

rm ~/dir
# or
unlink ~/dir

~/bin/ls 檔案在這兩種情況下都不會丟失。

查詢系統檔案並將檔案放置在正確的位置

[編輯 | 編輯原始碼]

X 視窗系統

[編輯 | 編輯原始碼]

安裝和配置 XFree86

[編輯 | 編輯原始碼]

設定顯示管理器

[編輯 | 編輯原始碼]

安裝和定製視窗管理器環境

[編輯 | 編輯原始碼]
華夏公益教科書