Unit 2: System Utilities and Basic Commands - Subjective Questions
CSE105 — Creative Engineering Workshop • Practice Questions with Detailed Answers
20 questions
Explain the general structure of a Linux command. Describe each component with a suitable example.
A Linux command follows a well-defined syntax that the shell parses before execution.
General Syntax:
command [options] [arguments]
- Command: The name of the program or utility to be executed (e.g.,
ls,cat,date). - Options (Flags/Switches): Modify the behaviour of the command. They usually begin with a hyphen
-(short form) or double hyphen--(long form). Example:-l,--all. - Arguments: The objects or data on which the command operates, such as filenames, directories, or text.
Example:
ls -l /home/user
ls→ command-l→ option (long listing format)/home/user→ argument (directory to list)
Key points:
- Commands are case-sensitive in Linux.
- Multiple options can be combined:
ls -la. - White space separates the command, options, and arguments.
- The shell interprets and passes these tokens to the program.
Describe the cal command. Explain its important options with examples and outputs.
The cal command displays a calendar in the terminal.
Syntax:
cal [options] [[month] year]
Common usages:
cal→ Displays the calendar of the current month.cal 2026→ Displays the calendar for the entire year 2026.cal 9 2026→ Displays September 2026.cal -3→ Displays previous, current, and next month.cal -y→ Displays the calendar for the whole current year.cal -j→ Displays the Julian calendar (day of the year, 1–366).
Example:
$ cal 9 2026
September 2026
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Key points:
- The current date is often highlighted.
- Useful for quick reference without a GUI.
- Month value ranges from 1 to 12.
Explain the date command in detail. How can date be displayed in custom formats using format specifiers?
The date command displays or sets the system date and time.
Syntax:
date [options] [+format]
Basic usage:
date→ Shows current date and time, e.g.Fri Sep 25 22:26:57 UTC 2026.
Format Specifiers (prefixed with +):
%d→ Day of month (01–31)%m→ Month number (01–12)%Y→ Four-digit year%y→ Two-digit year%H→ Hour (00–23)%M→ Minute (00–59)%S→ Second (00–59)%A→ Full weekday name%B→ Full month name%j→ Day of the year%T→ Time in HH:MM:SS
Examples:
$ date +"%d-%m-%Y"
25-09-2026
$ date +"%A, %B %d"
Friday, September 25
Setting the date (requires superuser):
sudo date -s "2026-09-25 10:00:00"
Key points:
- Only root can change the system date.
- Format strings allow flexible output for scripts and logs.
What is the purpose of the echo command? Explain its escape sequences and important options.
The echo command displays a line of text or the value of a variable on the standard output.
Syntax:
echo [options] [string]
Common Options:
-n→ Does not output the trailing newline.-e→ Enables interpretation of backslash escape sequences.-E→ Disables escape sequence interpretation (default).
Escape Sequences (used with -e):
\n→ New line\t→ Horizontal tab\\→ Backslash\a→ Alert (bell)\b→ Backspace\c→ Suppress trailing newline
Examples:
$ echo "Hello World"
Hello World
$ echo -e "Name:\tKiro\nRole:\tAI"
Name: Kiro
Role: AI
$ echo -n "No newline"
Displaying variables:
$ name="Linux"
$ echo "Value is $name"
Value is Linux
Key points:
- Widely used in shell scripts for messages and debugging.
- Behaviour of
-emay differ between shells.
Distinguish between the echo and printf commands. Explain why printf is preferred for formatted output.
Both echo and printf send output to the terminal, but they differ in flexibility and formatting control.
| Feature | echo |
printf |
|---|---|---|
| Purpose | Simple text display | Formatted output |
| Newline | Adds newline automatically | Does not add newline automatically |
| Format specifiers | Not supported | Supports %s, %d, %f, etc. |
| Portability | Behaviour varies across shells | Consistent, C-like behaviour |
| Escape sequences | Needs -e option |
Interprets by default |
printf Syntax:
printf "format" [arguments]
Format Specifiers:
%s→ String%d→ Integer%f→ Floating point number%c→ Character
Examples:
$ printf "Name: %s, Age: %d\n" "Kiro" 5
Name: Kiro, Age: 5
$ printf "%.2f\n" 3.14159
3.14
Why printf is preferred:
- Precise control over width, precision, and alignment.
- Consistent, predictable behaviour across systems.
- Ideal for generating tabular or formatted reports in scripts.
Explain the bc command as a command-line calculator. Demonstrate arithmetic operations, scale, and use in scripts.
The bc (Basic Calculator) command is an arbitrary-precision calculator language that supports interactive and scripted calculations, including floating-point arithmetic.
Interactive Mode:
$ bc
5 + 3
8
quit
Setting precision with scale:
- The
scalevariable controls the number of decimal places.
$ bc
scale=2
10 / 3
3.33
Using with a pipe (non-interactive):
$ echo "scale=4; 22/7" | bc
3.1428
Mathematical library (-l option):
Enables standard math functions with default scale 20.
$ echo "sqrt(2)" | bc -l
1.41421356237309504880
Operators supported:
- Arithmetic:
+,-,*,/,%,^ - Relational and logical operators
Example in a script:
result=$(echo "scale=2; 15.5 * 2" | bc)
echo "Result = $result"
Key points:
- Unlike
expr,bchandles floating-point numbers. - Supports variables, loops, and functions.
Explain the expr command with examples. What are its limitations compared to bc?
The expr command evaluates expressions and prints the result. It is mainly used for integer arithmetic and string operations in shell scripts.
Syntax:
expr expression
Arithmetic Examples:
$ expr 5 + 3
8
$ expr 10 - 4
6
$ expr 6 * 2
12
$ expr 20 / 3
6
Note: The multiplication operator
*must be escaped as\*to prevent shell globbing.
String Operations:
$ expr length "Linux"
5
$ expr substr "Creative" 1 4
Crea
Limitations compared to bc:
- Only integer arithmetic — no floating-point support.
- Requires careful escaping of operators like
*. - Every operand and operator must be space-separated.
- Less powerful;
bcsupports precision, functions, and loops.
Key points:
- Useful for simple counters and integer math in scripts.
- Returns exit status based on the result value.
Describe the script command. How is it used to record a terminal session? Explain with an example.
The script command makes a typescript (a recording) of everything displayed on the terminal, including commands typed and their output. It is useful for documentation, tutorials, and audit trails.
Syntax:
script [options] [filename]
- If no filename is given, output is saved in a file named
typescriptby default.
Workflow:
$ script session.log
Script started, file is session.log
$ date
$ whoami
$ exit
Script done, file is session.log
- Type
exitor pressCtrl+Dto stop recording.
Useful Options:
-a→ Append to an existing file instead of overwriting.-t→ Output timing data.-c command→ Run a single command and record it.
Example of appending:
script -a session.log
Key points:
- Captures the entire interactive session.
- The recorded file can be viewed with
cator a text editor. - Helpful for reproducing steps or teaching.
Explain the passwd command. Describe its role in user authentication and important options.
The passwd command is used to change a user's password and manage password-related properties.
Syntax:
passwd [options] [username]
Basic usage:
passwd→ Changes the password of the current user. It prompts for the current password, then the new password twice.sudo passwd username→ Root changes another user's password (no current password needed).
Important Options:
-l→ Locks the user account.-u→ Unlocks the account.-d→ Deletes the password (makes it empty).-e→ Expires the password, forcing change at next login.-S→ Displays password status information.
Example:
$ passwd
Changing password for user.
Current password:
New password:
Retype new password:
passwd: password updated successfully
Key points:
- Passwords are stored in encrypted form in
/etc/shadow. - A normal user can change only their own password.
- Only root can modify other users' passwords or lock accounts.
Distinguish between the who, whoami, and w commands. Explain the output fields of who.
These commands provide information about users logged into the system.
| Command | Purpose |
|---|---|
who |
Lists all users currently logged in |
whoami |
Displays the effective username of the current user |
w |
Shows logged-in users and what they are doing |
who command output fields:
$ who
user1 tty1 2026-09-25 09:15
user2 pts/0 2026-09-25 10:02 (192.168.1.5)
- Username → Name of the logged-in user.
- Terminal (tty/pts) → The terminal line used.
- Login date & time → When the session started.
- Host/IP (in parentheses) → Remote host for network logins.
whoami example:
$ whoami
user1
- Equivalent to
id -un.
Key points:
whoreports all users;whoamireports only you.- Useful options for
who:-H(headers),-b(last boot time),-r(run level).
Explain the uname command and its various options. What information does uname -a provide?
The uname (Unix name) command prints system information about the operating system and hardware.
Syntax:
uname [options]
Options:
-s→ Kernel name (default output), e.g.Linux.-n→ Network node hostname.-r→ Kernel release version.-v→ Kernel version (build info).-m→ Machine hardware name (architecture), e.g.x86_64.-p→ Processor type.-i→ Hardware platform.-o→ Operating system name.-a→ All available information combined.
uname -a example:
$ uname -a
Linux myhost 5.15.0-73-generic #80-Ubuntu SMP x86_64 GNU/Linux
The output includes, in order:
- Kernel name (
Linux) - Hostname (
myhost) - Kernel release (
5.15.0-73-generic) - Kernel version (build date/details)
- Machine architecture (
x86_64) - Operating system (
GNU/Linux)
Key points:
- Quick way to identify kernel and architecture.
- Frequently used in scripts to detect the platform.
Explain the uptime command in detail. Interpret the meaning of the load average values it displays.
The uptime command shows how long the system has been running along with current load information.
Syntax:
uptime [options]
Sample Output:
$ uptime
22:26:57 up 5 days, 3:14, 2 users, load average: 0.15, 0.20, 0.10
Fields explained:
- Current time →
22:26:57 - Up time → How long the system has been running (
5 days, 3:14). - Number of users → Users currently logged in (
2 users). - Load average → Three numbers:
0.15, 0.20, 0.10.
Load Average interpretation:
- The three values represent the average system load over the last 1, 5, and 15 minutes.
- Load is the average number of processes waiting for or using the CPU.
- On a single-core system:
1.00means the CPU is fully utilised.< 1.00means idle capacity.> 1.00means processes are waiting (overloaded).
- For an -core system, a load of indicates full utilisation.
Options:
-p→ Pretty format of uptime only.-s→ Shows the time since the system booted.
Key points:
- Useful for monitoring system health and performance trends.
What is a terminal in Linux? Explain the tty command and the difference between tty and pts.
A terminal is an interface that allows users to interact with the operating system by entering commands and viewing text output.
tty command:
The tty command prints the file name of the terminal connected to standard input.
Syntax:
tty [options]
Example:
$ tty
/dev/pts/0
Options:
-s→ Silent mode; prints nothing, only sets exit status.
Difference between tty and pts:
| Aspect | tty (virtual console) |
pts (pseudo-terminal) |
|---|---|---|
| Meaning | Physical/virtual console terminal | Pseudo terminal slave |
| Path | /dev/tty1, /dev/tty2 |
/dev/pts/0, /dev/pts/1 |
| Usage | Direct console login (Ctrl+Alt+F1) | Remote logins (SSH), terminal emulators |
| Origin | Real hardware terminals historically | Software-created terminals |
Key points:
ttyhelps identify the current terminal device.- If input is not a terminal, it prints
not a tty. - Useful in scripts to check whether they are running interactively.
Explain the stty command. How is it used to change and view terminal settings? Give examples.
The stty (set terminal) command is used to display and change terminal line settings, such as input/output behaviour and control characters.
Syntax:
stty [options] [setting]
Viewing settings:
stty→ Shows basic terminal settings.stty -a→ Shows all settings in detail.
$ stty -a
speed 38400 baud; rows 24; columns 80;
intr = ^C; erase = ^?; kill = ^U; ...
Changing settings — examples:
-
Disable echo (useful for password input):
stty -echo
-
Enable echo again:
stty echo
-
Change the interrupt key:
stty intr ^X
-
Reset the terminal to sane defaults:
stty sane
Common control settings:
erase→ Character to delete previous character.kill→ Character to erase entire line.intr→ Interrupt character (usuallyCtrl+C).
Key points:
- Controls how the terminal handles input and special keys.
stty -echois commonly used in scripts to hide sensitive input.
Explain the man command and describe how to navigate a manual page. What are the different sections of the man pages?
The man (manual) command displays the reference manual pages for commands, system calls, files, and more. It is the primary source of built-in documentation in Linux.
Syntax:
man [section] command
Example:
$ man ls
Manual Page Navigation (uses the less pager):
- Spacebar /
f→ Move forward one screen. b→ Move back one screen.- Arrow keys → Scroll line by line.
/pattern→ Search forward for a pattern.?pattern→ Search backward.n/N→ Next / previous search match.g/G→ Go to beginning / end.q→ Quit the man page.
Manual Sections:
- Section 1 → User commands (executable programs).
- Section 2 → System calls.
- Section 3 → Library functions.
- Section 4 → Special files (devices in
/dev). - Section 5 → File formats and conventions.
- Section 6 → Games.
- Section 7 → Miscellaneous (macros, conventions).
- Section 8 → System administration commands.
Example of specifying a section:
man 5 passwd # shows the /etc/passwd file format
Key points:
- Use
man -k keyword(apropos) to search by keyword. - Structured sections: NAME, SYNOPSIS, DESCRIPTION, OPTIONS, EXAMPLES, SEE ALSO.
Compare internal (built-in) commands and external commands in Linux. How can you determine the type of a command?
Linux commands can be broadly classified as internal (built-in) and external commands.
| Aspect | Internal Commands | External Commands |
|---|---|---|
| Definition | Built into the shell itself | Separate executable programs on disk |
| Location | Part of the shell (no separate file) | Stored in directories like /bin, /usr/bin |
| Execution speed | Faster (no disk access) | Slightly slower (loaded from disk) |
| Examples | cd, echo, pwd, exit |
ls, cat, date, cal |
| Process | Runs within the shell process | Runs as a new child process |
Determining the type of a command:
The type command reveals whether a command is built-in or external.
$ type cd
cd is a shell builtin
$ type ls
ls is /usr/bin/ls
Other helpful commands:
which command→ Shows the path of an external command.command -V command→ Similar totype.
Key points:
- Some commands (like
echo) exist both as built-ins and external programs. - The shell searches built-ins first, then the directories in the
PATHvariable.
Write short notes with examples on any four system information commands: date, uname, uptime, and whoami.
These commands quickly report useful details about the system and user environment.
1. date
- Displays or sets the current date and time.
- Supports custom formats.
$ date +"%d-%m-%Y"
25-09-2026
2. uname
- Prints operating system and kernel information.
uname -ashows all details.
$ uname -r
5.15.0-73-generic
3. uptime
- Shows how long the system has run, number of users, and load averages.
$ uptime
22:26:57 up 5 days, 2 users, load average: 0.15, 0.20, 0.10
4. whoami
- Displays the effective username of the current user.
$ whoami
student
Summary Table:
| Command | Information Provided |
|---|---|
date |
Current date & time |
uname |
OS / kernel details |
uptime |
Running time & load |
whoami |
Current username |
Key points:
- These commands are widely used in shell scripts and system monitoring.
A shell script needs to perform both integer and floating-point calculations. Explain and demonstrate how expr and bc can be combined, and write example calculations for area of a circle and simple interest.
In shell scripts, expr handles simple integer math while bc handles floating-point math. Combining them lets scripts perform a variety of calculations.
Using expr for integers:
$ count=$(expr 5 + 10)
$ echo $count
15
Using bc for floating-point:
$ result=$(echo "scale=2; 22/7" | bc)
$ echo $result
3.14
Example 1 — Area of a circle :
r=5
area=$(echo "scale=2; 3.14159 $r $r" | bc)
echo "Area = $area"
For :
Example 2 — Simple Interest :
P=1000
R=5
T=2
SI=P $R $T)/100" | bc)
echo "Simple Interest = $SI"
For , , :
Key points:
- Use
exprfor counters and integer indices. - Use
bcwhenever decimals or precision are required. - The
scalevariable inbccontrols decimal places.
Explain in detail the concept of options and arguments in command structure, the difference between short and long options, and how combining options works. Support your answer with multiple examples.
Commands in Linux gain flexibility through options and arguments that follow the command name.
1. Arguments:
Arguments are the data or objects on which a command acts, such as filenames or text strings.
$ cat file1.txt file2.txt
Here file1.txt and file2.txt are arguments.
2. Options (Flags):
Options modify the behaviour of a command.
-
Short options: Single letter preceded by a single hyphen
-.$ ls -l
-
Long options: Full word preceded by a double hyphen
--.$ ls --all
Difference between short and long options:
| Aspect | Short Option | Long Option |
|---|---|---|
| Prefix | Single - |
Double -- |
| Form | One letter (-a) |
Descriptive word (--all) |
| Readability | Compact | More readable |
| Combining | Can be combined | Usually written separately |
3. Combining options:
Multiple short options can be merged after a single hyphen.
$ ls -l -a -h # separate
$ ls -lah # combined (equivalent)
Options with values:
$ sort -k 2 file.txt # short with argument
$ head --lines=5 file.txt # long with =value
4. Order and precedence:
- Options generally come before arguments.
- Some commands allow options anywhere; others require a strict order.
Key points:
- Commands are case-sensitive.
- The
--marker signals the end of options, so filenames beginning with-can follow. - Understanding options and arguments is essential for reading man pages and writing scripts.
Describe how the man command, apropos, whatis, and --help work together as sources of command documentation. Compare them and give examples of when to use each.
Linux provides several complementary tools for learning about commands. Together they help a user discover, understand, and quickly reference commands.
1. man — full manual pages:
Provides complete, detailed documentation for a command.
$ man ls
- Structured into NAME, SYNOPSIS, DESCRIPTION, OPTIONS, etc.
- Best when you need in-depth information.
2. whatis — one-line description:
Displays a brief, one-line summary of a command.
$ whatis ls
ls (1) - list directory contents
- Best for a quick reminder of what a command does.
3. apropos — keyword search:
Searches man page descriptions for a keyword (same as man -k).
$ apropos copy
cp (1) - copy files and directories
scp (1) - secure copy
- Best when you don't know the command name but know the task.
4. --help option — quick syntax help:
Most commands support a built-in --help flag.
$ ls --help
- Shows a concise usage summary without opening the pager.
Comparison Table:
| Tool | Detail Level | Best Use |
|---|---|---|
man |
Detailed | Complete reference |
whatis |
One line | Quick definition |
apropos |
List of matches | Find a command by keyword |
--help |
Short summary | Quick syntax check |
Key points:
whatisandaproposrely on a database updated bymandb.- Use
aproposto discover,whatisto recall,--helpfor quick syntax, andmanfor depth.
Explain the general structure of a Linux command. Describe each component with a suitable example.
A Linux command follows a well-defined syntax that the shell parses before execution.
General Syntax:
command [options] [arguments]
- Command: The name of the program or utility to be executed (e.g.,
ls,cat,date). - Options (Flags/Switches): Modify the behaviour of the command. They usually begin with a hyphen
-(short form) or double hyphen--(long form). Example:-l,--all. - Arguments: The objects or data on which the command operates, such as filenames, directories, or text.
Example:
ls -l /home/user
ls→ command-l→ option (long listing format)/home/user→ argument (directory to list)
Key points:
- Commands are case-sensitive in Linux.
- Multiple options can be combined:
ls -la. - White space separates the command, options, and arguments.
- The shell interprets and passes these tokens to the program.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →