0% found this document useful (0 votes)
6 views11 pages

Linux Practice Questions

Uploaded by

villainformatic4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views11 pages

Linux Practice Questions

Uploaded by

villainformatic4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Linux Practice

Questions
https://www.linkedin.com/in/jbassim/

🌟 🚀
Support me and follow my LinkedIn profile for more insights and updates! Thanks for your
support.

Linux Practice Questions


Question Answer Why
What command lists files in the ls is used to list files and
ls
current directory? directories.
How do you change directory to
cd /home/user cd changes the current directory.
/home/user?
What command displays the pwd prints the full path of the
pwd
current working directory? current directory.
How do you create a new mkdir is used to create new
mkdir projects
directory named projects? directories.
How do you remove a file named
rm file.txt rm is used to delete files.
file.txt?
What command shows disk du reports disk space usage, and
du -h
usage for files and directories? -h makes it human-readable.
How do you copy a file named
cp file.txt backup.txt cp is used for copying files.
file.txt to backup.txt?
What command is used to move mv moves or renames files and
mv file.txt /path/to/directory/
file.txt to a directory? directories.
How do you view the contents of
cat file.txt cat displays the contents of files.
file.txt?
What command searches for a grep is used to search for patterns
grep "search_string" file.txt
string in file.txt? in files.
How do you display the last 10
tail file.txt tail shows the last lines of a file.
lines of file.txt?
What command displays system uname -a provides detailed
uname -a
information? system information.
How do you check current uptime shows how long the
uptime
system uptime? system has been running.
How do you change file chmod changes the permissions
chmod 755 file.txt
permissions? of a file.
What command shows active ps displays current processes
ps aux
processes? running on the system.
How do you find the location of a which shows the path to the
which command_name
command? executable of a command.
What is the command to view systemctl list-units -- systemctl manages system
running services? type=service services in modern Linux.
How do you view network Displays network interfaces and
ifconfig or ip addr
configuration? their configurations.
How can you create a symbolic ln -s creates a symbolic link to a
ln -s target link_name
link? file.
What command shows the history history lists previously executed
Question Answer Why
history of commands executed? commands.
How do you display the contents zcat displays the contents of
zcat file.gz
of a compressed file? compressed files.
How do you extract a .tar.gz file? tar -xzvf file.tar.gz tar extracts files from tar archives.
What command checks disk df shows disk space usage for
df -h
space usage? mounted filesystems.
How do you create a new file touch creates an empty file or
touch notes.txt
named notes.txt? updates the timestamp.
How do you append text to a >> appends text to the end of a
echo "text" >> file.txt
file? file.
find searches for files within a
How do you find files by name? find /path -name "filename"
directory tree.
What command compresses a
gzip file.txt gzip reduces the size of a file.
file using gzip?
How do you decompress a .gz gunzip restores the original file
gunzip file.txt.gz
file? from gzip compression.
What command displays all Lists all current environment
printenv or env
environment variables? variables.
How do you edit a file with nano is a simple text editor used
nano file.txt
nano? in the terminal.
How do you stop a running kill sends a signal to terminate a
kill PID
process? process by its PID.
What command gives you real- top provides a dynamic view of
top
time system performance stats? system processes.
How do you show the last login last shows the last login sessions
last
history? of users.
What command lists currently who displays users who are
who
logged-in users? currently logged in.
How do you check system free displays the amount of free
free -h
memory usage? and used memory.
How can you search for files by
find /path -type f -type f filters for files in the search.
type?
How do you list all installed dpkg lists all installed packages
dpkg -l
packages (Debian-based)? on a Debian-based system.
What command shows the man displays the manual pages
man command_name
manual for a specific command? for commands.
How do you create a tar creates a compressed archive
tar -czvf archive.tar.gz /path
compressed archive using tar? of specified files.
What command removes a
rmdir directory_name rmdir removes an empty directory.
directory?
How do you view the contents of less allows you to scroll through
less file.txt
a text file with pagination? the contents of a file.
What command displays the first
head file.txt head shows the first lines of a file.
10 lines of a file?
How do you find the current whoami displays the username of
whoami
user's username? the current user.
Question Answer Why
What command checks for apt checks for updates in Debian-
apt update
available updates? based systems.
How do you download files from
wget http://example.com/file wget retrieves files from the web.
the internet?
How can you monitor real-time tail -f displays new lines as they
tail -f /var/log/syslog
log file changes? are added to the log file.
What command changes the chown changes the owner and
chown user:group file.txt
ownership of a file? group of a file.
netstat displays network
How do you view network
netstat -tuln connections, listening ports, and
connections?
more.
How do you test the connectivity ping checks the reachability of a
ping hostname
to a host? host on a network.
What command clears the clear removes all previous
clear
terminal screen? commands from the terminal view.
How do you change the default chsh changes the login shell for
chsh -s /bin/bash username
shell for a user? the specified user.
How do you check the status of systemctl checks the status of a
systemctl status service_name
a service? specific service.
What command installs a apt is used to install software
apt install package_name
package (Debian-based)? packages.
How do you remove a package apt is used to uninstall software
apt remove package_name
(Debian-based)? packages.
What command shows current lsblk lists block devices and their
lsblk
disk partitions? mount points.
How do you make a file chmod modifies file permissions to
chmod +x file.sh
executable? allow execution.
What command finds the
pgrep searches for processes by
process ID (PID) of a running pgrep program_name
name.
program?
How do you schedule a task crontab edits the cron jobs for the
crontab -e
using cron? current user.
What command allows you to su changes the user account in
su username
switch users? the shell.
How do you display the current date shows the current system
date
date and time? date and time.
What command displays the IP ip is a powerful command for
ip addr
configuration of all interfaces? managing networking.
How do you change the passwd changes a user's
passwd username
password for a user? password.
What command shows system Both provide load averages of the
uptime or top
load averages? system.
How do you view the last few history displays previously
history
commands run in the terminal? executed commands.
How do you remove all files with rm *.ext * wildcard matches all files with
a specific extension? the specified extension.
What command checks the smartctl -a /dev/sda smartctl retrieves SMART
Question Answer Why
health of the disk? information from the disk.
How do you view the
Displays details about the
configuration of a network ip addr show eth0
specified network interface.
interface?

How do you search for files grep -r searches recursively in the


grep -r "string" /path/to/directory
containing a specific string? specified directory.
What command shows system htop provides an interactive
htop
resource usage in real time? process viewer.
How do you create a new file with > creates a new file with the
echo "Hello, World!" > file.txt
echo? specified content.
What command displays the hostname shows the name of the
hostname
system's hostname? current system.
How do you check for active user who lists users currently logged
who
sessions? into the system.
What command displays disk du -sh provides a summary of disk
du -sh /path/to/directory
usage for directories? usage.
How do you list all processes for ps -u filters processes by the
ps -u username
a specific user? specified user.
What command changes the chgrp changes the group
chgrp group_name file.txt
group ownership of a file? associated with a file.
How do you create a .zip zip compresses files into a .zip
zip archive.zip file1 file2
archive? archive.
Displays total, used, and free
What command checks the
free -h memory in a human-readable
available memory?
format.
How do you search for a apropos finds commands related
apropos command_name
command by name? to a keyword.
How do you display the contents cat shows the contents of the
cat /etc/config.conf
of a configuration file? specified file.
What command counts the wc -w counts words in the
wc -w file.txt
number of words in a file? specified file.
How do you find and delete Finds and deletes empty files in
find /path -type f -empty -delete
empty files? the specified path.
What command checks the Displays the current kernel
uname -r
version of the Linux kernel? version.
How do you find processes using lsof lists open files and their
lsof -i :port_number
a specific port? corresponding processes.
How do you compress a directory tar creates a compressed archive
tar -czvf archive.tar.gz /path
into a .tar.gz file? of the specified directory.
What command shows the Displays the path of the current
echo $SHELL
current shell being used? shell.
How do you create a cron job? crontab -e Edits the user's cron jobs.
What command logs out the
logout or exit Logs out of the current session.
current user?
How do you view detailed fdisk lists all disk partitions and
fdisk -l
information about disk partitions? their details.
What command retrieves HTTP curl -I fetches headers from a web
curl -I http://example.com
headers from a URL? resource.
How do you change a file's touch updates the file's
touch file.txt
timestamp to now? timestamp.
How do you display user account Displays user ID and group
id username
information? information.
What command shows all Lists all current environment
env
environment variables? variables.
How do you check if a service is systemctl is-enabled systemctl checks if a service is set
enabled at boot? service_name to start at boot.
How do you create a hard link? ln file.txt hardlink.txt ln creates a hard link to a file.
What command checks for open Displays active network
netstat -tuln
ports? connections and listening ports.
How do you display the routing Shows the current routing table
route -n
table? for the system.
What command shows the active Displays who is currently logged
who
users' sessions? into the system.
How do you check if a package is
`dpkg -l grep package_name`
installed?
How do you make a file read- Sets the file permissions to read-
chmod 444 file.txt
only? only for all users.
What command shuts down the Initiates a system shutdown
shutdown now
system? immediately.
How do you view the system log Opens the system log file for
less /var/log/syslog
file? viewing.
How do you check the status of a Displays information about
df -h
mounted file system? mounted file systems.
How do you remove a user from Removes a user account from the
userdel username
the system? system.
What command creates a new groupadd creates a new user
groupadd group_name
group? group.
How do you view all scheduled Lists all cron jobs for the current
crontab -l
cron jobs? user.
How do you disable a user
usermod -L username Locks the user account.
account?
What command provides disk
Displays disk usage with readable
usage in a human-readable du -h
sizes.
format?
How do you find the IP address Displays information about the
ip addr show eth0
of a specific interface? specified interface.
How do you create a backup of a cp -r recursively copies files and
cp -r /source /backup
directory? directories.
What command removes all files * wildcard removes all files in the
rm /path/to/directory/*
in a directory? specified directory.
How do you check the system's hostname Displays the hostname of the
hostname? system.
What command lists all active netstat -a Displays all active connections
network connections? and listening ports.
How do you display CPU usage Shows CPU usage statistics per
mpstat
statistics? processor.
What command shows memory ps lists processes sorted by
ps aux --sort=-%mem
usage by processes? memory usage.
How do you check for package
yum check-update yum checks for available updates.
updates (Red Hat-based)?
What command shows a list of Lists all installed RPM packages
rpm -qa
installed RPM packages? on the system.
How do you run a command as sudo executes commands with
sudo command_name
superuser? superuser privileges.
How do you check the
Displays configuration for the
configuration of a network ifconfig eth0
specified interface.
interface?
What command creates a backup tar creates a compressed backup
tar -czvf backup.tar.gz /
of the entire system? of the entire system.
How do you list all mounted Displays all currently mounted
mount
filesystems? filesystems.
How do you find files modified Searches for files modified in the
find /path -mtime -7
within the last 7 days? last 7 days.
What command lists all running systemctl list-units --
Displays active system services.
services? type=service
How do you restart the Restarts the networking service to
systemctl restart networking
networking service? apply changes.
What command shows the size Displays total size of the specified
du -sh /path/to/directory
of a directory? directory.
How do you check for processes Both provide a dynamic view of
top or htop
consuming high CPU? processes sorted by CPU usage.
How do you create a file with touch file.txt && chmod 600 Creates a file and sets its
specific permissions? file.txt permissions.
What command displays the Lists all currently running
ps -ef
active user processes? processes.
How do you display network Shows detailed statistics for
netstat -s
statistics? various network protocols.
How do you terminate a process Sends a termination signal to the
kill PID
by PID? specified process.
What command shows details Displays CPU architecture
lscpu
about the system's CPU? information.
How do you display the contents Lists the contents of the tar
tar -tvf archive.tar
of a .tar file? archive without extracting.
What command schedules a one- Schedules a one-time task to run
at time
time task? at a specified time.
How do you check for Lists all background jobs in the
jobs
background jobs? current session.
How do you create a new user? useradd username useradd creates a new user
account.
What command shows the file df -h Displays disk usage and available
system disk usage? space on mounted filesystems.
pacman updates the package
How do you check for system
pacman -Syu database and upgrades the
updates (Arch-based)?
system.
Question Answer Why
How do you view the current Displays the current Linux
uname -r
kernel version? kernel version.
What command shows the Displays the average load on
uptime
system’s load averages? the system.
dd if=/dev/zero of=/swapfile bs=1G
How do you create a swap file? Creates a 1GB swap file.
count=1
What command is used to Activates the specified swap
swapon /swapfile
activate a swap file? file.
How do you disable a swap Deactivates the specified
swapoff /swapfile
file? swap file.
What command installs a yum installs software
software package (RPM- yum install package_name packages on RPM-based
based)? systems.
How do you remove a directory rm -r recursively removes a
rm -r directory_name
and its contents? directory and its contents.
What command shows the disk
Displays the size of each item
usage of a directory and its du -sh *
in the directory.
subdirectories?
How do you display network Shows statistics for network
ifstat
interface statistics? interfaces.
What command changes the Changes the system's run
init 3
default run level? level to 3 (multi-user).
How do you check the SELinux Displays the current status of
sestatus
status? SELinux.
What command shows file
df --block-size=1 Displays disk usage in bytes.
system disk usage in bytes?
How do you view the history of Lists previously executed
history
commands? commands.
How do you search through
`history grep "search_term"`
command history?
What command locks a user Locks the specified user
usermod -L username
account? account.
How do you unlock a user Unlocks the specified user
usermod -U username
account? account.
What command displays the Shows the last 10 lines of the
tail -n 10 /var/log/syslog
last 10 lines of a log file? specified log file.
How do you copy a directory cp -r copies directories
cp -r source_dir target_dir
and its contents? recursively.
How do you find the size of a Shows the size of the
du -h file.txt
specific file? specified file.
What command lists all Displays all mounted
mount
currently mounted filesystems? filesystems.
Question Answer Why
How do you change file Changes the file's owner and
chown user:group file.txt
ownership and group? group.
How do you remove a user’s Removes the user and their
userdel -r username
home directory? home directory.
What command displays the Lists all groups the current
groups
current user's groups? user belongs to.
How do you schedule a Opens the cron table for
crontab -e
recurring task using cron? editing.
What command checks the Displays the current status of
systemctl status service_name
status of a service? a service.
How do you display the last
last Lists user login history.
login time for users?
What command shows disk
Displays disk usage for all
space usage for all mounted df -h
mounted filesystems.
filesystems?
How do you create a new Creates a new user account
adduser username
system user? on the system.
What command checks for find /path -type l ! -exec test -e {} \;
Finds broken symbolic links.
broken links? -print
How do you set the default Sets the default file
umask 022
permissions for new files? permissions.
What command shows the Displays kernel-related
dmesg
kernel messages? messages.
How do you display the current Shows the current date and
date
system date? time.
What command shows the Displays the home directory
echo $HOME
current user's home directory? of the current user.
How do you remove all files of Deletes all .jpg files in the
rm *.jpg
a certain type? current directory.
What command compresses Creates a .tar archive of the
tar -cvf archive.tar /path/to/files
files into a .tar archive? specified files.
Shows the size of the
How do you display disk usage
du -sh file.txt specified file in a human-
for a specific file?
readable format.
What command allows you to Sets the system date and
date -s "YYYY-MM-DD HH:MM:SS"
change the system time? time.
How do you check the last Shows shutdown and reboot
last -x
shutdown or reboot times? history.
What command is used to Changes the system's
hostnamectl set-hostname newname
change the system hostname? hostname.
How do you display the process Shows running processes in a
pstree
tree? tree format.
What command lists users Displays users logged into the
who
currently logged in? system.
How do you check the health cat /proc/mdstat Displays the status of RAID
status of a RAID array? arrays.
What command sends a write username Sends a message to a
Question Answer Why
message to another user? logged-in user.
How do you check the Displays filesystem types for
df -T
filesystem type? mounted partitions.
What command shows Lists block devices and their
lsblk
available storage on a device? storage availability.
Displays detailed information
How do you view detailed
stat file.txt including size and
information about a file?
permissions.
What command installs Installs software compiled
make install
software from source? from source code.
Provides a detailed overview
How do you display system
inxi -F of system hardware and
information?
software.
What command checks the Displays the current status of
ufw status
status of the firewall? the firewall.
How do you update the
Updates the package list for
package index (Debian- apt update
upgrades.
based)?
How do you display the Lists the contents of the
unzip -l archive.zip
contents of a .zip file? specified zip file.
What command changes the Sets the default shell for the
chsh -s /bin/bash username
default shell for a user? specified user.
How do you check the status of Sends 4 ping requests to test
ping -c 4 google.com
a network connection? connectivity.
What command lists all Displays a list of valid login
cat /etc/shells
available shells? shells.
How do you display system Displays virtual memory
vmstat
performance metrics? statistics.
What command removes a Forcefully removes a directory
rm -rf directory_name
directory and its contents? and all its contents.
How do you check the current Retrieves the public IP
curl ifconfig.me
IP address? address.
What command lists the open Lists all open files for a
lsof -p PID
files of a process? specific process ID.
How do you run a command Schedules a command to run
* * * * * command
every minute with cron? every minute.
What command shows the
Lists all environment variables
environment variables for a env
for the current user.
user?
How do you display a file’s last Shows detailed timestamps
stat file.txt
access time? including last access time.
What command displays the Displays the user ID (UID) of
id -u
current user's UID? the current user.
Opens a new file in nano for
How do you create a script file? nano script.sh
scripting.
What command shows the
`ps aux wc -l`
number of processes running?
Question Answer Why
Displays the current boot log
How do you view the boot logs? journalctl -b
entries.
Shows available and used
What command checks
df -h disk space for each
available disk space?
filesystem.
How do you remove duplicate
`sort file.txt uniq`
lines from a file?
What command lists all active Displays all network
ip link show
network interfaces? interfaces and their statuses.
How do you find a specific Searches for a string in all
grep -r "string" /path
string in multiple files? files within a directory.
What command retrieves Lists detailed hardware
lshw
system hardware information? configuration information.
How do you change the Changes the system's
timedatectl set-timezone Zone
timezone? timezone.
What command checks for Checks for available updates
dnf check-update
updates (Fedora-based)? for installed packages.
How do you view running Shows user-specific services
services in a graphical systemctl --user running in a graphical
interface? interface.

https://www.linkedin.com/in/jbassim/

🌟 🚀
Support me and follow my LinkedIn profile for more insights and updates! Thanks for your
support.

You might also like