LPI Linux Certification/LPI-101 Exercises results
Hardware & Architecture
editConfigure Fundamental BIOS Settings
editTo show the amount of physical RAM available:
free
or
cat /proc/meminfo | grep MemTotal
Which are the devices that are sharing an interrupt line?
cat /proc/interrupts | more
How many PCI buses and bridges are there?
lspci | wc -l
Are there any PCI/ISA bridges?
lspci | grep 'PCI\|ISA'
What is the option with lspci to list all the Intel PCI devices?
lspci -d 8086:*
What is the command to set you IDE hard drive in read only mode?
hdparm -r1 <device>
What is the command to turn on/off the disk cache hard drive?
hdparm -W1 <device> hdparm -W0 <device>
What does the setpci utility do?
setpci is a utility for querying and configuring PCI devices.
What would be the command to write a word in register N of a PCI device?
setpci -s 12:3.4 N.W=1
.
Configure Modem and Sound cards
editSetup SCSI Devices
editSetup different PC expansion cards
editConfigure Communication Devices
editConfigure USB devices
editLinux Installation & Package Management
editDesign hard disk layout
editTo display periodically the virtual memory usage:
vmstat -n 1
Install a boot manager
editMake and install programs from source
editWhat steps should you follow to compile and install a program from source?
./configure
make
make install
Manage shared libraries
editUse Debian package management
editTo 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>
Use Red Hat Package Manager (RPM)
editTo see what will be installed on your computer, use the command: rpm -qpl package_name.rpm
GNU & Unix Commands
editWorking on the command line
edit Get information on the useradd and userdel commands.
man useradd
man userdel
Assuming you have $PAGER set to less; Use SPACE to advance by one page, B to go back.
Create two new accounts user1 and user2 and set the passwords to those accounts with the passwd command. As root lock the accounts and check if you can still log in.
What is the command to concatenate files?
cat file1 file2
Declare and Initialize the following environment variables NAME and LASTNAME. Use echo to print them out.
set NAME="Joe"
set LASTNAME="Bloggs"
echo "$NAME $LASTNAME"
Start a new bash (type bash) and check that you can still see those declared variables.
No
Use exec to start a new bash session. Can you still see those declared variables?
Yes
Use date to display the month.
Add a new user named notroot with root's rights and lock the root account.GNU and UNIX Commands
This is a trick question. The only account with root privileges is the one with a UID of zero.
One could alter /etc/passwd so that “root” is called something else, which would have the a similar effect; the account “root” would no longer exist. With the possible exception of translation to a foreign language, I can’t see the point in doing this.
You could set the SUID bit on all files on the file system for that authentic “Redmond style" security but again, why would you want to?
Process text streams using filters
edit1. 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 ":" "#"
Perform basic file management
edit1. 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.
Use streams, pipes, and redirects
edit1. Create a file list.bin that will contain all the file names from the /bin directory.
ls /bin > list.bin
2. Write a command that will append the list of files from /usr/local/bin to the file named list.bin and discard any error output.
ls /usr/local/bin >> list.bin 2>/dev/null
3. Split your list.bin file into files that are 50 lines long and remove list.bin.
split -l 50 list.bin rm -f list.bin
4. From the split files recreate list.bin (but with inversed order).
cat xab xaa > list.bin
7. Write a command that will create a file list.sbin with the contents of /sbin and at the same time display it to standard output.
ls /sbin | tee sbin.txt
8. Create a file that within the filename you include the creation time.
ls -l /sbin > `date +%d_%m_%y.txt`
9. Create a file that will contain all the filenames in reverse order with extension .conf from the /etc directory. ls *.conf
ls /etc/*\.conf > first.txt tac first.conf > end_list.txt rm -f first.txt
Create, monitor, and kill processes
edit1. How can you control CPU usage for PID 3196
top -p 3196 renice -20 3196
Modify process execution priorities
editSearch text files using regular expressions
editPerform basic file editing operations using vi
editAll of the vi commands below must of course be entered in command mode.
- vi foo
- Most frequently one would use i, but there are other ways of getting into command mode.
- ZZ
- vi foo
- o opens a new line beneath the cursor position and drops you into command mode. i puts you directly into command mode without making the new line, so o is more efficient.
- press esc to get out of command mode
- :q!
Devices, Linux Filesystems, Filesystem Hierarchy Standard
editCreate partitions and filesystems
editMaintain the integrity of filesystems
editControl mounting and unmounting filesystems
editManaging disk quota
editUse file permissions to control access to files
editManage file ownership
edit1.
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
File permissionsː Logically AND with 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-- ---
Directory permissionsː Locically AND with 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
File permissionsː Logically AND with 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-
Directory permissionsː Locically AND with 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
File permissionsː Logically AND with 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-
Directory permissionsː Locically AND with 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
File permissionsː Logically AND with 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ː --- --- ---
Directory permissionsː Locically AND with 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ː --- --- ---
Create and change hard and symbolic links
edit1.
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
The ~/bin/ls file gets lost in neither of the cases.