This chapter covers essential Linux command-line commands that you must know for the CompTIA A+ 220-1102 exam. Linux commands are a key part of the Operating Systems domain (Objective 1.6), and while the exam does not require deep Linux administration, you will see questions that test your ability to navigate the file system, manage files, view processes, and understand permissions. Expect 3–5% of exam questions to touch on Linux commands, often in the context of troubleshooting or basic system management. This chapter provides a focused, exam-relevant guide to the commands most likely to appear, with clear explanations and practical examples.
Jump to a section
Think of a Linux system as a large library with millions of books (files) and many reading rooms (directories). The librarian (the shell) helps you find books and move them around. When you want to see what's in a room, you use 'ls' — like scanning the shelf list. 'cd' moves you from one reading room to another, like walking through doorways. 'cp' copies a book from one shelf to another, leaving the original in place. 'mv' moves a book to a different shelf, removing it from the original location — like a book being relocated. 'rm' removes a book from the library permanently, so you must be careful. 'mkdir' builds a new reading room (directory), while 'rmdir' removes an empty one. 'touch' creates a new blank book or updates the date on an existing one. 'cat' reads the entire book aloud, while 'less' lets you read page by page. 'grep' is like a search tool that finds specific words across all books. 'chmod' changes the permissions on a book — who can read, write, or execute it. 'ps' shows you who is in the library and what they are doing (processes). 'kill' sends a signal to stop a patron (process) that is misbehaving. 'sudo' lets you act as the head librarian with full access. 'man' is the instruction manual for any command. Each command has options (flags) that modify its behavior, like 'ls -l' for detailed listing or 'rm -r' to remove a directory and its contents recursively. Understanding these commands is like knowing how to navigate the library efficiently — you can find, organize, and manage files and processes quickly.
What is Linux Command Line and Why Does It Exist?
Linux is a Unix-like operating system that relies heavily on a command-line interface (CLI) for system administration. Unlike Windows, which offers a robust graphical interface, Linux's strength lies in its ability to perform complex tasks efficiently through text commands. The CLI is often accessed via a terminal emulator or a virtual console (e.g., TTY). The default shell is usually Bash (Bourne Again SHell), but others like Zsh or Fish exist. The command line allows you to execute programs, manage files, control processes, and configure the system. For the A+ exam, you need to be familiar with basic navigation, file management, process management, and permission commands.
How the Shell Works Internally
When you type a command and press Enter, the shell performs the following steps:
1. Parsing: The shell reads the command line, splits it into tokens (command name, options, arguments), and handles variable expansion, globbing (wildcard expansion), and quote removal.
2. Alias expansion: If the command is an alias (e.g., ll for ls -l), the shell expands it.
3. Path resolution: The shell searches for the executable in the directories listed in the PATH environment variable (e.g., /usr/local/bin, /usr/bin, /bin). If not found, it returns "command not found".
4. Fork and exec: The shell forks a new process (child) and executes the command using the execve() system call. The child process inherits the environment and file descriptors.
5. I/O redirection: If the command includes redirection operators (>, <, |), the shell sets up file descriptors before execution.
6. Execution: The command runs, possibly interacting with the kernel for file operations, process scheduling, etc.
7. Exit status: The command returns an exit code (0 for success, non-zero for error). The shell collects this and may display a prompt again.
Key Commands for File and Directory Navigation
- `pwd` (Print Working Directory): Displays the absolute path of the current directory. Example: pwd outputs /home/user.
- `ls` (List): Lists files and directories. Common options:
- -l : Long format showing permissions, owner, size, modification date.
- -a : Show all files including hidden ones (starting with .).
- -h : Human-readable sizes (e.g., 1K, 234M).
- -R : Recursively list subdirectories.
- -t : Sort by modification time (newest first).
Example: ls -la /home.
- `cd` (Change Directory): Moves to another directory. Special directories:
- . : Current directory.
- .. : Parent directory.
- ~ : Home directory of current user.
- - : Previous directory.
Example: cd /var/log or cd ...
- `mkdir` (Make Directory): Creates a new directory. Use -p to create parent directories as needed. Example: mkdir -p /tmp/a/b/c.
- `rmdir` (Remove Directory): Removes an empty directory. For non-empty directories, use rm -r.
File Management Commands
- `touch`: Creates an empty file or updates the timestamp of an existing file. Example: touch newfile.txt.
- `cp` (Copy): Copies files or directories. Options:
- -r : Recursive copy for directories.
- -i : Interactive (prompt before overwrite).
- -u : Copy only when source is newer than destination.
Example: cp -r /src /dest.
- `mv` (Move): Moves or renames files/directories. Options:
- -i : Interactive prompt.
- -u : Move only when source is newer.
Example: mv oldname.txt newname.txt.
- `rm` (Remove): Deletes files or directories. Use with caution: there is no recycle bin. Options:
- -r : Recursive (for directories).
- -f : Force (no prompt).
- -i : Interactive prompt.
Example: rm -rf /tmp/junk (dangerous: forces removal of everything in /tmp/junk without prompting).
- `cat` (Concatenate): Displays file content. Also used to combine files: cat file1 file2 > combined.
- `less` and `more`: Page through files. less allows backward navigation. Example: less /var/log/syslog.
- `head` and `tail`: Show first or last lines of a file. tail -n 20 shows last 20 lines; tail -f follows a growing file (like logs).
- `grep` (Global Regular Expression Print): Searches for patterns in files. Common options:
- -i : Case-insensitive.
- -r : Recursive.
- -v : Invert match (show lines that do NOT match).
- -c : Count matches.
Example: grep -r "error" /var/log/.
- `find`: Searches for files by name, type, size, etc. Example: find /home -name "*.txt".
- `wc` (Word Count): Counts lines, words, characters. Example: wc -l file.txt gives line count.
- `sort`: Sorts lines alphabetically or numerically. Example: sort -n numbers.txt.
- `uniq`: Removes duplicate adjacent lines (often used with sort).
Wildcards (Globbing)
Wildcards are patterns the shell expands before executing a command:
- * : Matches any sequence of characters (including none). Example: ls *.txt lists all .txt files.
- ? : Matches any single character. Example: ls file?.txt matches file1.txt, fileA.txt, but not file10.txt.
- [abc] : Matches any one of the characters inside. Example: ls file[12].txt matches file1.txt and file2.txt.
- [!abc] : Matches any character NOT in the set.
- {a,b,c} : Brace expansion generates multiple strings. Example: mkdir {dir1,dir2,dir3} creates three directories.
Redirection and Pipes
> : Redirects stdout to a file (overwrites). Example: ls > output.txt.
>> : Appends stdout to a file.
2> : Redirects stderr. Example: command 2> errors.txt.
&> : Redirects both stdout and stderr (Bash 4+).
< : Takes stdin from a file. Example: sort < input.txt.
| : Pipe: stdout of left command becomes stdin of right command. Example: ls -l | grep "txt".
tee : Splits output: writes to file and stdout. Example: ls | tee listing.txt.
Process Management Commands
- `ps` (Process Status): Displays running processes. Common options:
- aux : Shows all processes (a=all users, u=user-oriented format, x=processes without terminal). This is a common exam format.
- -ef : Full listing.
Example: ps aux | grep bash.
- `top`: Real-time view of processes sorted by CPU usage. Press q to quit. htop is an enhanced version (not always installed).
- `kill`: Sends a signal to a process. Common signals:
- SIGTERM (15) : Terminate gracefully (default).
- SIGKILL (9) : Force kill (cannot be caught).
- SIGHUP (1) : Hang up (often reload config).
Example: kill -9 1234 kills process with PID 1234.
- `killall`: Kills processes by name. Example: killall firefox.
- `pkill`: Kills processes by pattern. Example: pkill -f "python script.py".
- `jobs`: Lists background jobs. bg resumes a job in background; fg brings it to foreground.
- `nohup`: Runs a command immune to hangups (continues after logout). Example: nohup longscript.sh &.
Permissions and Ownership
Linux uses a permission system with three categories: owner, group, others. Each has read (r=4), write (w=2), and execute (x=1) permissions. Permissions are displayed as a string like -rwxr-xr-- (first character is file type: - for file, d for directory, l for link).
`chmod` (Change Mode): Changes permissions. Two modes:
Symbolic: u/g/o/a +/-/= r/w/x. Example: chmod u+x script.sh adds execute for user.
Numeric (octal): Three digits (owner, group, other). Example: chmod 755 script.sh sets rwxr-xr-x.
`chown` (Change Owner): Changes file owner and group. Example: chown user:group file.txt.
`umask`: Sets default permission mask for new files. Files default to 666 minus umask; directories default to 777 minus umask. Common umask: 022 gives 644 for files, 755 for directories.
User and Group Management
`whoami`: Displays current username.
`id`: Shows user ID (UID), group ID (GID), and groups.
`adduser` or `useradd`: Creates a new user. useradd is low-level; adduser is interactive (Debian/Ubuntu).
`passwd`: Changes user password.
`su` (Substitute User): Switches to another user (requires password). Example: su - john switches to john's login shell.
`sudo` (Superuser Do): Executes a command as another user (typically root) without needing the target user's password, provided the user is in /etc/sudoers. Example: sudo apt update.
Package Management (Exam Overview)
Linux distributions use package managers. Debian/Ubuntu use apt (Advanced Package Tool). Red Hat/CentOS use yum or dnf. Common commands:
- apt update : Updates package list.
- apt upgrade : Upgrades all packages.
- apt install <package> : Installs a package.
- apt remove <package> : Removes a package.
- yum install <package> : Same on Red Hat.
- rpm -i <package.rpm> : Install an RPM package.
Viewing System Information
`uname -a`: Shows all system information (kernel version, hostname, etc.).
`lsb_release -a`: Shows distribution-specific info (LSB=Linux Standard Base).
`df -h`: Shows disk space usage in human-readable format.
`du -sh`: Shows total disk usage of a directory.
`free -h`: Shows memory usage (RAM and swap).
`uptime`: Shows how long the system has been running.
`dmesg`: Displays kernel ring buffer messages (hardware detection, etc.).
Network Commands (Basic)
`ifconfig`: Displays network interfaces (older, deprecated; use ip addr).
`ip addr`: Shows IP addresses and interface info.
`ping <host>`: Tests connectivity.
`netstat` or `ss`: Shows network connections, routing tables, etc.
`nslookup` or `dig`: DNS queries.
`traceroute` (or tracert on Windows): Traces network path.
Getting Help
`man <command>`: Displays manual page. Use arrow keys to scroll, q to quit.
`<command> --help`: Shows brief usage summary.
`info <command>`: GNU info system (more detailed than man).
Common Exam Scenarios
The 220-1102 exam may present scenarios where you need to:
Navigate to a log directory and view the last few lines of a file: cd /var/log && tail -n 20 syslog.
Find all files owned by a user: find / -user username.
Kill a hung process: ps aux | grep hungapp, then kill -9 PID.
Change permissions to make a script executable: chmod +x script.sh.
Copy a directory recursively: cp -r source dest.
Use grep to find specific error messages: grep "Out of memory" /var/log/syslog.
Use pipes to chain commands: ps aux | grep firefox | grep -v grep.
Security and Best Practices
Avoid using rm -rf / as root (deletes entire system).
Use sudo instead of logging in as root.
Be careful with wildcards: rm * .txt (space before .txt) deletes all files and then tries to delete .txt.
Use -i flag with rm, cp, mv to prevent accidental overwrites.
Always verify command syntax with man before running destructive commands.
Summary of Essential Commands for the Exam
| Command | Purpose | Common Options |
|---------|---------|----------------|
| ls | List directory contents | -l, -a, -h, -R |
| cd | Change directory | (none) |
| pwd | Print working directory | (none) |
| mkdir | Create directory | -p |
| rmdir | Remove empty directory | (none) |
| cp | Copy files/directories | -r, -i, -u |
| mv | Move/rename | -i, -u |
| rm | Remove files/directories | -r, -f, -i |
| touch | Create/update file | (none) |
| cat | Display file content | (none) |
| less | Page through file | (none) |
| head | First lines | -n |
| tail | Last lines | -n, -f |
| grep | Search text | -i, -r, -v, -c |
| find | Search files | -name, -type, -user |
| chmod | Change permissions | numeric or symbolic |
| chown | Change owner | (none) |
| ps | Process status | aux, -ef |
| kill | Send signal | -9, -15 |
| sudo | Execute as superuser | (none) |
| man | Manual pages | (none) |
| apt / yum | Package management | install, update, remove |
These commands form the core of Linux CLI interaction and are the most likely to appear on your A+ exam. Practice them in a Linux virtual machine to build muscle memory.
Navigate to /var/log
First, open a terminal. Use `cd /var/log` to change to the log directory. Verify with `pwd` to confirm. This is a common location for system logs. The `cd` command uses an absolute path starting with `/`. If you are already in a subdirectory, you could use a relative path like `cd ../../var/log` from `/home/user`. Understanding absolute vs relative paths is critical for the exam.
List log files with details
Run `ls -lh` to see all files in the directory with human-readable sizes and permissions. The `-l` option shows permissions, owner, group, size, and modification time. `-h` makes sizes like 1.2K or 34M. Look for files like `syslog`, `auth.log`, or `messages`. Note the file timestamps to identify recent activity. The output shows file types: `-` for file, `d` for directory, `l` for link.
View the last 10 lines of syslog
Use `tail -n 10 syslog` to display the last 10 lines of the syslog file. The `-n` option specifies number of lines. If you want to watch new entries in real time (e.g., during troubleshooting), use `tail -f syslog`. This continuously displays new lines as they are appended. Press Ctrl+C to stop. The `tail` command is essential for log monitoring.
Search for 'error' in all logs
Run `grep -i "error" *` to search for the word "error" (case-insensitive) in all files in the current directory. The `-i` flag makes it case-insensitive. The `*` wildcard matches all files. To search recursively in subdirectories, use `grep -r -i "error" .`. The `grep` command prints matching lines. This is a powerful way to find issues in logs.
Create a backup of syslog
Use `cp syslog syslog.backup` to copy the syslog file to a backup. The `cp` command takes source and destination. To avoid overwriting an existing file, use `cp -i syslog syslog.backup` which prompts before overwriting. If you need to copy directories, use `cp -r sourcedir destdir`. This step demonstrates file management.
Compress the backup using gzip
Run `gzip syslog.backup` to compress the backup file. This creates `syslog.backup.gz`. `gzip` compresses files and adds `.gz` extension. To decompress, use `gunzip syslog.backup.gz`. Alternatively, `bzip2` or `xz` can be used. Compression is important for saving disk space, especially on log files that rotate.
Check disk usage of /var/log
Use `du -sh` to see the total disk usage of the current directory (`/var/log`). The `-s` flag gives a summary, `-h` for human-readable. For more detailed breakdown, use `du -h` or `du -sh *` to see per-file sizes. This helps identify which logs are consuming space. The `df -h` command shows overall disk space.
In a production Linux server environment, system administrators routinely use command-line tools to monitor and maintain systems. For example, a web server running Apache or Nginx generates access logs and error logs in /var/log. When users report slow page loads, an admin might first check the error log: tail -f /var/log/apache2/error.log. If the log shows "Out of memory" errors, the admin can check memory usage with free -h and identify memory-hungry processes with ps aux --sort=-%mem | head. This combination of commands allows rapid diagnosis without a GUI.
Another common scenario is automating backups. An admin may write a script that uses tar to archive a directory, gzip to compress it, and scp to copy it to a remote server. For instance: tar czf backup-$(date +%Y%m%d).tar.gz /var/www/html && scp backup-*.tar.gz backup@remote:/backups/. This uses command substitution ($(...)) to generate a timestamped filename. The script is then scheduled with cron to run daily. Understanding basic commands like tar (archive), cron (scheduling), and scp (secure copy) is essential for such tasks.
A third scenario involves user management. When a new employee joins, an admin creates a user account: sudo useradd -m -s /bin/bash jdoe (creates home directory and sets shell). Then sets a password with sudo passwd jdoe. The admin might also add the user to groups: sudo usermod -aG sudo jdoe (adds to sudo group). To verify, id jdoe shows the user's UID and groups. If the user leaves, the admin locks the account with sudo passwd -l jdoe or deletes with sudo userdel -r jdoe (removes home directory). These commands are critical for access control.
Misconfiguration can lead to security breaches or data loss. For example, a typo in a chmod command like chmod 777 /etc/shadow would make the password file world-readable, compromising all accounts. Using sudo without proper /etc/sudoers configuration can give unintended privileges. Also, forgetting to use -i with rm can accidentally delete important files. Therefore, best practices include always double-checking commands, using -i for destructive operations, and testing scripts in a safe environment first.
For the CompTIA A+ 220-1102 exam, Objective 1.6 ("Given a scenario, use appropriate Linux commands") is specifically tested. The exam expects you to know the purpose and syntax of the most common commands. Here are the critical points:
1. What the exam tests:
- Navigation: cd, ls, pwd
- File management: cp, mv, rm, mkdir, rmdir, touch
- Viewing files: cat, less, more, head, tail
- Searching: grep, find
- Permissions: chmod, chown
- Process management: ps, kill
- Superuser: sudo
- Manual: man
- Package management: apt-get (or apt), yum (or dnf)
- Network: ping, ifconfig/ip, netstat/ss
2. Common wrong answers candidates choose:
- Confusing rmdir with rm -r: rmdir only removes empty directories; rm -r removes non-empty ones. Exam questions may describe a scenario where a directory has files, and the wrong answer is rmdir.
- Using kill without a signal number: The default is SIGTERM (15), but if a process doesn't respond, you need SIGKILL (9). Candidates often forget the -9.
- Mixing up chmod numeric and symbolic: For example, chmod 777 sets rwx for all, but chmod 777 is often used incorrectly for making a file executable (should be chmod +x).
- Thinking sudo is the same as su: sudo runs a single command as root; su switches to root shell. The exam may ask which command to use to run a single admin command.
- Confusing apt with yum: Debian-based vs Red Hat-based. The exam may ask which command to install a package on Ubuntu vs CentOS.
3. Specific numbers and values:
- Permission octal: 755 (rwxr-xr-x), 644 (rw-r--r--), 700 (rwx------).
- Signal numbers: SIGTERM=15, SIGKILL=9, SIGHUP=1.
- Default umask: 022 (files 644, directories 755).
- tail -n 20 shows last 20 lines; head -n 10 shows first 10.
- ps aux format: USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND.
4. Edge cases and exceptions:
- Hidden files (starting with .) are not shown with plain ls; need ls -a.
- rm * does not remove hidden files.
- mv can rename across filesystems (copy + delete), but it's transparent to user.
- cp -r is required for directories; cp without -r fails on directories.
- find uses -name for case-sensitive search; -iname for case-insensitive.
- grep -v inverts match: shows lines that do NOT match.
- sudo -i gives a root shell; sudo -s gives a shell with root privileges (but may not source root's profile).
5. How to eliminate wrong answers:
- Read the scenario carefully: Is the directory empty? Use rmdir. Is there a need to preserve the original? Use cp not mv. Is the command to be run as root? Use sudo. Is the process hung? Use kill -9. Is the file executable? Use chmod +x. By understanding the underlying mechanism (e.g., rmdir only works on empty directories because it calls rmdir() syscall which fails if directory not empty), you can eliminate options that don't match the technical requirement.
Use `pwd` to see your current directory; `cd` to change it; `ls` to list contents with `-l` for details and `-a` for hidden files.
Use `cp -r` to copy directories; `mv` to move/rename; `rm -rf` to delete recursively (use with caution).
Use `cat` for short files, `less` for long files, `head`/`tail` for first/last lines, and `grep` to search patterns within files.
Use `chmod` to change permissions (numeric like 755 or symbolic like u+x); `chown` to change owner.
Use `ps aux` to list all processes; `kill -9 PID` to force-terminate a process.
Use `sudo` to run a single command as root; `su` to switch to a root shell.
Use `man command` to view the manual; `command --help` for a brief summary.
Use `apt` (Debian/Ubuntu) or `yum`/`dnf` (Red Hat/CentOS) for package management.
Use `df -h` for disk space, `du -sh` for directory size, `free -h` for memory usage.
Use `ping` to test connectivity; `ifconfig` or `ip addr` to view network interfaces.
These come up on the exam all the time. Here's how to tell them apart.
cd (Change Directory)
Changes the current working directory to a specified path.
Accepts absolute paths (starting with /) and relative paths (e.g., ..).
With no arguments, `cd` returns to the user's home directory.
`cd -` switches to the previous directory.
Used in scripts to navigate file systems.
pwd (Print Working Directory)
Displays the full absolute path of the current directory.
No arguments; simply outputs the path.
Useful after `cd` to confirm the new location.
Often used in shell prompts or scripts to show context.
Does not change state; only reads information.
cp (Copy)
Creates a duplicate of a file or directory at a new location.
Original file remains unchanged.
Requires `-r` flag to copy directories.
Can copy across different filesystems.
Used for backups and replication.
mv (Move)
Moves or renames a file or directory.
Original file is removed from the source location.
Works on directories without special flags (except across filesystems).
Moving across filesystems is actually a copy+delete, but appears atomic.
Used for reorganization and renaming.
rm (Remove)
Deletes files or directories (with `-r`).
No confirmation by default; use `-i` for interactive.
Can delete non-empty directories with `-rf`.
Permanent deletion; no trash.
Use with extreme caution, especially with wildcards.
rmdir (Remove Directory)
Only removes empty directories.
Fails with an error if directory is not empty.
Safer than `rm -r` for removing empty directories.
Does not require `-r` flag.
Often used in scripts to clean up temporary directories.
ps (Process Status)
Provides a snapshot of current processes.
Common options: `aux` (all users, detailed), `-ef` (full listing).
Output is static; use `grep` to filter.
Can show specific PIDs or users.
Useful for scripting and one-time checks.
top (Table of Processes)
Provides a real-time, dynamic view of processes.
Sorted by CPU usage by default (press M for memory).
Interactive: allows killing processes (k), changing priority (r).
Updates every few seconds.
Useful for ongoing monitoring and troubleshooting.
Mistake
The `rm` command moves files to a trash folder.
Correct
`rm` permanently deletes files by unlinking them from the filesystem. There is no recycle bin or trash in the Linux command line by default. Once removed, data may be recoverable with specialized tools only if not overwritten, but it is not moved to a trash folder. This is why `rm -i` is recommended for safety.
Mistake
The `sudo` command stands for 'superuser do' and requires the root password.
Correct
`sudo` stands for 'substitute user do' and runs a command as another user (default root). It does NOT require the root password; instead, it requires the user's own password, provided the user is listed in `/etc/sudoers`. The root password is only needed if you `su` to root.
Mistake
The `chmod 777` command makes a file executable.
Correct
`chmod 777` sets full read, write, and execute permissions for owner, group, and others. While it does make a file executable, it also grants write and read to everyone, which is a security risk. The correct command to simply make a file executable is `chmod +x` (adds execute to current permissions).
Mistake
The `ls -l` command shows hidden files.
Correct
`ls -l` shows files in long format but does NOT include hidden files (those starting with a dot). To show hidden files, you must use `ls -la` or `ls -l -a`. The `-a` flag is necessary to display all files including `.` and `..`.
Mistake
The `kill` command always terminates a process immediately.
Correct
By default, `kill` sends SIGTERM (signal 15), which asks the process to terminate gracefully. The process may ignore it or take time to clean up. Only `kill -9` (SIGKILL) forces immediate termination by the kernel, which cannot be caught or ignored. Using `kill` without options may not stop a hung process.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
`su` (substitute user) switches to another user account, typically root, and requires that user's password. It opens a new shell. `sudo` (substitute user do) allows a permitted user to execute a command as another user (usually root) using their own password, as specified in `/etc/sudoers`. The key difference: `su` gives you a root shell (until you exit), while `sudo` runs a single command with elevated privileges. For security, `sudo` is preferred because it logs commands and limits access.
Use the `chmod` command. The simplest way is `chmod +x filename`. This adds execute permission for the owner, group, and others based on the current umask. You can also specify `chmod u+x filename` to add execute only for the owner. Alternatively, use numeric mode: `chmod 755 filename` sets rwxr-xr-x, which includes execute for all. To verify, use `ls -l filename`; an 'x' in the permission string indicates executable.
`ps aux` displays a snapshot of all running processes on the system. The `a` option shows processes for all users, `u` shows user-oriented format (including CPU and memory usage), and `x` includes processes not attached to a terminal (daemons). The output includes columns: USER (owner), PID (process ID), %CPU, %MEM, VSZ (virtual memory size), RSS (resident set size), TTY (terminal), STAT (process state), START (start time), TIME (cumulative CPU time), and COMMAND (command name). This is the most common way to list all processes for troubleshooting.
Use the `find` command. For example, `find /home -name "*.txt"` searches for all files ending with `.txt` under `/home`. The `-name` option is case-sensitive; use `-iname` for case-insensitive. You can also search by type (`-type f` for files, `-type d` for directories), size (`-size +100M`), or modification time (`-mtime -7` for modified in last 7 days). `find` is powerful but can be slow on large filesystems; use `locate` (if installed) for faster searches based on a database.
`grep` (global regular expression print) searches for patterns in text files. It prints lines that match a given pattern. For example, `grep "error" /var/log/syslog` finds all lines containing 'error'. Common options: `-i` for case-insensitive, `-r` for recursive search in directories, `-v` to invert match (show lines that do NOT match), `-c` to count matches, `-n` to show line numbers. `grep` is essential for log analysis and filtering command output (e.g., `ps aux | grep apache`).
Use `cp -r sourcedir destdir`. The `-r` (recursive) flag is required to copy directories. For example, `cp -r /var/www /backup/www` copies the entire `/var/www` directory to `/backup/www`. If `destdir` does not exist, it will be created. To preserve permissions and timestamps, add `-p` (or `-a` for archive mode, which includes `-r` and preserves everything). Use `-i` to prompt before overwriting existing files.
`apt` (Advanced Package Tool) is used on Debian-based distributions (Ubuntu, Debian, Mint). `yum` (Yellowdog Updater Modified) is used on Red Hat-based distributions (RHEL, CentOS, Fedora). Both install, update, and remove software packages. For example, to install a package: `sudo apt install nginx` on Ubuntu, `sudo yum install nginx` on CentOS. `yum` is being replaced by `dnf` in newer Fedora/RHEL versions. The exam may ask which command to use on a given distribution.
You've just covered Linux Basic Commands — now see how well it sticks with free 220-1102 practice questions. Full explanations included, no account needed.
Done with this chapter?