linux_terminalbench 69 Q&As

Linux Terminalbench FAQ & Answers

69 expert Linux Terminalbench answers researched from official documentation. Every answer cites authoritative sources you can verify.

File Permissions

9 questions
A

chmod 600 sets read and write permissions for the owner only (rw-------). The owner can read and write the file, while group members and others have no access at all. This is commonly used for sensitive files like SSH private keys (~/.ssh/id_rsa) and configuration files containing passwords.

95% confidence
A

chmod 755 sets permissions to rwxr-xr-x, allowing the owner to read, write, and execute, while group members and others can only read and execute. This is the standard permission for directories and executable scripts that need to be accessible by all users but only modifiable by the owner.

95% confidence
A

chmod 644 sets permissions to rw-r--r--, allowing the owner to read and write, while group members and others can only read. This is the typical permission for regular text files and web content, ensuring only the owner can modify the file while everyone else can view it.

95% confidence
A

chmod 777 sets permissions to rwxrwxrwx, giving everyone (owner, group, and others) full read, write, and execute access. This is dangerous because any user on the system can modify or execute the file, creating security vulnerabilities. It should almost never be used in production environments. Use more restrictive permissions like 755 for directories or 644 for files instead.

95% confidence
A

Use chmod +x filename to add execute permission for all users (owner, group, and others). For more specific control: chmod u+x filename adds execute for owner only, chmod g+x filename for group only, chmod o+x filename for others only. You can also use numeric mode: chmod 755 filename gives rwxr-xr-x permissions.

95% confidence
A

Numeric permissions use three digits representing owner, group, and others. Each digit is the sum of: read (4) + write (2) + execute (1). For example: 7 = 4+2+1 = rwx (full access), 6 = 4+2 = rw- (read and write), 5 = 4+1 = r-x (read and execute), 4 = r-- (read only), 0 = --- (no access). So chmod 754 means owner gets rwx, group gets r-x, others get r--.

95% confidence
A

Use chmod -R to recursively change permissions on a directory and all its contents. For example: chmod -R 755 /path/to/directory. A common best practice for web directories is to set different permissions for files vs directories: find /var/www -type d -exec chmod 755 {} ; (directories) and find /var/www -type f -exec chmod 644 {} ; (files).

95% confidence
A

umask (user file-creation mode mask) defines default permissions for new files and directories by specifying which permissions to remove. Default umask is 022 for root and 002 for regular users. With umask 022: new files get 644 (666-022), new directories get 755 (777-022). View current umask with the 'umask' command.

95% confidence
A

Set umask in shell configuration files: ~/.bashrc or ~/.bash_profile for individual users, /etc/profile or /etc/bash.bashrc for system-wide. Add the line 'umask 027' (for example). Common values: 022 (owner full, others read), 027 (owner full, group read, others none), 077 (owner only, completely private).

95% confidence

Cron Jobs

9 questions
A

Crontab uses five time fields followed by the command: minute (0-59) hour (0-23) day-of-month (1-31) month (1-12) day-of-week (0-7, where 0 and 7 are Sunday). Special characters: * (any value), , (list separator), - (range), / (step values). Example: 30 2 * * 1 /script.sh runs at 2:30 AM every Monday.

95% confidence
A

Use crontab -e to edit your personal crontab. Other useful commands: crontab -l lists current crontab entries, crontab -r removes the entire crontab, crontab -i prompts before removal. To edit another user's crontab (requires root): crontab -u username -e. System-wide cron jobs go in /etc/crontab or /etc/cron.d/ directory.

95% confidence
A

Use */5 in the minute field: */5 * * * * /path/to/script.sh runs every 5 minutes. The */5 syntax means 'every 5th minute' (0, 5, 10, 15, etc.). Note: */35 does NOT run every 35 minutes; it runs at minutes 0 and 35 each hour. For true 35-minute intervals, you need external scheduling tools.

95% confidence
A

Common causes: 1) Environment variables not set (cron has minimal PATH), 2) Script not executable (run chmod +x), 3) Missing absolute paths to commands, 4) Syntax errors in crontab, 5) Missing newline at end of crontab file, 6) Output not redirected (add >/dev/null 2>&1 or redirect to log). Check cron logs: grep CRON /var/log/syslog (Debian/Ubuntu) or /var/log/cron (RHEL/CentOS).

95% confidence
A

Define variables at the top of your crontab file before any jobs: PATH=/usr/local/bin:/usr/bin:/bin, SHELL=/bin/bash, HOME=/home/user. These apply to all jobs below. For single jobs, use inline: * * * * * PATH=/custom/path /script.sh. You can also source profiles in a wrapper script: #!/bin/bash; source /etc/profile; /actual/script.sh

95% confidence
A

Test with minimal environment: env -i /bin/bash -c '/path/to/script.sh' simulates cron's environment. Redirect output for debugging: * * * * * /script.sh >>/var/log/myscript.log 2>&1. Use full paths for all commands (find with 'which command'). Compare environments: add 'env > /tmp/cronenv.txt' to cron job and compare with manual 'env > /tmp/shellenv.txt'.

95% confidence
A

Edit crontab with crontab -e and add a line with the five time fields plus command. Examples: 0 3 * * * /backup.sh (daily at 3:00 AM), 30 8 1 * * /monthly.sh (1st of each month at 8:30 AM), 0 0 * * 0 /weekly.sh (Sunday midnight), 0 */6 * * * /script.sh (every 6 hours). Use crontab.guru to validate syntax.

95% confidence

File Operations

8 questions
A

Use find with -perm option. Exact match: find / -perm 644 (files with exactly 644). At least: find / -perm -755 (at least 755, extras allowed). Any match: find / -perm /222 (writable by owner OR group OR others). Find SUID files: find / -perm -4000. Find SGID files: find / -perm -2000. Add -type f for files only.

95% confidence
A

Use find with -user option: find /path -user username finds all files owned by that user. Examples: find / -user john (all files owned by john), find /home -user root (root-owned files in /home). Add -type f for files only or -type d for directories. Combine with -exec to take action: find / -user john -exec ls -l {} ;

95% confidence
A

Use cp source destination for files. For directories, add -r (recursive): cp -r sourcedir destdir. Useful options: -v (verbose), -i (interactive, prompt before overwrite), -p (preserve permissions/timestamps), -a (archive, preserves everything including symlinks). Example: cp -av /source /backup creates exact copy.

95% confidence
A

Use mv source destination to move or rename. For files: mv oldname newname (rename) or mv file /new/path/ (move). For directories: same syntax, no -r needed. Options: -v (verbose), -i (interactive), -n (no overwrite). Example: mv *.txt /archive/ moves all txt files to archive.

95% confidence
A

Use rm filename to delete files. For directories: rm -r dirname (recursive). Safety options: -i (prompt before each removal), -I (prompt once before removing more than 3 files). CAUTION: rm -rf is dangerous and permanent. Example: rm -ri /path/to/dir prompts for each file. Never run rm -rf / or rm -rf * without careful consideration.

95% confidence

Access Control Lists

7 questions
A

The ACL mask defines the maximum effective permissions for named users, named groups, and the owning group (not owner or others). When setfacl modifies permissions, it automatically recalculates the mask to be the union of all affected entries. Use setfacl -n to prevent automatic mask recalculation. View the mask with getfacl; effective permissions are shown in comments.

95% confidence
A

Use setfacl with -R flag for recursive application: setfacl -Rm u:username:rwx /path/to/dir sets ACL on directory and all existing contents. For default ACLs on new files too, combine with -d: setfacl -Rdm u:username:rwx /path/to/dir. Note: -R only affects existing files; -d affects newly created files.

95% confidence

Service Management

7 questions
A

Use systemctl status servicename to see if a service is running, its PID, memory usage, and recent log entries. States include: active (running), inactive (stopped), failed, or activating/deactivating. Example: systemctl status nginx shows nginx status. Add -l for full log lines without truncation.

95% confidence
A

Use systemctl with these actions: systemctl start servicename (start), systemctl stop servicename (stop), systemctl restart servicename (stop then start), systemctl reload servicename (reload config without stopping). Examples: systemctl restart nginx, systemctl stop apache2. Requires root or sudo privileges.

95% confidence
A

Use systemctl enable servicename to configure a service to start automatically at boot. Use systemctl disable servicename to prevent auto-start. Check current state with systemctl is-enabled servicename. To enable AND start immediately: systemctl enable --now servicename. These commands modify symlinks in /etc/systemd/system/.

95% confidence
A

Use journalctl -u servicename to view logs for a specific systemd service. Useful options: -f (follow new entries like tail -f), -n 50 (show last 50 lines), --since '1 hour ago' (time-based filter), -p err (show only errors). Example: journalctl -u nginx -f shows live nginx logs. Combine with grep for filtering.

95% confidence
A

Common journalctl commands: journalctl -b (current boot only), journalctl -b -1 (previous boot), journalctl --since 'today' (today's logs), journalctl --since '2024-01-01' --until '2024-01-02' (date range), journalctl -p err (errors only), journalctl -k (kernel messages). Add -r to reverse order (newest first).

95% confidence
A

Use systemctl list-units --type=service to show active services. Add --all to include inactive services: systemctl list-units --type=service --all. For installed unit files: systemctl list-unit-files --type=service. Filter by state: systemctl list-units --type=service --state=running shows only running services.

95% confidence
A

Configure in /etc/systemd/journald.conf: SystemMaxUse=1G limits total disk usage to 1GB. RuntimeMaxUse limits volatile storage. Apply changes with: systemctl restart systemd-journald. Check current usage: journalctl --disk-usage. Clean manually: journalctl --vacuum-size=500M or journalctl --vacuum-time=7d.

95% confidence

File Recovery

4 questions
A

Use dd if=inputfile bs=1 skip=OFFSET count=LENGTH to extract LENGTH bytes starting at byte OFFSET. Example: dd if=disk.img bs=1 skip=1234 count=100 extracts 100 bytes starting at offset 1234. For efficiency with large offsets, use iflag=skip_bytes,count_bytes: dd if=disk.img skip=1234 count=100 iflag=skip_bytes,count_bytes. Redirect output with 2>/dev/null to suppress the summary message.

95% confidence
A

Use grep -aob 'pattern' filename to search binary files and get byte offsets. The -a flag treats binary as text, -o prints only matched parts, and -b prints the byte offset before each match. Example: grep -aob 'PASSWORD' disk.img outputs '1234:PASSWORD' meaning the pattern starts at byte 1234. For hex patterns use: grep -obUaP '\x00\x01' file.bin. Pipe to cut -d: -f1 to extract just the offset number.

95% confidence
A

Combine grep and dd for forensic text recovery: 1) Find byte offset with grep -aob 'known_pattern' disk.img, 2) Extract surrounding data with dd if=disk.img bs=1 skip=OFFSET count=WINDOW 2>/dev/null, 3) Filter printable chars with tr -c 'A-Za-z0-9' ' '. For passwords: if you know it starts with 'XYZ', use grep -aob 'XYZ' disk.img to find offset, then extract a window around it. Deleted files remain on disk until overwritten.

95% confidence
A

When you know partial password content (e.g., starts with 'ABC', ends with 'XYZ'), use this forensic strategy: 1) Find disk image with: find /path -name '.img' -o -name '.dat', 2) Search for start pattern: OFFSET=$(grep -aob 'ABC' disk.img | head -1 | cut -d: -f1), 3) Extract window around offset: dd if=disk.img bs=1 skip=$OFFSET count=50 2>/dev/null, 4) Filter to alphanumeric only: tr -c 'A-Z0-9' ' ', 5) Find contiguous sequences matching both patterns. Write results to output file.

95% confidence

Text Processing

4 questions
A

Use tr -c 'A-Za-z0-9' ' ' to replace all non-alphanumeric characters with spaces. The -c flag means 'complement' (match everything NOT in the set). For uppercase and digits only: tr -c 'A-Z0-9' ' '. For lowercase only: tr -c 'a-z' ' '. Combine with binary extraction: dd if=file bs=1 skip=100 count=50 2>/dev/null | tr -c 'A-Z0-9' ' '. Use tr ' ' '\n' to split on spaces into separate lines.

95% confidence
A

Basic: grep 'pattern' filename searches for pattern. Useful options: -r (recursive in directories), -i (case insensitive), -n (show line numbers), -l (list matching files only), -v (invert, show non-matching lines), -c (count matches). Example: grep -rn 'error' /var/log/ searches for 'error' in all log files.

95% confidence
A

Use awk '{print $N}' where N is the column number (1-based). Examples: awk '{print $1}' file (first column), awk '{print $1,$3}' file (first and third columns). Change delimiter with -F: awk -F: '{print $1}' /etc/passwd extracts usernames. $0 prints the entire line, NF is the number of fields.

95% confidence

Log Analysis

4 questions

Security Monitoring

4 questions
A

Check auth logs: grep 'Failed password' /var/log/auth.log (Debian/Ubuntu) or /var/log/secure (RHEL/CentOS). To count by IP: grep 'Failed password' /var/log/auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -rn shows IPs sorted by attempt count. Use journalctl -u sshd for systemd systems.

95% confidence
A

Authentication logs location varies by distribution: Debian/Ubuntu use /var/log/auth.log, RHEL/CentOS use /var/log/secure. On systemd systems, also use journalctl -u sshd or journalctl -t sshd. These logs contain SSH logins, sudo usage, su commands, and other authentication events.

95% confidence
A

Use these commands: 'last' shows recent successful logins with login/logout times. 'lastb' shows failed login attempts (requires root). 'lastlog' shows most recent login for each user. 'who' shows currently logged-in users. 'w' shows logged-in users and what they are doing. Data comes from /var/log/wtmp and /var/log/btmp.

95% confidence

Process Management

4 questions
A

Use ps aux to list all processes with detailed info including user, PID, CPU%, memory%, and command. Other useful options: ps -ef (full format), ps aux --sort=-%mem (sort by memory), ps aux --sort=-%cpu (sort by CPU). Use 'top' or 'htop' for real-time interactive process monitoring.

95% confidence
A

Use kill PID to send SIGTERM (graceful termination). If process doesn't stop, use kill -9 PID for SIGKILL (forced termination, cannot be caught or ignored). Examples: kill 1234, kill -9 1234. SIGTERM allows cleanup; SIGKILL is immediate. Always try SIGTERM first, use SIGKILL as last resort.

95% confidence
A

Use pkill processname to kill all processes matching the name. Use killall processname for exact name match. Examples: pkill firefox, killall nginx. Add -9 for forced kill: pkill -9 firefox. Use pgrep processname first to see which processes would be affected. Be careful with partial matches using pkill.

95% confidence

Network Troubleshooting

4 questions
A

Use ping hostname or ping IP to test connectivity. Useful options: -c 4 (send 4 packets then stop), -i 2 (2 second interval), -w 10 (timeout after 10 seconds). Examples: ping -c 4 google.com, ping -c 3 192.168.1.1. Note: some hosts block ICMP, so no response doesn't always mean host is down.

95% confidence
A

Use ss -tunlp or netstat -tunlp to show listening ports with process info. Options: -t (TCP), -u (UDP), -n (numeric), -l (listening), -p (process). Example output shows local address:port, state, and PID/program name. ss is the modern replacement for netstat and is faster.

95% confidence
A

Use traceroute hostname (or tracert on Windows) to show the path packets take to reach a destination. Each line shows a hop with its response time. Use -n for numeric output (no DNS lookups), -m 30 to set max hops. Alternative: mtr hostname combines traceroute and ping for continuous monitoring.

95% confidence

Special Permissions

3 questions
A

The sticky bit on a directory allows only the file owner, directory owner, or root to delete or rename files within it, even if others have write permission. It is commonly used on /tmp. To set: chmod +t directory or chmod 1777 directory. When set, ls -l shows a 't' in the others execute position (drwxrwxrwt).

95% confidence
A

SUID (Set User ID) makes an executable run with the file owner's permissions rather than the executing user's. For example, /usr/bin/passwd has SUID set so users can change their password (which requires root access to /etc/shadow). To set: chmod u+s filename or chmod 4755 filename. When set, ls -l shows 's' in owner execute position (-rwsr-xr-x).

95% confidence
A

SGID (Set Group ID) has two functions: on files, it runs with the file's group permissions; on directories, it makes new files inherit the directory's group ownership instead of the creator's primary group. Useful for shared directories. To set: chmod g+s directory or chmod 2755 directory. When set, ls -l shows 's' in group execute position (drwxr-sr-x).

95% confidence

File Ownership

2 questions
A

Use chown user:group filename to change both owner and group. Variations: chown user filename (owner only), chown :group filename (group only), chown -R user:group directory (recursive). Examples: chown root:www-data /var/www sets owner to root and group to www-data. Only root or sudo users can change file ownership.

95% confidence