LPI Linux 認證/LPI-101 練習結果
顯示可用的物理記憶體量
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 <device>
開啟/關閉硬碟快取的命令是什麼?
hdparm -W1 <device> hdparm -W0 <device>
setpci 實用程式的作用是什麼?
setpci 是一個用於查詢和配置 PCI 裝置的實用程式。
將一個字寫入 PCI 裝置的暫存器 N 的命令是什麼?
setpci -s 12:3.4 N.W=1
.
定期顯示虛擬記憶體使用情況
vmstat -n 1
從原始碼編譯和安裝程式應遵循哪些步驟?
./configure
make
make install
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 <package name>
To see what will be installed on your computer, use the command: rpm -qpl package_name.rpm
獲取有關 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 foo
- 最常用的是i,但還有其他進入命令模式的方法。
- ZZ
- vi foo
- o在游標位置下方開啟一個新行,並將你置於命令模式。i將你直接置於命令模式,而不會建立新行,因此o效率更高。
- 按 esc 退出命令模式
- :q!
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 檔案在這兩種情況下都不會丟失。