LPI Linux Certification/LPI-101 Exercises results

LPI logo

Hardware & ArchitectureEdit

Configure Fundamental BIOS SettingsEdit

To 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 cardsEdit

Setup SCSI DevicesEdit

Setup different PC expansion cardsEdit

Configure Communication DevicesEdit

Configure USB devicesEdit

Linux Installation & Package ManagementEdit

Design hard disk layoutEdit

To display periodically the virtual memory usage:
vmstat -n 1

Install a boot managerEdit

Make and install programs from sourceEdit

What steps should you follow to compile and install a program from source?
./configure
make
make install

Manage shared librariesEdit

Use Debian package managementEdit

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>

Use Red Hat Package Manager (RPM)Edit

To see what will be installed on your computer, use the command:
 rpm -qpl package_name.rpm

GNU & Unix CommandsEdit

Working on the command lineEdit

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 filtersEdit

  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 ":" "#"

Perform basic file managementEdit

  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.

Use streams, pipes, and redirectsEdit

1. 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 processesEdit

1. How can you control CPU usage for PID 3196

top -p 3196

Modify process execution prioritiesEdit

Search text files using regular expressionsEdit

Perform basic file editing operations using viEdit

All of the vi commands below must of course be entered in command mode.

  1. vi foo
  2. Most frequently one would use i, but there are other ways of getting into command mode.
  3. ZZ
  4. vi foo
  5. 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.
  6. press esc to get out of command mode
  7. :q!

Devices, Linux Filesystems, Filesystem Hierarchy StandardEdit

Create partitions and filesystemsEdit

Maintain the integrity of filesystemsEdit

Control mounting and unmounting filesystemsEdit

Managing disk quotaEdit

Use file permissions to control access to filesEdit

Manage file ownershipEdit

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

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 linksEdit

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

The ~/bin/ls file gets lost in neither of the cases.

Find system files and place files in the correct locationEdit

The X Window SystemEdit

Install & Configure XFree86Edit

Setup a display managerEdit

Install & Customize a Window Manager EnvironmentEdit

Last modified on 22 March 2014, at 22:49