Linux Command Line Exam with Complete Solutions, Exams of Advanced Education

A comprehensive overview of the linux command line, covering a wide range of topics such as file organization, command-line options, file manipulation, text processing, compression, and more. It includes detailed explanations and complete solutions to various linux command-line tasks, making it a valuable resource for anyone studying or working with the linux operating system. Essential linux commands, their syntax, and practical examples, providing a solid foundation for understanding and effectively using the linux command-line interface. Whether you are a student, a system administrator, or a linux enthusiast, this document can serve as a comprehensive study guide, lecture notes, or reference material to help you master the linux command line and enhance your skills in working with the operating system.

Typology: Exams

2023/2024

Available from 10/14/2024

Examproff
Examproff šŸ‡ŗšŸ‡ø

3

(2)

8.3K documents

1 / 44

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Linux Command Line Exam with
Complete Solutions
What is the shell? - ANS-A program that takes keyboard commands and passes them
to the operating system to carry out.
What is BASH (Bourne Again Shell)? - ANS-A common shell program from the GNU
Project found on almost all Linux distributions.
What is the terminal emulator? - ANS-A program that gives access to the shell.
What is the shell prompt? - ANS-The window that appears when the terminal emulator
is launched.
What does pressing the up-arrow key in the terminal do? - ANS-It brings up previously
executed commands.
What does pressing the down-arrow key in the terminal do? - ANS-It makes the
previous command disappear.
What does pressing the left and right arrow keys in the terminal do? - ANS-It positions
the cursor on the current line.
How do you automatically copy text? - ANS-Highlight the text in question.
How do you paste automatically copied text? - ANS-Press the middle mouse button.
How do you access the virtual terminal/console? - ANS-Press CTRL-ALT-F1 through
CTRL-ALT-F6.
How are files organized in a hierarchical directory structure? - ANS-In a singled root
tree-like pattern of directories (folders).
What is the root directory? - ANS-The first directory in the filesystem. It contains files
and subdirectories, which contain more files and subdirectories, and so on.
What is a parent directory? - ANS-It is the directory directly above.
What is the current working directory? - ANS-It is the directory in use.
What is a pathname? - ANS-A route taken along the filesystem to get to the desired
directory.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c

Partial preview of the text

Download Linux Command Line Exam with Complete Solutions and more Exams Advanced Education in PDF only on Docsity!

Linux Command Line Exam with

Complete Solutions

What is the shell? - ANS-A program that takes keyboard commands and passes them to the operating system to carry out. What is BASH (Bourne Again Shell)? - ANS-A common shell program from the GNU Project found on almost all Linux distributions. What is the terminal emulator? - ANS-A program that gives access to the shell. What is the shell prompt? - ANS-The window that appears when the terminal emulator is launched. What does pressing the up-arrow key in the terminal do? - ANS-It brings up previously executed commands. What does pressing the down-arrow key in the terminal do? - ANS-It makes the previous command disappear. What does pressing the left and right arrow keys in the terminal do? - ANS-It positions the cursor on the current line. How do you automatically copy text? - ANS-Highlight the text in question. How do you paste automatically copied text? - ANS-Press the middle mouse button. How do you access the virtual terminal/console? - ANS-Press CTRL-ALT-F1 through CTRL-ALT-F6. How are files organized in a hierarchical directory structure? - ANS-In a singled root tree-like pattern of directories (folders). What is the root directory? - ANS-The first directory in the filesystem. It contains files and subdirectories, which contain more files and subdirectories, and so on. What is a parent directory? - ANS-It is the directory directly above. What is the current working directory? - ANS-It is the directory in use. What is a pathname? - ANS-A route taken along the filesystem to get to the desired directory.

What is an absolute pathname? - ANS-A pathname that begins with the root directory and follows the tree branch by branch until the path to the desired directory or file is completed. What is a relative pathname? - ANS-A pathname that begins from the current working directory and uses. (dot) and .. (dot dot) to represent relative positions in the filesystem.

. (dot) refers to the working directory and .. (dot dot) refers to the working directory's parent directory. Are filenames with a period hidden by default? - ANS-Yes. Are filenames not case sensitive? - ANS-No. What type of characters should be avoided in filenames? - ANS-Avoid punctuation characters and spaces. What do options in commands do? - ANS-They modify the behavior of the commands. What are arguments in commands? - ANS-The items upon which the command acts. What is the form a command is written in? - ANS-command -options arguments and/or --options for long options What do configuration files do? - ANS-They contain system settings. What are scripts? - ANS-They are programs that the system uses. What is Less? - ANS-A pager program (allows for easy viewing of long text documents page by page) What is a symbolic link? - ANS-A file that references other files. What do wildcards do? - ANS-They select filenames based on a pattern of characters. What four things can commands be? - ANS-1. Executable programs

  1. Shell built-ins
  2. A shell function
  3. An alias What is an alias? - ANS-A user-defined command. What is a manual (man) page? - ANS-A piece of documentation for executable programs displayed with Less. What is an info page? - ANS-A more comprehensive alternative to man pages displayed with a reader program (a program that displays info in a website-like manner).

cd ./dir is what kind of pathname? - ANS-A relative pathname. Can multiple short options be strung together? - ANS-Yes. ls -a or ls --all - ANS-List all files, even those that begin with a period (i.e. hidden). ls -l - ANS-Display results of the directory's contents in a long format. ls -l -d or ls -l --directory - ANS-Display details about the directory rather than its contents. ls -F or ls --classify - ANS-Append an indicator name to the end of each listed name (i.e. a forward slash if the name is a directory). ls -l -h or ls -l --human-readable - ANS-In long format listings, display file sizes in human-readable format rather than in bytes. ls -r - ANS-Display the results in reverse alphabetical order (ls normally displays results in alphabetical order). ls -S - ANS-Sort results by size (biggest files first). ls -t - ANS-Sort results by modification time (most recent files first). ls -ltr - ANS-Display long results with most recent files last. file - ANS-Display brief description of a file* content and filetype. Less: Page Up or b - ANS-Scroll back one page. Less: Page Down or Spacebar. - ANS-Scroll forward one page. Less: Up Arrow - ANS-Scroll up one line. Less: Down Arrow - ANS-Scroll down one line. Less: G - ANS-Move to the end of the text file. Less: g - ANS-Move to the beginning of the text file. Less: /characters - ANS-Search forward to the next occurrence of characters. Less: n - ANS-Search for the next occurrence of the previous search. Less: h - ANS-Display help screen.

Less: q - ANS-Quit Less. / - ANS-The root directory, where everything begins. /bin - ANS-Contains binaries (programs) that must be present for the system to boot and run. /boot - ANS-Contains the linux kernel, initial RAM disk image (for drivers needed at boot time), and the boot loader. /dev - ANS-Contains a list of device nodes (the devices the kernel understands). /etc - ANS-Contains all of the system-wide configuration files and a collection of shell scripts that start each of the system services at boot time. /home - ANS-Ordinary users can only write files here (protects the system from errant user activity). /lib - ANS-Contains shared library files used by the core system programs. /lost+found - ANS-Contains a partial recovery from a filesystem corruption event. /media - ANS-Contains mount points for removable media such as USB drives, CD- ROMS, etc. that are mounted automatically at insertion. /opt - ANS-Contains commercial software products that may be installed on the system. /proc - ANS-Contains a virtual filesystem maintained by the Linux kernel and provides a picture of how the kernel sees the computer. /root - ANS-The home directory for the root account. /sbin - ANS-Contains "system" binaries. /tmp - ANS-Contains temporary, transient files created by various programs. /usr - ANS-Contains all the programs and support files used by regular users. /usr/bin - ANS-Contains the executable programs installed by your Linux distribution. /usr/lib - ANS-Contains the shared libraries for the programs in /usr/bin. /usr/local - ANS-Contains programs that are not included with the distribution but are intended for system-wide use are installed.

Wildcard: [:alnum:] - ANS-Any alphanumeric character. Wildcard: [:alpha:] - ANS-Any alphabetic character. Wildcard: [:digit:] - ANS-Any numeral. Wildcard: [:lower:] - ANS-Any lowercase letter. Wildcard: [:upper:] - ANS-Any uppercase letter. Wildcard: g* - ANS-Any file beginning with g. Wildcard: b.txt - ANS-Any file beginning with b followed by any characters and ending with .txt. Wildcard: Data??? - ANS-Any file beginning with Data followed by exactly three characters. Wildcard: [abc] - ANS-Any file beginning with either a, b, or c. Wildcard: BACKUP.[0-9][0-9][0-9] - ANS-Any file beginning with BACKUP. followed by exactly three numerals. Wildcard: [[:upper:]]* - ANS-Any file beginning with an uppercase letter. Wildcard: [![:digit:]]* - ANS-Any file not beginning with a numeral. Wildcard: *[[:lower:]123] - ANS-Any file ending with a lowercase letter or the numerals 1, 2, or 3. mkdir dir1 dir2 dir3 - ANS-Create directories dir1, dir2, and dir mkdir -p dir1/dir2 - ANS-Create nested directories. cp sourcefile destfile - ANS-Copy a file named sourcefile to destfile. cp file1 file2 dir - ANS-Copy files to a directory. cp -r dir1 dir2 - ANS-Copy a directory (recursively) into dir2. cp -a or cp --archive - ANS-Copy the files and directories and all of their attributes, including ownerships and permissions. cp -i or cp --interactive - ANS-Before overwriting an existing file, prompt the user.

cp -r or cp --recursive - ANS-Recursively copy directories and their contents (required when copying directories). cp -u or cp --update - ANS-When copying files from one directory to another, copy only files that either don't exist or are newer than the existing corresponding files in the destination directory. cp -v or cp --verbose - ANS-Display informative messages as the copy is performed cp dir1/* dir2 - ANS-Copy all the files in dir1 into dir2. mv -i or mv --interactive - ANS-Before overwriting an existing file, prompt the user for confirmation. mv -u or mv --update - ANS-When moving files from one directory to another, move only files that either don't exist in the destination directory or are newer than the existing corresponding files in the destination directory. mv -v or mv --verbose - ANS-Display informative messages as the move is performed. mv file1 file2 - ANS-Move file1 to file2. mv -i file1 file2 - ANS-Move file1 to file2. If file2 exists, the user is prompted before it is overwritten. mv file1 file2 dir1 - ANS-Move file1 and file2 into dir1. mv dir1 dir2 - ANS-Move dir1 (and its contents) into dir2. rm -i or rm --interactive - ANS-Before deleting an existing file, prompt the user for confirmation. rm -r or rm --recursive - ANS-Recursively delete directories. rm -f or rm --force - ANS-Ignore nonexistent files and do not prompt. Overrides the -- interactive option. rm -v or rm --verbose - ANS-Display informative messages as the deletion is performed. rm file1 - ANS-Delete file1. rm -i file1 - ANS-Before deleting file1, prompt the user for confirmation. rm -r file1 dir1 - ANS-Delete file1 and dir1 (and its contents)

apropos searchterm - ANS-Display appropriate commands relevant to searchterm. alias foo="cd Documents" - ANS-A user-defined command called foo which is equivalent to the command "cd Documents". Where does output go to and input come from normally? - ANS-Normally, output goes to the screen and input comes from the keyboard I/O redirection - ANS-Redirect the input and output of commands to and from files. What are abbreviations for standard input, standard output, and standard error? - ANS- stdin, stdout, and stderr. Operator - ANS-A character that represents an action.

  • ANS-An operator that redirects standard output from the screen to a file. ls -l /usr/bin> ls-output.txt - ANS-Redirect the results of the ls -l /usr/bin command to ls- output.txt.
  • ANS-An operator that appends redirected output to a file instead of overwriting the file. ls -l /boot/grub>> ls-output.txt - ANS-Append redirected output of the ls -l /boot/grub command to ls-output.txt. File descriptor - ANS-An abstract indicator used to access a file or other input/output resource, such as a pipe or network connection. What are the file descriptors for the standard input, output, and error file streams? - ANS-0, 1, and 2 respectively. ls -l /bin/usr 2> ls-error.txt - ANS-Redirects error of the ls -l /bin/usr command to ls- error.txt. ls -l /bin/usr &> ls-output.txt - ANS-Redirects output and error of the ls -l /bin/usr command to ls-output.txt. CTRL-D on stdin - ANS-Reach end-of-file (EOF). < - ANS-An operator that changes the source of stdin from the keyboard to a file. cat < lazy_dog.txt - ANS-Input the text of lazy_dog.txt into the cat command which outputs the text on the screen.

ls -l /bin/usr 2> /dev/null - ANS-Dispose of the error message of the ls -l /bin/usr command. cat - ANS-Concatenate (join) files. Read one or more files and copies them to standard output. Synopsis of cat - ANS-cat [OPTION]... [FILE]... cat ls-output.txt - ANS-Display the contents of ls-output.txt. cat movie.mpeg.0* > movie.mpeg - ANS-Join mpeg files movie.mpeg.001, movie.mpeg.002, movie.mpeg.003, ... into movie.mpeg. | (pipe operator) - ANS-Pipe the stdout of one command into the stdin of another. command1 | command2 - ANS-Pipe the stdout of command1 into the stdin of command2. ls -l /usr/bin | less - ANS-Pipe the stdout of the ls -l /usr/bin command into the stdin of the less program. Filter - ANS-Takes inputs, changes it somehow, then outputs it. command1 | filter | command2 - ANS-Filter takes the input from command1, changes it, then outputs it. The output is the input for command2 which outputs even more results. Filter: sort - ANS-Sort lines of text files. Synopsis of sort - ANS-sort [OPTION]... [FILE]... sort [OPTION]... --files0-from=F ls /bin /usr/bin | sort | less - ANS-Creates a combined list of all the executable programs in /bin and /usr/bin, put them in sorted order, and then view the list with less. Filter: uniq - ANS-Omit duplicated lines. Synopsis of uniq - ANS-uniq [OPTION]... [INPUT [OUTPUT]] uniq -d - ANS-Report duplicated lines. ls /bin /usr/bin | sort | uniq | less - ANS-Creates a combined list of all the executable programs in /bin and /usr/bin, put them in sorted order, removes duplicated lines, and then view the list with less. wc - ANS-Print line, word, and byte counts.

echo * - ANS-Lists the contents of a directory (like ls) without coloring scheme. Pathname expansion - ANS-The mechanism by which wildcards work. echo s - ANS-List the contents of a directory ending with s. echo [[:upper:]] - ANS-List the contents of a directory starting with an uppercase letter. echo /usr//share - ANS-List directories which have the /usr//share pattern such as /usr/local/share. echo ~username - ANS-Displays the name of the home directory of username. Arithmetic expansion - ANS-Use the form $((expression)) to perform mathematical operations. Only supports integers. echo $((2+2)) - ANS-Prints 4. Operator: + - ANS-Addition Operator: - - ANS-Subtraction Operator: * - ANS-Multiplication Operator: / - ANS-Division (results are integers, regardless if remainders exist). Operator: % - ANS-Modulo (remainder). Operator: ** - ANS-Exponentiation. echo $(((5**2)) * 3)) - ANS-Prints 75. echo Five divided by two equals $((5/2)) - ANS-Print Five divided by two equals 2 (ignoring remainder). echo with $((5%2)) left over. - ANS-Print with 1 left over. Brace expansion - ANS-Used to create multiple text strings from a pattern containing braces. It may contain either a comma-separated list of strings or a range of integers or single characters. echo Number_{1..3} - ANS-Prints Number_1, Number_2, Number_ echo {Z..X} - ANS-Prints Z Y X.

echo a{A{1,2},B{3,4}}b - ANS-aA1b, aA2b, aB3b, aB4b mkdir {2009..2010}-0{1..3} - ANS-Prints directories 2009-01, 2009-02, 2009-03, 2010- 01,2010-02, 2010-03. Parameter Expansion - ANS-Used to work with variables. echo $USER - ANS-Prints the current username. printenv - ANS-Prints a list of all available variables. Synopsis of printenv - ANS-printenv [OPTION]... [VARIABLE]... Command substitution - ANS-Allows the use of the output of a commands as an expansion. echo $(ls) - ANS-Prints the output of the ls command Delimiter - ANS-One or more characters that separates text strings such as unquoted spaces, tabs, and newlines. Text enclosed in double quotes - ANS-All special characters are treated as ordinary characters except $ (dollar sign), \ (blackslash), and ` (back tick). Combines several arguments into one argument. echo this is a test - ANS-Prints this is a test. echo "this is a test" - ANS-Print this is a test (with the spaces). ls -l two words.txt - ANS-Not a valid command due to the space in the filename. ls -l "two words.txt" - ANS-Displays the long list format of two words.txt. echo $(cal) - ANS-Displays the calendar with each text string separated echo "$(cal)" - ANS-Displays the calendar formatted correctly (with delimiters) w/o highlighting the current date. Text enclosed in single quotes - ANS-Suppresses all special characters. echo '$USER $((2+2)) $(cal)' - ANS-Print $USER $((2+2)) $(cal). Escaping character - ANS-Invokes an alternative interpretation on subsequent characters in a character sequence such as \ (backlash). ls -l two\ words.txt - ANS-Displays the long list format of two words.txt.

Text Editing: ALT-T - ANS-Transpose the word at the cursor location with the one preceding it. Text Editing: ALT-L - ANS-Convert the characters from the cursor location to the end of the word to lowercase. Text Editing: ALT-U - ANS-Convert the characters from the cursor location to the end of the word to uppercase. Cut and Paste (Kill and Yank) Text: CTRL-K - ANS-Kill text from the cursor location to the end of the line. Cut and Paste (Kill and Yank) Text: CTRL-U - ANS-Kill text from the cursor location to the end of the current word. Cut and Paste (Kill and Yank) Text: ALT-D - ANS-Kill text from the cursor location to the end of the current word. Cut and Paste (Kill and Yank) Text: ALT-L - ANS-Kill text from the cursor location to the beginning of the current word. If the cursor is at the beginning of a word, kill the previous word. Cut and Paste (Kill and Yank) Text: CTRL-Y - ANS-Yank text from the kill-ring (buffer) and insert it at the cursor location. TAB - ANS-Autocompletes an (unique) pathname, variable, username, command, or hostname. TAB-TAB - ANS-Display a list of possible completions. .bash_history - ANS-Contains a list of previously used commands. history | grep /usr/bin - ANS-Displays previous commands used to list /usr/bin. !# - ANS-Expands !# into the contents of the !#th line in the history list. History: CTRL-P - ANS-Move to the previous history entry. Same action as the up arrow. History: CTRL-N - ANS-Move to the next history entry. Same action as the down arrow. History: ALT-< - ANS-Move to the beginning (top) of the history list.

History: CTRL-R - ANS-Reverse incremental search. Searches incrementally from the current command line up the history list. History: ALT-P - ANS-Reverse search, non-incremental. With this key, type the search string and press ENTER before the search is performed. History: ALT-N - ANS-Forward search, non-incremental. History: CTRL-O - ANS-Execute the current item in the history list and advance to the next one. History Expansion: !! - ANS-Repeat the last command. It is the same as pressing the up arrow and ENTER. History Expansion: !# - ANS-Repeat history list item number. History Expansion: !string - ANS-Repeat last history list item starting with string. History Expansion: !?string - ANS-Repeat last history list item containing string. script - ANS-Records an entire shell session and store it in a file Synopsis of script - ANS-script [options] [file] Access rights to files are defined in terms of read, write, and execution access for what three types of people? - ANS-The file's owner, file's group owner, and everybody else id - ANS-Display user identity. Synopsis of id - ANS-id [OPTION]... [USER] chmod - ANS-Change a file's mode. Can only be used by the file's owner or superuser. Synopsis of chmod - ANS-chmod [-R] mode file ... umask - ANS-Set the default file permissions. Synopsis of umask - ANS-umask [-S] [mask] su - ANS-Run a shell as another user. Synopsis of su - ANS-su [options] [username] sudo - ANS-Execute a command as another user. Synopsis of sudo - ANS-sudo command

lrwxrwxrwx - ANS-A symbolic link with dummy values. The real permissions are kept with the actual file pointed to by the symbolic link. drwxrwx--- - ANS-A directory. The owner and the members of the owner group may enter the directory and create, rename, and remove files within the directory. Octal File Mode: 0 - ANS---- Octal File Mode: 1 - ANS---x Octal File Mode: 2 - ANS--w- Octal File Mode: 3 - ANS--wx Octal File Mode: 4 - ANS-r-- Octal File Mode: 5 - ANS-r-x Octal File Mode: 6 - ANS-rw- Octal File Mode: 7 - ANS-rwx chmod 777 foo.txt - ANS-Permissions set for foo.txt: -rwxrwxrwx chmod -u - ANS-Short for user but means the file or directory owner. chmod -g - ANS-Group owner. chmod -o - ANS-Short for others but means world. chmod -a - ANS-Short for all; the combination of u, g, and o. chmod u+rw - ANS-Add read and write permission for the owner. chmod u-x - ANS-Remove execute permission from the owner. +x - ANS-Add execute permission for the owner, group, and world. Same as a+x. go=rw - ANS-Set the group owner and anyone besides the owner to have read and write permission. If either the group or world previously had execute permissions, remove them. u+x, go=rw - ANS-Add execute permission for the owner and set the permissions for the group and others to read and execute. umask 0000

foo.txt - ANS-Permissions set for foo.txt: -rw-rw-rw- su -l user - ANS-The resulting shell session is a login session for the specified user (i.e. the user's environment is loaded and the working directory is changed to the user's home directory.) sudo su - ANS-Gain access to superuser privileges chown [owner] [[:group]] file... - ANS-Changes a file' s owner to owner and group owner to group chown bob:admins foo.txt - ANS-Changes the file's owner to bob and group owner to admins.

chown bob: foo.txt - ANS-Changes the file's owner to bob and group owner to the login group of user bob. Multitasking - ANS-Rapidly switching from one executing program to another. Processes - ANS-How Linux organizes the different programs waiting for their turn at the CPU. When a system starts up, the kernel initiates a few of its own activities and launches a program called _____ (parent process) which runs shell scripts (child process) which start all system _____. - ANS-init, services Daemon programs - ANS-Services/programs that run in the background w/o an user interface. Name three reasons to launch a graphical program from the command line - ANS-1. Might not be listed on the window's manager's menu.

  1. See error messages.
  2. Use cli options ps - ANS-Report a snapshot of current processes Synopsis of ps - ANS-ps [options] top - ANS-Display tasks. jobs. - ANS-List active jobs. Synopsis of jobs - ANS-jobs [options] [JOBSPEC] bg - ANS-Place a job in the background (immune from keyboard input and termination.