Linux Command Mastery: 300 Essential Interview Questions and Answers

300 Linux Command Questions with Answers

Basic Commands and Navigation

  1. What command displays your current working directory?

Ans: pwd (Print Working Directory)

  1. How do you list files in a directory?

Ans: ls (List)

  1. What does the -l option do when used with ls?

Ans: Shows files in long format with details like permissions, ownership, size, and date

  1. How do you list hidden files in Linux?

Ans: ls -a (lists all files including hidden ones that start with a dot)

  1. What command changes directories?

Ans: cd (Change Directory)

  1. How do you navigate to your home directory quickly?

Ans: cd or cd ~

  1. What command creates a new directory?

Ans: mkdir (Make Directory)

  1. How do you remove an empty directory?

Ans: rmdir (Remove Directory)

  1. What command removes a non-empty directory?

Ans: rm -r (Remove recursively)

  1. How do you create an empty file?

Ans: touch filename

  1. What is the difference between rm and rmdir?

Ans: rm removes files by default, and with -r flag can remove directories and their contents rmdir only removes                   empty directories

  1. How do you copy a file?

Ans: cp source destination

  1. How do you move a file?

Ans: mv source destination

  1. What does the cp -r command do?

Ans: Copies directories recursively (including all files and subdirectories)

  1. How do you display the contents of a file?

Ans: cat filename (concatenate and display)

  1. What command shows just the first few lines of a file?

Ans: head filename

  1. What command shows just the last few lines of a file?

Ans: tail filename

  1. How do you concatenate and display file contents?

Ans: cat file1 file2 file3

  1. What command shows file or directory information?

Ans: stat filename

  1. How do you find recently modified files?

Ans: find /path -type f -mtime -n (where n is the number of days)

File Permissions and Ownership

  1. What command changes file permissions?

Ans: chmod (Change Mode)

  1. How do you read file permissions in Linux?

Ans: In the format -rwxrwxrwx where first character is file type, and the next 9 characters represent owner, group,              and others permissions (read, write, execute)

  1. What do the numbers 754 represent in chmod?

Ans: 7 (rwx=4+2+1) for owner, 5 (r-x=4+0+1) for group, 4 (r–=4+0+0) for others

  1. How do you make a file executable?

Ans: chmod +x filename

  1. What command changes file ownership?

Ans: chown user filename

  1. How do you change both user and group ownership at once?

Ans: chown user:group filename

  1. What command sets default permissions for new files?

Ans: umask

  1. What is the difference between symbolic and numeric permission notation?

Ans: Symbolic uses letters (r,w,x) and operators (+,-,=)

Numeric uses octal numbers (0-7)

  1. How do you view the permissions in octal format?

Ans: stat -c ‘%a %n’ filename

  1. What is the sticky bit and how do you set it?

Ans: It restricts file deletion; set with chmod +t directory or chmod 1xxx directory

  1. What does the setuid bit do?

Ans: Allows users to run an executable with the permissions of the file owner; set with chmod u+s filename

  1. What does the setgid bit do?

Ans: When applied to directories, new files inherit the directory’s group; set with chmod g+s directory

  1. How do you find all files with specific permissions?

Ans: find /path -perm mode

  1. What permissions are required to delete a file?

Ans: Write permission on the directory containing the file

  1. What command displays your current user ID and group IDs?

Ans: id

  1. How do you change only specific permission bits?

Ans: chmod u+x,g-w,o=r filename

  1. How do you copy file permissions between files?

Ans: chmod –reference=reference_file target_file

  1. What is ACL in Linux and how do you use it?

Ans: Access Control Lists provide more granular permissions; use setfacl to set and getfacl to view

  1. How do you check if a file has extended attributes?

Ans: lsattr filename

  1. What command shows the security context of a file?

Ans: ls -Z filename (on SELinux-enabled systems)

Users and Groups

  1. What command creates a new user?

Ans: useradd username or adduser username

  1. How do you delete a user account?

Ans: userdel username

  1. What command creates a new group?

Ans: groupadd groupname

  1. How do you add a user to a group?

Ans:  usermod -aG groupname username

  1. What command changes your password?

Ans: passwd

  1. How do you switch to another user?

Ans: su username

  1. What command shows all currently logged-in users?

Ans: who or w

  1. How do you list all users on the system?

Ans: cat /etc/passwd or getent passwd

  1. What file contains user information?

Ans: /etc/passwd

  1. What file contains group information?

Ans: /etc/group

  1. How do you lock a user account?

Ans: passwd -l username or usermod -L username

  1. What command modifies user account details?

Ans: usermod

  1. How do you change a user’s default shell?

Ans: chsh -s /path/to/shell username or usermod -s /path/to/shell username

  1. What command shows your current username?

Ans: whoami

  1. How do you temporarily become the superuser?

Ans: sudo -i or sudo su

  1. What is the difference between su and sudo?

Ans: su switches user (often to root) and requires the target user’s password

sudo executes a single command with elevated privileges and requires your own password

  1. How do you edit the sudoers file safely?

Ans: visudo

  1. What command sets user resource limits?

Ans: ulimit for shell limits or prlimit for process limits

  1. How do you check the groups a user belongs to?

Ans: groups username

  1. How do you remove a user from a group?

Ans: gpasswd -d username groupname or deluser username groupname

Process Management

  1. What command lists running processes?

Ans: ps

  1. How do you view processes in a hierarchical tree?

Ans: pstree

  1. What command shows dynamic real-time processes?

Ans: top or htop

  1. How do you kill a process?

Ans: kill PID or killall process_name

  1. What signal does kill -9 send?

Ans: SIGKILL (forcefully terminates the process)

  1. How do you find the process ID of a specific program?

Ans: pidof program_name or pgrep program_name

  1. What command runs a process in the background?

Ans: Add & at the end of command or press Ctrl+Z followed by bg

  1. How do you bring a background process to the foreground?

Ans: fg [job_number]

  1. What command displays the status of jobs in the current session?

Ans: jobs

  1. How do you set process priority when launching a program?

Ans: nice -n value command

  1. What command changes the priority of a running process?

Ans: renice -n value -p PID

  1. How do you list processes by resource usage?

Ans: ps aux –sort=-%cpu or ps aux –sort=-%mem

  1. What command shows process information for a specific user?

Ans: ps -u username

  1. How do you check which processes are using a file?

Ans: lsof filename

  1. What command displays information about process limits?

Ans: ulimit -a

  1. How do you pause and resume a process?

Ans: Pause with kill -STOP PID, resume with kill -CONT PID

  1. What command shows processes sorted by memory usage?

Ans: ps aux –sort=-%mem

  1. How do you start a process that continues after you log out?

Ans: nohup command & or using screen/tmux

  1. What command shows process ancestry?

Ans: ps f or pstree

  1. How do you kill all processes of a specific user?

Ans: pkill -u username

Text Processing

  1. What command searches for text patterns in files?

Ans: grep pattern files

  1. How do you use regular expressions with grep?

Ans: grep -E “regex_pattern” file or egrep “regex_pattern” file

  1. What command counts lines, words, and characters?

Ans: wc filename

  1. How do you replace text in a file without opening it?

Ans: sed ‘s/old_text/new_text/g’ filename

  1. What command sorts the content of a file?

Ans: sort filename

  1. How do you remove duplicate lines from a file?

Ans: sort filename | uniq or awk ‘!seen[$0]++’ filename

  1. What command extracts specific columns from text?

Ans: cut -d delimiter -f fields filename

  1. How do you combine multiple files side by side?

Ans: paste file1 file2

  1. What command compares two files?

Ans: diff file1 file2

  1. How do you display differences between files in a unified format?

Ans: diff -u file1 file2

  1. What command checks a file for spelling errors?

Ans: aspell check filename

  1. How do you convert tabs to spaces in a file?

Ans: expand filename

  1. What command shows non-printable characters in a file?

Ans: cat -A filename or cat -v filename

  1. How do you extract specific lines from a file?

Ans: sed -n ‘start,endp’ filename or head -n end | tail -n count

  1. What command joins lines from multiple files based on a common field?

Ans: join file1 file2

  1. How do you convert text to uppercase or lowercase?

Ans: To uppercase: tr ‘a-z’ ‘A-Z’ < file

To lowercase: tr ‘A-Z’ ‘a-z’ < file

  1. What command formats text into columns?

Ans: column -t filename

  1. How do you print specific fields from each line?

Ans: awk ‘{print $1, $3}’ filename

  1. What command applies a command to each line of a file?

Ans: xargs command < input_file

  1. How do you find lines matching multiple patterns?

Ans: grep -E ‘pattern1|pattern2’ file or grep pattern1 file | grep pattern2

Shell Scripting Basics

  1. How do you create a shell script?

Ans: Create a text file with commands and make it executable with chmod +x script.sh

  1. What permissions should a shell script have?

Ans: At minimum, executable (chmod +x script.sh or chmod 755 script.sh)

  1. How do you pass arguments to a shell script?

Ans: Add arguments after the script name: ./script.sh arg1 arg2

Access inside script with $1, $2, etc. or $@ for all arguments

  1. What does #!/bin/bash mean at the start of a script?

Ans: It’s a shebang that specifies which interpreter should execute the script (in this case, bash)

  1. How do you define variables in shell scripts?

Ans: variable_name=value (no spaces around =)

  1. What command returns the exit status of the last command?

Ans: echo $?

  1. How do you implement if-else statements in bash?

Ans:  if [ condition ]; then

commands

elif [ condition ]; then

commands

else

commands

fi

  1. What is the syntax for loops in bash?

Ans:  For loop:

for var in list; do

commands

done

While loop:

while [ condition ]; do

commands

done

  1. How do you read user input in a script?

Ans:  read variable_name

  What are shell script functions and how do you define them?

Ans: function_name() {

commands

return value

}

  1. How do you perform arithmetic operations in bash?

Ans: $((expression)) or expr expression

  1. What command executes another command and captures its output?

Ans: Command substitution: $(command) or backticks `command`

  1. How do you check if a file exists in a script?

Ans: if [ -f filename ]; then

  1. What is command substitution and how is it used?

Ans: Captures output of a command: variable=$(command) or variable=`command`

  1. How do you create arrays in bash?

Ans: array=(value1 value2 value3)

  1. What special variables are available in shell scripts?

Ans: $0 (script name), $1-$9 (arguments), $# (argument count), $@ (all arguments), $$ (PID), $? (exit status)

  1. How do you debug a shell script?

Ans: Run with -x flag: bash -x script.sh or add set -x in script

  1. What is the difference between single and double quotes in scripts?

Ans: Single quotes preserve literal value

Double quotes allow variable substitution and command expansion

  1. How do you handle errors in shell scripts?

Ans: Check exit status, use set -e to exit on error, use trap to catch signals

  1. What command returns the length of a string variable?

Ans: ${#variable}

System Information

  1. What command shows system hardware information?

Ans: lshw or dmidecode

  1. How do you display kernel version?

Ans: uname -r or cat /proc/version

  1. What command shows system uptime?

Ans: uptime

  1. How do you check CPU information?

Ans: lscpu or cat /proc/cpuinfo

  1. What command displays memory usage information?

Ans: free -h

  1. How do you check disk usage?

Ans: df -h

  1. What command shows free and used disk space?

Ans: df -h

  1. How do you check disk I/O statistics?

Ans: iostat

  1. What command displays network interface information?

Ans: ifconfig or ip addr show

  1. How do you show the system hostname?

Ans: Hostname

  1. What command displays system load average?

Ans: uptime or cat /proc/loadavg

  1. How do you view the current date and time?

Ans: date

  1. What command lists attached USB devices?

Ans: lsusb

  1. How do you view information about PCI devices?

Ans: lspci

  1. What command shows installed hardware components?

Ans: lshw

  1. How do you display the system’s boot messages?

Ans: dmesg

  1. What command checks the battery status on a laptop?

Ans: acpi -b or upower -i /org/freedesktop/UPower/devices/battery_BAT0

  1. How do you find out your Linux distribution?

Ans: lsb_release -a or cat /etc/*-release

  1. What command shows running time of processes?

Ans: ps -eo pid,cmd,etime

  1. How do you display the file system type?

Ans: df -T or findmnt

Disk and File System

  1. What command creates a file system on a partition?

Ans: mkfs -t filesystem /dev/partition

  1. How do you check and repair a file system?

Ans: fsck /dev/partition

  1. What command shows mounted file systems?

Ans: mount or df -h

  1. How do you mount a file system?

Ans: mount /dev/partition /mount_point

  1. What command unmounts a file system?

Ans: umount /mount_point or umount /dev/partition

  1. How do you create a swap space?

Ans: mkswap /dev/partition followed by swapon /dev/partition

  1. What command shows disk partition information?

Ans: fdisk -l or parted -l

  1. How do you create disk partitions?

Ans: Using fdisk, parted, or gparted

  1. What is the command to create a CD/DVD ISO image?

Ans: dd if=/dev/cdrom of=image.iso or readom dev=/dev/cdrom f=image.iso

  1. How do you burn an ISO to a CD/DVD?

Ans: wodim dev=/dev/cdrom image.iso or cdrecord -v dev=/dev/cdrom image.iso

  1. What command checks disk space usage by directory?

Ans: du -sh /path/to/directory

  1. How do you find large files on your system?

Ans: find /path -type f -size +100M or du -h /path | sort -hr | head

  1. What command creates a soft link?

Ans: ln -s target_file link_name

  1. How do you create a hard link?

Ans: ln target_file link_name

  1. What is the difference between soft and hard links?

Ans: Soft links point to a file path; can cross file systems; break if target is deleted

Hard links point to inode; must be on same file system; persist even if original is deleted

  1. How do you check inode usage on a file system?

Ans: df -i

  1. What command shows file system block size?

Ans: tune2fs -l /dev/partition | grep “Block size” or blockdev –getbsz /dev/partition

  1. How do you set disk quotas for users?

Ans: Use quotacheck, edquota, and quotaon commands

  1. What command displays read/write statistics for devices?

Ans: iostat or vmstat

  1. How do you clone a disk or partition?

Ans: dd if=/dev/source of=/dev/destination or using clonezilla

Package Management

  1. How do you install a package using apt?

Ans: apt install package_name

  1. What command removes a package in Debian/Ubuntu?

Ans: apt remove package_name or apt purge package_name

  1. How do you update the package list?

Ans: apt update

  1. What command upgrades all installed packages?

Ans: apt upgrade or apt full-upgrade

  1. How do you search for packages?

Ans: apt search keyword

  1. What command shows information about a package?

Ans: apt show package_name or dpkg -s package_name

  1. How do you list all installed packages?

Ans: dpkg -l or apt list –installed

  1. What command installs a local DEB file?

Ans: dpkg -i package.deb or apt install ./package.deb

  1. How do you add a new repository?

Ans: add-apt-repository ppa:repository/name or edit /etc/apt/sources.list

  1. What command cleans the local package cache?

Ans: apt clean or apt autoclean

  1. How do you hold a package at its current version?

Ans: apt-mark hold package_name

  1. What is the difference between upgrade and dist-upgrade?

Ans: upgrade only upgrades installed packages

dist-upgrade (or full-upgrade) may add or remove packages to satisfy dependencies

  1. How do you install a package using yum/dnf?

Ans: yum install package_name or dnf install package_name

  1. What command removes a package in Red Hat/Fedora?

Ans: yum remove package_name or dnf remove package_name

  1. How do you download a package without installing it?

Ans: apt download package_name or yumdownloader package_name

  1. What command shows package dependencies?

Ans: apt-cache depends package_name or rpm -qR package_name

  1. How do you list files installed by a package?

Ans: dpkg -L package_name or rpm -ql package_name

  1. What command finds which package a file belongs to?

Ans: dpkg -S /path/to/file or rpm -qf /path/to/file

  1. How do you check for broken dependencies?

Ans: apt check or yum check dependencies

  1. What command manages package repositories?

Ans: apt-add-repository in Debian/Ubuntu or editing repo files in /etc/yum.repos.d/

Networking

  1. What command shows your IP address?

Ans: ip addr or ifconfig

  1. How do you ping a remote host?

Ans: ping hostname

  1. What command shows active network connections?

Ans: netstat -tuln or ss -tuln

  1. How do you check open ports on your system?

Ans: netstat -tuln or ss -tuln or lsof -i

  1. What command traces the route to a host?

Ans: traceroute hostname or tracepath hostname

  1. How do you download files from the web?

Ans: wget URL or curl -O URL

  1. What command transfers files over SSH?

Ans: scp source user@host:destination

  1. How do you configure a network interface?

Ans: ifconfig interface options or ip addr add IP/mask dev interface

  1. What command shows network routing tables?

Ans: route -n or ip route show

  1. How do you check DNS resolution?

Ans: nslookup hostname or dig hostname

  1. What command captures and analyzes network packets?

Ans: tcpdump or wireshark

  1. How do you scan ports on a remote host?

Ans: nmap host

  1. What command checks if a port is reachable?

Ans: telnet host port or nc -zv host port

  1. How do you display socket statistics?

Ans: ss or netstat

  1. What command shows network interface statistics?

Ans: ip -s link or ifconfig

  1. How do you set up a basic firewall?

Ans: Using iptables, ufw, or firewalld

  1. What command checks bandwidth usage?

Ans: iftop or nethogs

  1. How do you share files over HTTP temporarily?

Ans: python -m http.server 8000 or python3 -m http.server 8000

  1. What command shows hostname resolution?

Ans: host hostname or getent hosts hostname

  1. How do you manage SSH keys?

Ans: ssh-keygen to create keys, ssh-copy-id to copy to remote host

System Administration

  1. How do you view system logs?

Ans: less /var/log/syslog or using journalctl

  1. What command schedules a job to run once?

Ans: at time or systemd-run –on-active=time command

  1. How do you schedule recurring jobs?

Ans: Using crontab -e or by adding scripts to /etc/cron.d/

  1. What command shows resource limits for users?

Ans: ulimit -a

  1. How do you change the system hostname?

Ans: hostnamectl set-hostname new_name or edit /etc/hostname

  1. What command synchronizes system time?

Ans: ntpdate pool.ntp.org or timedatectl set-ntp true

  1. How do you shut down the system?

Ans: shutdown -h now or systemctl poweroff

  1. What command reboots the system?

Ans: reboot or systemctl reboot

  1. How do you check if a service is running?

Ans: systemctl status service_name or service service_name status

  1. What command starts a service?

Ans: systemctl start service_name or service service_name start

  1. How do you enable a service to start at boot?

Ans: systemctl enable service_name

  1. What command shows memory consumption of each process?

Ans: ps aux –sort=-%mem

  1. How do you clear the terminal screen?

Ans: clear or Ctrl+L

  1. What command shows currently logged-in users with their activity?

Ans: w

  1. How do you view system boot logs?

Ans: journalctl -b

  1. What command manages background services?

Ans: systemctl or the older service

  1. How do you manage runlevels or targets?

systemctl get-default and systemctl set-default target

  1. What command displays the last login times?

Ans: last

  1. How do you send a message to all logged-in users?

Ans: wall “message”

  1. What command shows system initialization messages?

Ans: dmesg

Advanced Commands

  1. What command executes a program at specified intervals?

Ans: watch command

  1. How do you find file duplicates?

Ans: fdupes path or using find with checksums

  1. What command displays process wait I/O statistics?

Ans: pidstat -d or iotop

  1. How do you convert file encoding?

Ans: iconv -f source_encoding -t target_encoding file

  1. What command shows file access attempts?

Ans: auditctl with ausearch or aureport

  1. How do you stress test your system?

Ans: stress or stress-ng

  1. What command splits a file into smaller parts?

Ans: split -b size file or split -l lines file

  1. How do you merge multiple files into one?

Ans: cat file1 file2 file3 > merged_file

  1. What command connects to a remote server?

Ans: ssh user@hostname

  1. How do you sync files between directories or systems?

Ans: rsync source destination

  1. What command searches for files by content or attributes?

Ans: find with -exec grep or just grep -r

  1. How do you batch rename files?

Ans: rename ‘s/old/new/’ files or using a for loop with mv

  1. What command runs programs with modified environment variables?

Ans: env VAR=value command

  1. How do you limit process resource usage?

Ans: ulimit for shell limits or systemd-run with resource controls

  1. What command extracts archives?

Ans: tar -xf archive.tar or unzip archive.zip

  1. How do you create encrypted files?

Ans: Using gpg -c filename

  1. What command generates random data?

Ans: dd if=/dev/urandom or openssl rand

  1. How do you secure delete files?

Ans: shred filename or wipe filename

  1. What command benchmarks disk performance?

Ans: hdparm -t /dev/device or dd if=/dev/zero of=test bs=1M count=1000

  1. How do you run commands at low or high priority?

Ans: nice -n value command for low, nice -n -value command for high

 Security

  1. What command changes file security contexts?

Ans: chcon or restorecon

  1. How do you check for listening services?

Ans: netstat -tulnp or ss -tulnp

  1. What command displays and controls SELinux?

Ans: sestatus shows status, setenforce changes modes

  1. How do you check for root kits?

Ans: rkhunter or chkrootkit

  1. What command shows failed login attempts?

Ans: lastb or journalctl _COMM=sshd

  1. How do you generate cryptographic hashes?

Ans: md5sum, sha1sum, sha256sum, etc.

  1. What command verifies file integrity?

Ans: md5sum -c checksum_file or other hash verification tools

  1. How do you encrypt a partition?

Ans: Using cryptsetup for LUKS encryption

  1. What command scans for vulnerabilities?

Ans: lynis or openvas

  1. How do you check password aging information?

Ans: chage -l username

  1. What command changes password expiry information?

Ans: chage options username

  1. How do you set up two-factor authentication?

Ans: Using google-authenticator or libpam-yubico

  1. What command lists system capabilities?

Ans: getcap or setcap

  1. How do you audit system events?

Ans: Using auditd with ausearch and aureport

  1. What command checks file permissions for security issues?

Ans: ls -la or specialized tools like lynis

  1. How do you manage firewall rules?

Ans: Using iptables, ufw, or firewall-cmd

  1. What command shows active authorization sessions?

Ans: loginctl list-sessions

  1. How do you create and manage SSL certificates?

Ans: Using openssl or certbot

  1. What command shows failed authentication attempts?

Ans: journalctl _COMM=sshd | grep Failed

  1. How do you set file access control lists?

Ans: setfacl and getfacl

Archive and Compression

  1. What command creates a tar archive?

Ans: tar -cf archive.tar files

  1. How do you extract a tar archive?

Ans: tar -xf archive.tar

  1. What command compresses files using gzip?

Ans: gzip filename or tar -czf archive.tar.gz files for multiple files

  1. How do you decompress gzip files?

Ans: gunzip filename.gz or gzip -d filename.gz

  1. What command creates zip archives?

Ans: zip archive.zip files

  1. How do you extract zip archives?

Ans: unzip archive.zip

  1. What command shows the contents of an archive without extracting?

Ans: tar -tf archive.tar or unzip -l archive.zip

  1. How do you create encrypted archives?

Ans: zip -e archive.zip files or tar -czf – files | gpg -c > archive.tar.gz.gpg

  1. What command compresses files with better compression than gzip?

Ans: bzip2 filename or xz filename

  1. How do you check the integrity of a compressed file?

Ans: gzip -t file.gz, bzip2 -t file.bz2, or unzip -t file.zip

  1. What command combines archiving and compression in one step?

Ans: tar -czf archive.tar.gz files (gzip) or tar -cjf archive.tar.bz2 files (bzip2)

  1. How do you compare archives without extracting?

Ans: diff <(tar -tf archive1.tar) <(tar -tf archive2.tar)

  1. What command splits a large archive into parts?

Ans: split -b size archive.tar archive.part. or using zip/tar with volume options

  1. How do you join split archives?

Ans: cat archive.part.* > archive.tar or using specific tools like zip

  1. What command shows compression ratio statistics?

Ans: gzip -l file.gz or 7z l archive.7z

  1. How do you convert between archive formats?

Ans: Extract and recreate using the desired format’s tools

  1. What command creates differential backups?

Ans: tar –listed-incremental=snapshot-file -czf backup.tar.gz directory

  1. How do you create incremental backups?

Ans: tar –listed-incremental=snapshot-file -czf backup.tar.gz directory

  1. What command performs better compression for text files?

Ans: xz typically offers better compression for text files than gzip or bzip2

  1. How do you password-protect archives?

Ans: zip -e archive.zip files or gpg -c archive.tar

Miscellaneous

  1. What command sets terminal options?

Ans: stty

  1. How do you create a desktop shortcut from the command line?

Ans: Create a .desktop file in ~/.local/share/applications

  1. What command manages system services?

Ans: systemctl or the older service

  1. How do you add a scheduled shutdown?

Ans: shutdown -h time where time can be +minutes or hh:mm

  1. What command cancels a scheduled shutdown?

Ans: shutdown -c

  1. How do you run a command immune to hangups?

Ans: nohup command &

  1. What command manages environment variables?

Ans: export VAR=value to set or unset VAR to remove

  1. How do you execute commands from standard input?

Ans: bash -s or using a pipe with sh

  1. What command sets file timestamps?

Ans: touch -t YYYYMMDDHHMM.SS filename

  1. How do you run a previous command?

Ans:!! for the last command or !n for command number n in history

  1. What command displays the manual for a command?

Ans: man command

  1. How do you check command syntax without executing it?

Ans: Shell-specific: bash -n script.sh or using a “dry run” mode with some commands

  1. What command displays a calendar?

Ans: cal or ncal

  1. How do you add a user to the sudoers file?

Ans: visudo and add username ALL=(ALL) ALL or add to the sudo group

  1. What command kills processes by name?

Ans: pkill process_name or killall process_name

  1. How do you substitute characters in text?

Ans: tr ‘old_chars’ ‘new_chars’ < input_file or using sed

  1. What command shows file type information?

Ans: file filename

  1. How do you set the system time and date?

Ans: date -s “YYYY-MM-DD HH:MM:SS” or timedatectl set-time “YYYY-MM-DD HH:MM:SS”

  1. What command displays directory sizes?

Ans: du -sh directory or du -h –max-depth=1

  1. How do you disown a running process?

Ans: disown %job_number or start with nohup command &

 

 

SHARE THIS STORY

× How can I help you?