Midterm Test Flashcards
You have a service called “crond” on your system. This service is currently set to not start in any run level. What command would you use to cause it to start in run levels 2 and 3?
service crond 23 on
chkconfig –level 23 crond on
start crond –level 23
chkconfig –list crond
chkconfig –level 23 crond on
Which two commands will shutdown a system running the traditional init program and not do a reboot?
init 6
shutdown -h now
telinit 1
init 0
shutdown -h now
init 0
You hire Homer Simpson as a junior Linux Sys Admin for your company. You decide to test his job performance before letting him touch important systems. So you ask Homer to install the Apache web server version 2 on an older Debian system. The system uses the traditional init and init scripts to control what processes run at the different run levels. You tell Homer to make sure that Apache runs at run level 2, but does not run at run level 1.
After he is done, you login to the system to check his work. You notice a script called apache2 in the /etc/init.d directory. This is the correct init script. Next you look in the directory /etc/rc1.d and see this using ls -l.
lrwxrwxrwx 1 root root 17 Apr 3 2011 K09apache2 -> ../init.d/apache2
lrwxrwxrwx 1 root root 20 Mar 28 2011 K15pulseaudio -> ../init.d/pulseaudio
lrwxrwxrwx 1 root root 22 Mar 28 2011 K20acpi-support -> ../init.d/acpi-support
lrwxrwxrwx 1 root root 20 Mar 28 2011 K20kerneloops -> ../init.d/kerneloops
lrwxrwxrwx 1 root root 17 Feb 7 2013 K20postfix -> ../init.d/postfix
lrwxrwxrwx 1 root root 15 Mar 28 2011 K20saned -> ../init.d/saned
lrwxrwxrwx 1 root root 14 Sep 27 15:15 K73gpsd -> ../init.d/gpsd
lrwxrwxrwx 1 root root 13 Oct 1 16:37 K77ntp -> ../init.d/ntp
lrwxrwxrwx 1 root root 19 Mar 28 2011 S30killprocs -> ../init.d/killprocs
lrwxrwxrwx 1 root root 19 Mar 28 2011 S70dns-clean -> ../init.d/dns-clean
lrwxrwxrwx 1 root root 18 Mar 28 2011 S70pppd-dns -> ../init.d/pppd-dns
lrwxrwxrwx 1 root root 17 Apr 3 2011 S71apache2 -> ../init.d/apache2
lrwxrwxrwx 1 root root 16 Mar 28 2011 S90single -> ../init.d/single
You then look in the directory /etc/rc2.d and see this using ls -l
lrwxrwxrwx 1 root root 20 Mar 28 2011 S20fancontrol -> ../init.d/fancontrol
lrwxrwxrwx 1 root root 20 Mar 28 2011 S20kerneloops -> ../init.d/kerneloops
lrwxrwxrwx 1 root root 17 Feb 7 2013 S20postfix -> ../init.d/postfix
lrwxrwxrwx 1 root root 13 Oct 1 16:37 S23ntp -> ../init.d/ntp
lrwxrwxrwx 1 root root 14 Sep 27 15:15 S26gpsd -> ../init.d/gpsd
lrwxrwxrwx 1 root root 15 Mar 28 2011 S50rsync -> ../init.d/rsync
lrwxrwxrwx 1 root root 15 Mar 28 2011 S50saned -> ../init.d/saned
lrwxrwxrwx 1 root root 19 Mar 28 2011 S70dns-clean -> ../init.d/dns-clean
lrwxrwxrwx 1 root root 18 Mar 28 2011 S70pppd-dns -> ../init.d/pppd-dns
lrwxrwxrwx 1 root root 14 Sep 27 15:13 S75sudo -> ../init.d/sudo
lrwxrwxrwx 1 root root 17 Apr 3 2011 S91apache2 -> ../init.d/postfix
lrwxrwxrwx 1 root root 22 Mar 28 2011 S99acpi-support -> ../init.d/acpi-support
lrwxrwxrwx 1 root root 21 Mar 28 2011 S99grub-common -> ../init.d/grub-common
lrwxrwxrwx 1 root root 18 Mar 28 2011 S99ondemand -> ../init.d/ondemand
lrwxrwxrwx 1 root root 18 Mar 28 2011 S99rc.local -> ../init.d/rc.local
Did Homer setup Apache the way you told him to do?
Yes
No
I can not tell from the information above.
No answer text provided.
I can not tell from the information above.
On most newer Linux distributions the traditional init has been replaced with a newer system. What are the names of the two most common replacements? (select two)
upstart
systemd
initrd
Sys V Run Scripts
upstart
systemd
Match the description to the correct command.
Manage the current state of a service. Run or stop the service manually.
Tool to configure the runlevels for a service.
init
shutdown
service
chkconfig
Manage the current state of a service. Run or stop the service manually.
service
Tool to configure the runlevels for a service.
chkconfig
Which two commands will reboot a system running the traditional init program?
shutdown -h +2
shutdown -r now
init 6
telinit 1
shutdown -r now
init 6
In the traditional linux run levels. Run level blank is used to halt the system and run level blank is used to reboot the system.
0,6
You are working on an older RedHat system that uses the traditional init and init scripts to control programs. You know that Redhat uses the name httpd to refer to the Apache web server. What command could you use to check to see if Apache is running?
telinit httpd
chkconfig httpd status
systemctl status apache
service httpd status
service httpd status
In the traditional Linux boot sequence which component is responsible for loading and executing the init process? Initial Ram Disk BIOS MBR Kernel
Kernel
Match the stage of the traditional Linux boot sequence to its correct component.
Stage 1
Stage 2
Stage 3
Stage 4
Stage 5
Stage 6
BIOS Runlevel Kernel Init MBR Grub systemctl
Stage 1
BIOS
Stage 2
MBR
Stage 3
Grub
Stage 4
kernel
Stage 5
init
Stage 6
runlevel scripts
You want to create an alias called lm. It will run the ls command with the -a and -l options and pipe the results to the less pager command. Which of the following is the correct syntax to create this new alias at the shell prompt?
alias ‘ls -la | less’=lm
set lm=”ls -la | less”
alias lm=’ls -la | less’
export lm; ls -la; less
alias lm=’ls -la | less’
johnb@booboo:/tmp/test$ ls /etc > Notes.txt
johnb@booboo:/tmp/test$ head notes.txt
How will the shell respond to the head command?
Show the top 10 lines of the file
Show the bottom 10 lines of the file
Give the error “notes.txt: no such file or directory”
Give the error “Command not found”
Give the error “notes.txt: no such file or directory”
You have been told that the command fdisk is used to partition hard drives. At the command line how might you get a list of any options used with the fdisk command? (select 2)
which fdisk
man -k fdisk
fdisk -h
man fdisk
man fdisk
fdisk -h
You have added a new executable script to the directory /usr/local/sbin called myscript.sh. You are currently in your home directory. You view the value of your $PATH environment variable with the echo command. It looks like this:
/bin:/usr/bin:/usr/local/bin:/usr/games:/usr/bin/X11
What will happen if you type the command “myscript.sh” at the command prompt?
The shell will show the contents of myscript.sh.
The output of myscript.sh will be added to a file in the current directory.
The script myscript.sh will run.
The shell will give the error “Command not found”.
The shell will give the error “Command not found”.
The pwd command tells you that you are in the /var/log directory. You want to edit a file called file_list located in the /tmp directory, but want to stay in the /var/log directory. Which commands would work? (select two) vi ../tmp/file_list vi ./file_list vi ../../tmp/file_list vi /tmp/file_list
vi /tmp/file_list
What command will display the name of the present working directory?
uname -p
cd
history
pwd
pwd
What command would you enter to see a list of all the commands you recently used at the command prompt? uname clear bash history
history
Which command will show the current user name?
whoami
exec $USER
ls –user
pwd
whoami
What command produces a list of all the shell environment variables?
env
echo $ENV
cat $ENV
unset ENV
env
The output of the free command gives a listing of how much ram memory is being used on a system. You decide to keep track of the memory usage on your system by running this command once an hour for a day and saving the output into a file so you can review the memory usage over the course of the day. Which command line would you use to save all the output into the file~/free_output.txt.
free > ~/free_output.txt
cat ~/free_output.txt
free»_space; ~/free_output.txt
free | ~/free_output.txt
free»_space; ~/free_output.txt
At the command line you do a pwd command, It shows you that your current working directory is /var/log. What command would you use to change directory to /var/lib/mysql using a relative path?
mkdir /var/lib/mysql
cd ~/var/lib/mysql
cd ../../lib/mysql
cd ../lib/mysql
cd ../lib/mysql
Select two ways of saving and exiting a vi session.
:wq
:q!
Shift ZZ
:w
:wq
Shift ZZ
When you were working on a system last week, you kept some notes in a file about what you did. Now you are on that system, but can not remember the name you called the file. But you remember that you used vi to edit the file. You decide to search your command history to find all the uses of the vi program in the hope that one usage will show the file name. What command would you use to search your history to find all uses of vi?
cat ~/.bashrc
history»_space; vi
history | grep vi
ps ax | grep vi
history | grep vi
You want to check the file sizes of several files in your home directory. You know that some of them begin with a dot and are normally hidden. What command could you give to view the sizes of the files.
ls -la
ls -Ri
ls -l
ls -d
ls -la
total 16
10750961 drwxrwxr-x 4 root fuse 4096 Feb 6 15:33 .
9699331 drwxr-xr-x 62 johnb johnb 4096 Feb 6 14:52 ..
10750963 -rw-rwxr– 1 root fuse 0 Nov 19 2013 myfile
10750971 drwxrwxrwx 2 root fuse 4096 Nov 21 2013 newdir
10750977 drwxr-xr-x 2 root fuse 4096 Nov 21 2013 newdir2
10750970 -rw-rw-rw- 1 root fuse 0 Nov 21 2013 newfile
10750972 -rw-rw-r– 1 root fuse 0 Nov 21 2013 newfile2
10750973 -rw-r–r– 1 root fuse 0 Nov 21 2013 newfile3
10751663 -rw-r–r– 1 root root 0 Feb 6 15:33 .reconf
Which command produced the output above?
file newfile*
ls -l
ls -lai
ls –all
ls -lai
The pwd command shows that you are in your home directory. You have a file in your home directory called pumpkin.txt. You want to move this file to the /tmp directory and rename it to lantern.txt. What command would you use?
mv pumpkin.txt /tmp/lantern.txt
mv /tmp/lantern.txt pumpkin.txt
ln -s pumpkin.txt /tmp/lantern.txt
touch /tmp/lantern.txt
mv pumpkin.txt /tmp/lantern.txt
You decide that you want to make a backup of all the configuration files in the /etc directory. You are currently the root user. You have connected a usb disk to the /mnt directory in the file system. What command would you use to copy the contents of /etc and all its sub-directories to the /mnt directory?
cp -r /etc /mnt
cp -r /mnt /etc
mv /etc /mnt
ln -s /mnt /etc
cp -r /etc /mnt
You have a directory in your home directory called my_junk. It has several dozen files and directories in it. You decide that you want to get rid of my_junk and everything in it, but you don’t want to delete every file and directory individually. What command can you give to remove my_junk and all its contents?
rm -rf ~/my_junk
rmdir ~/my_junk
find ~/my_junk | xargs shred
rm -rf /
rm -rf ~/my_junk
Which of the following commands should you use to view just the last 10 lines of your /var/log/messages file? cat /var/log/messages file /var/log/messages head /var/log/messages tail /var/log/messages
tail /var/log/messages
You have opened a file with vi and are adding text to the document in text entry mode. You now want to edit the document to move one paragraph above another. What key must you press to leave text entry mode and go to the command mode?
esc (escape key)
Ctrl-O
Shift ZZ
:exit
esc (escape key)
Select two commands that will make a symbolic link from the file foo to the name foo2.
ln foo foo2 cp foo2 foo ln -s foo2 foo ln -s foo foo2 cp -s foo foo2
cp -s foo foo2
ln -s foo foo2
You need to find all files in and below /home that are owned by the user "karenl". Which command below would you use to find these files? which /home/karenl grep -r karenl /home/* locate karenl /home find /home -user karenl
find /home -user karenl
You have just installed the MySQL database program on your server. According to a Howto you found, the configuration file for MySQL is called my.cnf. But you don’t know which directory on your system has this file. What command can you use to find my.cnf?
find /var -name my.cnf
locate my.cnf
find /etc -name my.cnf
grep -r my.cnf /etc/*
find /etc -name my.cnf
You decide to change the permissions on a command called “free” so only the root user can run it. What command could you use to find where the “free” executable file is located?
which free
ls -la free
man -k free
grep / free
which free
Your junior system administrator Homer has been working for a month on a project on one of your systems. You notice that he has been putting many temporary files in the directory /var/junk, but not deleting them. You decide to delete any files he has not modified in a week, or that are bigger than 100 MB. How would get a list of any files that match those criteria?
find /var/junk -mtime +7 -o -size +100M
find /var/junk -mtime +7 -size +100M
find /var/junk -size +100M | grep mtime +7
find /var/junk -mtime +7 -o -size -100M
find /var/junk -mtime +7 -o -size +100M
srwxr-xr-x 1 johnb johnb 0 Feb 6 09:46 debconf_141996_eabdecdb_data
-rw-r–r– 1 johnb johnb 0 Feb 9 20:32 foo
lrwxrwxrwx 1 johnb johnb 3 Feb 9 20:32 foo2 -> foo
drwx—— 2 johnb johnb 4096 Feb 3 19:30 gpg-TlVQX7
-rw——- 1 johnb johnb 2443 Feb 9 12:28 JEQWTX.tmp
Based on the ls fragment above, the file foo2 is a hard link, true or false?
True
False
False
What command searches through the content of files looking for keyword or regular expression matches? find which grep locate
grep
What command searches through the file system looking for files by name, file size, time created, and other metadata?
find
locate
grep
which
find