
Basic Commands and Concepts
- What is Linux?
- Answer: Linux is an open-source operating system kernel based on Unix. It is widely used for server environments, desktops, and embedded systems. Linux distributions combine the kernel with other software to form complete operating systems.
- What is a Linux distribution?
- Answer: A Linux distribution (or distro) is a complete operating system built around the Linux kernel. Examples include Ubuntu, CentOS, Fedora, and Debian. Each distribution includes the kernel, system libraries, and application software.
- How do you list files in a directory?
- Answer: Use the
ls
command. For example,ls -l
provides a detailed listing of files including permissions, owner, size, and modification date.
- Answer: Use the
- What does the
cd
command do?- Answer: The
cd
(change directory) command is used to navigate between directories in the file system.
- Answer: The
- How do you check the current working directory?
- Answer: Use the
pwd
(print working directory) command to display the full path of the current directory.
- Answer: Use the
- How do you create a new directory?
- Answer: Use the
mkdir
command followed by the name of the directory you want to create. For example,mkdir new_directory
.
- Answer: Use the
- How do you remove a file?
- Answer: Use the
rm
command followed by the name of the file. For example,rm file.txt
. Userm -r
to remove directories and their contents recursively.
- Answer: Use the
- What does the
cp
command do?- Answer: The
cp
command is used to copy files or directories from one location to another. For example,cp source.txt destination.txt
.
- Answer: The
- How do you move or rename a file?
- Answer: Use the
mv
command. For example,mv old_name.txt new_name.txt
renames a file, andmv file.txt /path/to/destination/
moves a file to a different directory.
- Answer: Use the
- How do you view the contents of a file?
- Answer: Use commands like
cat
,more
, orless
. For example,cat file.txt
displays the entire file content, whileless file.txt
allows for scrolling through the file.
- Answer: Use commands like
File Permissions and Ownership
- What do file permissions like
rwxr-xr-x
mean?- Answer: These permissions indicate read (r), write (w), and execute (x) permissions for the owner, group, and others. In
rwxr-xr-x
, the owner has full permissions, the group has read and execute permissions, and others have read and execute permissions.
- Answer: These permissions indicate read (r), write (w), and execute (x) permissions for the owner, group, and others. In
- How do you change file permissions?
- Answer: Use the
chmod
command. For example,chmod 755 file.txt
sets the permissions torwxr-xr-x
.
- Answer: Use the
- How do you change the ownership of a file?
- Answer: Use the
chown
command. For example,chown user:group file.txt
changes the ownership offile.txt
touser
andgroup
.
- Answer: Use the
- What does the
umask
command do?- Answer: The
umask
command sets default permissions for new files and directories. It determines the permissions that are not set when a new file or directory is created.
- Answer: The
- How do you find out which user you are currently logged in as?
- Answer: Use the
whoami
command to display the current user.
- Answer: Use the
System Information and Management
- How do you check the systemโs disk usage?
- Answer: Use the
df
command to check disk space usage. For example,df -h
provides human-readable sizes.
- Answer: Use the
- How do you check the memory usage on a Linux system?
- Answer: Use the
free
command to display memory usage. For example,free -h
provides human-readable sizes.
- Answer: Use the
- How do you display the running processes on a system?
- Answer: Use the
ps
command ortop
command. For example,ps aux
lists all running processes, whiletop
provides a real-time view.
- Answer: Use the
- What does the
uname
command do?- Answer: The
uname
command provides system information. For example,uname -a
displays all available system information including the kernel version.
- Answer: The
- How do you find the IP address of a Linux system?
- Answer: Use the
ip a
orifconfig
command. For example,ip a
shows detailed network information, including IP addresses.
- Answer: Use the
Networking and Connectivity
- How do you test network connectivity to a remote host?
- Answer: Use the
ping
command. For example,ping google.com
tests connectivity to Googleโs servers.
- Answer: Use the
- How do you check which ports are open on your Linux system?
- Answer: Use the
netstat -tuln
command orss -tuln
command to list open ports and listening services.
- Answer: Use the
- What is the
traceroute
command used for?- Answer: The
traceroute
command shows the path packets take from your system to a remote host, including intermediate routers.
- Answer: The
- How do you configure a static IP address on a Linux system?
- Answer: Edit the network configuration files, such as
/etc/network/interfaces
for Debian-based systems or/etc/sysconfig/network-scripts/ifcfg-eth0
for Red Hat-based systems, and set the static IP address configuration.
- Answer: Edit the network configuration files, such as
- What does the
route
command do?- Answer: The
route
command is used to display or modify the IP routing table. For example,route -n
shows the routing table.
- Answer: The
Package Management
- How do you install a package on a Debian-based system?
- Answer: Use the
apt-get
orapt
command. For example,sudo apt-get install package_name
.
- Answer: Use the
- How do you update the package list on a Red Hat-based system?
- Answer: Use the
yum
ordnf
command. For example,sudo yum update
orsudo dnf update
.
- Answer: Use the
- How do you remove a package on a Debian-based system?
- Answer: Use the
apt-get remove
orapt remove
command. For example,sudo apt-get remove package_name
.
- Answer: Use the
- How do you search for a package on a Linux system?
- Answer: Use the
apt-cache search
command on Debian-based systems oryum search
on Red Hat-based systems. For example,apt-cache search package_name
.
- Answer: Use the
- How do you list installed packages on a Debian-based system?
- Answer: Use the
dpkg -l
command to list all installed packages.
- Answer: Use the
System Configuration and Maintenance
- How do you check system logs on a Linux system?
- Answer: System logs are typically located in
/var/log
. Use commands likecat
,less
, ortail
to view log files. For example,cat /var/log/syslog
.
- Answer: System logs are typically located in
- How do you schedule tasks in Linux?
- Answer: Use the
cron
service to schedule recurring tasks. Edit the crontab file usingcrontab -e
to add scheduled tasks. For one-time tasks, use theat
command.
- Answer: Use the
- How do you change the hostname of a Linux system?
- Answer: Use the
hostnamectl
command to change the hostname. For example,sudo hostnamectl set-hostname new_hostname
.
- Answer: Use the
- What is
systemd
and how do you use it?- Answer:
systemd
is an init system and service manager used in many Linux distributions. Commands likesystemctl start service
,systemctl stop service
, andsystemctl status service
manage services.
- Answer:
- How do you add a new user to a Linux system?
- Answer: Use the
useradd
command followed by the username. For example,sudo useradd username
and set a password withsudo passwd username
.
- Answer: Use the
Security and Permissions
- How do you check the last logins on a Linux system?
- Answer: Use the
last
command to display a list of recent logins.
- Answer: Use the
- How do you lock and unlock a user account?
- Answer: Use
passwd -l username
to lock an account andpasswd -u username
to unlock it.
- Answer: Use
- What is the purpose of
sudo
?- Answer:
sudo
(superuser do) allows a permitted user to execute commands with superuser privileges or other usersโ privileges, as defined in the/etc/sudoers
file.
- Answer:
- How do you check the status of a service in Linux?
- Answer: Use the
systemctl status service_name
command to check the status of a service managed bysystemd
.
- Answer: Use the
- How do you manage file and directory permissions in Linux?
- Answer: Use the
chmod
command to change permissions,chown
to change ownership, andchgrp
to change group ownership.
- Answer: Use the
Advanced Topics
- What is a Linux kernel module?
- Answer: A kernel module is a piece of code that can be loaded into the kernel to extend its functionality, such as adding support for hardware or file systems.
- How do you load and unload kernel modules?
- Answer: Use
modprobe
to load or unload modules. For example,modprobe module_name
to load andmodprobe -r module_name
to unload.
- Answer: Use
- How do you view and configure system services in Linux?
- Answer: Use
systemctl
commands to manage and configure system services. For example,systemctl enable service_name
to enable a service at boot.
- Answer: Use
- What is the
lsof
command used for?- Answer: The
lsof
command lists open files and the processes using them. It helps in identifying which processes are accessing specific files or ports.
- Answer: The
- How do you create and manage disk partitions in Linux?
- Answer: Use tools like
fdisk
,parted
, orgparted
to create and manage disk partitions. For example,fdisk /dev/sda
to manage partitions on/dev/sda
.
- Answer: Use tools like
- What is the purpose of the
/etc/fstab
file?- Answer: The
/etc/fstab
file defines the file systems to be mounted at boot time and their mount options.
- Answer: The
- How do you monitor system performance in Linux?
- Answer: Use commands like
top
,htop
,vmstat
, andiostat
to monitor system performance metrics such as CPU, memory, and I/O usage.
- Answer: Use commands like
- How do you create a symbolic link in Linux?
- Answer: Use the
ln -s
command. For example,ln -s target_file symbolic_link
creates a symbolic link namedsymbolic_link
that points totarget_file
.
- Answer: Use the
- What is the
chmod
command used for?- Answer:
chmod
changes the file permissions of a file or directory. For example,chmod 755 file.txt
sets the permissions torwxr-xr-x
.
- Answer:
- How do you handle log rotation in Linux?
- Answer: Use the
logrotate
utility to manage log rotation. It compresses, rotates, and removes old log files based on configuration specified in/etc/logrotate.conf
and/etc/logrotate.d/
.
- Answer: Use the
Subscribe to QABash Weekly ๐ฅ
Dominate โ Stay Ahead of 99% Testers!