GNU and Unix commands
GNU and Unix commands is the heaviest objective on the 101 paper. It covers the shell itself, text processing, file management, redirection and pipes, process control, priorities, regular expressions and vi. Objective 103 of LPIC-1 Exam 101-500, worth 43.33% of the exam.
- Share of the exam
- 43.33%
- Questions in a real sitting
- roughly 26 of 60
- Questions in this bank
- 130
- Signed for by a person
- 0
- Machine-checked only
- 130
Partly checked. None of the 130 questions here has been read against the cited source by a person. 130 questions have been checked against their cited clause by an automated pass — which is not the same thing, and is not a signature.
Only questions a person has signed for are used in mock exams here. That is the whole difference between the two kinds of checking above.
How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.
What this objective covers
The 130 questions written for this objective cite 8 LPI exam objectives (103.1, 103.2, 103.3, 103.4, 103.5, 103.6, 103.7, 103.8) and 34 manual pages (bash(1), bzip2(1), cp(1), cpio(1), crontab(1), dd(1), env(1), find(1), getpriority(2), glob(7), grep(1), gzip(1), ls(1), man(1), mv(1), nano(1), nice(1), nohup(1), ps(1), regex(7), renice(1), rmdir(1), screen(1), sed(1), signal(7), tar(1), tee(1), top(1), touch(1), uname(1), vi(1p), vim(1), wc(1), xargs(1)).
They break down as 88 single-answer questions, 18 choose-several questions and 24 type-the-answer questions.
What this objective is really about
At more than forty per cent of the paper, this objective decides whether you pass. It is also the most practical: nearly every question is about what a specific command or shell construct does, so the material rewards typing it more than reading it.
Shell, quoting and redirection
Bash reads different startup files depending on the kind of shell. An interactive login shell reads /etc/profile and then the first of ~/.bash_profile, ~/.bash_login and ~/.profile that exists — only the first. An interactive non-login shell, which is what a new terminal window in a desktop session gives you, reads ~/.bashrc. That is why aliases belong in .bashrc and why most .bash_profile files source it.
Single quotes suppress every expansion; double quotes still perform parameter expansion, command substitution and backslash escapes, and only stop word splitting and globbing. Exporting a variable is what makes it part of the environment child processes inherit; without export it stays a shell variable, which is why env shows a smaller list than set.
Redirection is about file descriptors: 0 stdin, 1 stdout, 2 stderr. > truncates and >> appends. 2> redirects only errors. n>&m makes descriptor n a duplicate of whatever m points at right now — which is why order matters, and why cmd 2>&1 > file sends errors to the terminal and only stdout to the file, while cmd > file 2>&1 sends both to the file. A here-document, <<, feeds inline text to standard input; <<< is a here-string for a single line.
Text processing and finding files
The filters divide by what they do to a stream. sort orders it (-n numerically, -r reversed, -u deduplicating, -k by field). uniq collapses only adjacent duplicates, which is why sort almost always comes first, and -c counts. cut extracts fields (-d sets the delimiter, which defaults to tab). paste merges lines positionally while join matches on a key field and needs sorted input. tr translates or deletes characters and reads only from standard input. sed substitutes, with the g flag for every match on a line rather than the first. wc counts, nl numbers non-empty lines by default, and tail -n sets how many lines to show from the end.
For finding files, find searches live and precisely: -name is case-sensitive and -iname is not, patterns must be quoted so the shell does not expand them first, and -print0 paired with xargs -0 is the safe idiom for names containing spaces. locate is a fast database lookup that is only as current as the last updatedb run. which searches PATH and reports the file it would find there — but the shell checks aliases, functions and builtins first, so which is not a reliable answer to "what will actually run". type is, and a question that mentions any of those three is asking for type.
Processes, priorities and regular expressions
kill sends SIGTERM by default, not SIGKILL. Escalate to -9 only when a process has ignored SIGTERM, because SIGKILL gives it no chance to flush data or release locks. SIGHUP is conventionally a reload signal for daemons. killall and pkill signal by name; kill needs a PID; pgrep only reports. To survive a logout, use nohup, disown, or a screen or tmux session — nice does nothing for this.
Nice values run from -20, most favourable, through 0 to 19, least favourable, and the direction is counterintuitive: a higher number means lower priority. An unprivileged user may only raise their own processes' nice value, never lower it back. nice starts a new command with an adjustment; renice changes one that already exists.
For regular expressions, the split to learn is basic versus extended. Both treat . * [ ] ^ $ as metacharacters. In a basic expression the characters + ? { } ( ) | need a backslash to take on their special meaning; in an extended expression (grep -E) they are special as typed. grep -F disables regular expressions entirely and treats the pattern as fixed text, which is the answer whenever a question worries about dots matching any character.
vi, and why it is examined at all
vi opens in command mode, which is why typing text at first appears to do strange things. i, a and o all enter insert mode and differ only in where the cursor lands; Esc returns to command mode. dd cuts a line, yy copies one, p pastes. To leave: :w writes, :q quits and refuses if the buffer is modified, :q! discards, and :wq writes then quits. The reason vi is examined at all is that a vi-compatible editor is effectively guaranteed to exist on any Unix-like system, including rescue images where nano is not installed.
Lessons in this objective
The objective cut into the pieces the blueprint declares. Each one has the material written out and the questions that test it.
- Working on the command line
- Filtering text streams
- Basic file management
- Streams, pipes and redirection
- Creating, monitoring and killing processes
- Process execution priorities
- Searching text with regular expressions
- Editing files from the terminal
Drill this objective
The trainer can run a short practice set drawn from this objective alone, which is what the weight column above is for: revise the heavy objectives first.
Practise GNU and Unix commands
Questions on this objective (page 1 of 7)
- A user starts a new terminal window in a running graphical desktop session, which launches bash as an interactive shell that is NOT a login shell. Which file in the user's home directory does bash read in that case? machine-checked
- In bash, which history expansion re-runs the entire previous command line? machine-checked
- Which bash command prints the literal five characters $USER instead of the current user name? machine-checked
- You want /opt/bin searched for executables, after all the directories already in PATH, in the current bash session and in every command started from it. Which command does that? machine-checked
- There is a passwd manual page in section 1 (the command) and another in section 5 (the /etc/passwd file format). Which command opens the section 5 page? machine-checked
- Select the TWO true statements about shell variables and the environment in bash. machine-checked
- Type the single command that prints the absolute path of the shell's current working directory. machine-checked
- A file contains one plain integer per line. Sorting it with plain `sort` produces the order 1, 10, 2, 20, 3. Which option makes sort order the numbers by value? machine-checked
- Which command reads standard input and writes it out with every lowercase letter converted to uppercase? machine-checked
- A text file contains several blank lines. Which command numbers only the non-empty lines by default? machine-checked
- Two files each contain 100 lines. You want line 1 of the first file next to line 1 of the second, line 2 next to line 2, and so on, separated by a tab. Which command does this? machine-checked
- In config.txt some lines contain the word `foo` more than once. Which command prints the file with EVERY occurrence on every line replaced by `bar`, leaving the file itself unchanged? machine-checked
- Select the TWO true statements about the uniq command. machine-checked
- Type the complete command that displays the last 20 lines of the file /var/log/syslog. Pass the file as an argument, not through a redirect. machine-checked
- Type the complete command that reports ONLY the number of lines in the file report.txt, passing the file as an argument. machine-checked
- The file /etc/passwd has colon-separated fields. Type the complete command that prints only the third field (the UID) of every line, using cut and passing the file as an argument. machine-checked
- Which command finds files under /data whose names end in .txt, .TXT or .Txt in a single search? machine-checked
- The directory /srv/old still contains files and subdirectories. Which command removes it together with everything inside it? machine-checked
- You have been handed backup.tar and want to see what it contains before unpacking anything. Which command lists the archive's contents without extracting it? machine-checked
- A downloaded file is called `data` with no extension. Which command inspects its content and reports what kind of file it is? machine-checked
Practise GNU and Unix commands
The other objectives in LPIC-1 Exam 101-500
- 101. System architecture — 13.33% of the exam
- 102. Linux installation and package management — 18.33% of the exam
- 104. Devices, Linux filesystems, filesystem hierarchy standard — 25% of the exam