Learn Linux CLI Commands

For experienced candidates, acing Linux interview questions is key to standing out. Focus on Linux interview questions for 5 years experience, which often cover advanced topics like system administration, performance tuning, and security. Be prepared for detailed queries on Linux commands and practical applications. Mastering these Linux commands interview questions will highlight your expertise and increase your chances of success.

  1. ls: List files and directories in the current directory.
    Description: Displays a list of files and directories in the current working directory.
    Example:
    ls
    Shows the files and directories in the current directory.

  1. cd: Change directory.
    Description: Moves to a different directory.
    Example:
    cd /path/to/directory
    Changes the current directory to /path/to/directory.

  1. pwd: Print the current working directory.
    Description: Displays the full path of the current working directory.
    Example:
    pwd
    Outputs the path of the current directory.

  1. mkdir: Create a new directory.
    Description: Creates a new directory with the specified name.
    Example:
    mkdir new_directory
    Creates a new directory named new_directory.

  1. rm: Remove files and directories.
    Description: Deletes specified files or directories.
    Example:
    rm file.txt
    Removes the file named file.txt.

  1. cp: Copy files and directories.
    Description: Copies files or directories from one location to another.
    Example:
    cp file.txt /path/to/destination
    Copies file.txt to /path/to/destination.

  1. mv: Move or rename files and directories.
    Description: Moves or renames files or directories.
    Example:
    mv file.txt /path/to/destination
    Moves file.txt to /path/to/destination.

  1. touch: Create an empty file.
    Description: Creates a new empty file or updates the timestamp of an existing file.
    Example:
    touch file.txt
    Creates an empty file named file.txt.

  1. cat: Display the contents of a file.
    Description: Shows the contents of a file in the terminal.
    Example:
    cat file.txt
    Displays the contents of file.txt.

  1. grep: Search for a pattern in a file.
    Description: Searches for a specified pattern in a file and displays matching lines.
    Example:
    grep "pattern" file.txt
    Finds lines containing pattern in file.txt.

  1. head: Display the first few lines of a file.
    Description: Shows the beginning portion of a file.
    Example:
    head file.txt
    Displays the first 10 lines of file.txt.

  1. tail: Display the last few lines of a file.
    Description: Shows the end portion of a file.
    Example:
    tail file.txt
    Displays the last 10 lines of file.txt.

  1. chmod: Change the permissions of a file or directory.
    Description: Modifies file or directory permissions.
    Example:
    chmod 755 file.txt
    Sets permissions for file.txt to rwxr-xr-x.

  1. chown: Change the ownership of a file or directory.
    Description: Alters the owner and/or group of a file or directory.
    Example:
    chown user:group file.txt
    Changes ownership of file.txt to user and group group.

  1. ln: Create a symbolic link to a file.
    Description: Creates a link to a file that points to another file or directory.
    Example:
    ln -s /path/to/file link
    Creates a symbolic link named link pointing to /path/to/file.

  1. find: Search for files and directories.
    Description: Locates files and directories based on specified criteria.
    Example:
    find /path/to/search -name "pattern"
    Searches for files matching pattern in /path/to/search.

  1. tar: Archive files and directories.
    Description: Combines multiple files or directories into a single archive file.
    Example:
    tar -czvf archive.tar.gz files/
    Creates a compressed archive archive.tar.gz of the files/ directory.

  1. unzip: Extract files from a zip archive.
    Description: Unpacks files from a zip archive.
    Example:
    unzip archive.zip
    Extracts the contents of archive.zip.

  1. man: Display the manual page/Help of a command.
    Description: Shows the manual or help documentation for a command.
    Example:
    man ls
    Displays the manual page for the ls command.

  1. history: View command history.
    Description: Shows a list of previously executed commands.
    Example:
    history
    Lists the command history for the current session.

  1. ps: Display currently running processes.
    Description: Lists currently active processes.
    Example:
    ps aux
    Displays detailed information about all running processes.

  1. kill: Terminate a process.
    Description: Sends a signal to terminate a process by its process ID (PID).
    Example:
    kill PID
    Sends a termination signal to the process with ID PID.

  1. df: Display disk space usage.
    Description: Shows the amount of disk space used and available on filesystems.
    Example:
    df -h
    Displays disk space usage in a human-readable format.

  1. du: Estimate file and directory sizes.
    Description: Displays the disk usage of files and directories.
    Example:
    du -sh directory
    Shows the total size of directory.

  1. scp: Copy files between hosts securely.
    Description: Securely transfers files between local and remote hosts.
    Example:
    scp file.txt user@remote:/path/to/destination
    Copies file.txt to /path/to/destination on remote server.

  1. ssh: Connect to a remote host securely.
    Description: Provides a secure command-line interface to a remote host.
    Example:
    ssh user@host
    Connects to host as user.

  1. ping: Send ICMP echo requests to a host.
    Description: Checks connectivity to a network host.
    Example:
    ping google.com
    Sends ping requests to google.com.

  1. ifconfig: Display network interface information.
    Description: Shows details about network interfaces.
    Example:
    ifconfig
    Lists network interfaces and their configurations.

  1. wget: Download files from the web.
    Description: Retrieves files from the web.
    Example:
    wget https://example.com/file.txt
    Downloads file.txt from example.com.

  1. curl: Transfer data from or to a server.
    Description: Transfers data using various protocols.
    Example:
    curl https://example.com
    Fetches the content from https://example.com.

  1. top: Display system resource usage and running processes.
    Description: Monitors system performance and process activity in real-time.
    Example:
    top
    Shows real-time system resource usage.

  1. apt-get: Package manager for Debian-based distributions.
    Description: Manages packages for Debian-based systems.
    Example:
    apt-get install package
    Installs the specified package.

  1. yum: Package manager for Red Hat-based distributions.
    Description: Manages packages for Red Hat-based systems.
    Example:
    yum install package
    Installs the specified package.

  1. systemctl: Control system services.
    Description: Manages system services using systemd.
    Example:
    systemctl start service
    Starts the specified service.

  1. journalctl: Query and display system logs.
    Description: Views and manages logs collected by systemd.
    Example:
    journalctl -u service
    Displays logs for the specified service.

  1. sed: Stream editor for text manipulation.
    Description: Edits text streams based on patterns.
    Example:
    sed 's/old/new/' file.txt
    Replaces occurrences of old with new in file.txt.

  1. awk: Text processing and pattern scanning.
    Description: Performs text processing and pattern matching.
    Example:
    awk '{print $1}' file.txt
    Prints the first column of file.txt.

  1. sort: Sort lines of text files.
    Description: Arranges lines of text files in order.
    Example:
    sort file.txt
    Sorts the lines of file.txt alphabetically.

  1. uniq: Report or omit repeated lines.
    Description: Removes duplicate lines from sorted files.
    Example:
    uniq file.txt
    Removes adjacent duplicate lines from file.txt.

  1. gzip: Compress files.
    Description: Reduces the size of files using the gzip compression format.
    Example:
    gzip file.txt
    Compresses file.txt into file.txt.gz.

  1. gunzip: Decompress files.
    Description: Expands files compressed with gzip.
    Example:
    gunzip file.txt.gz
    Decompresses file.txt.gz to file.txt.

  1. ssh-keygen: Generate SSH keys.
    Description: Creates a new SSH key pair for secure connections.
    Example:
    ssh-keygen -t rsa
    Generates a new RSA SSH key pair.

  1. ssh-copy-id: Copy SSH public key to a remote host.
    Description: Adds the SSH public key to the remote host’s authorized keys.
    Example:
    ssh-copy-id user@host
    Copies the public key to host for user user.

  1. mount: Mount a file system.
    Description: Attaches a filesystem to the system’s file hierarchy.
    Example:
    mount /dev/sdb1 /mnt
    Mounts the device /dev/sdb1 at the /mnt directory.

  1. umount: Unmount a file system.
    Description: Detaches a filesystem from the file hierarchy.
    Example:
    umount /mnt
    Unmounts the filesystem mounted at /mnt.

  1. lsblk: List block devices.
    Description: Displays information about block devices.
    Example:
    lsblk
    Lists all block devices and their mount points.

  1. fdisk: Partition table manipulator for disks.
    Description: Manages disk partitions.
    Example:
    fdisk /dev/sdb
    Opens the partition editor for disk /dev/sdb.

  1. date: Display the current date and time.
    Description: Shows or sets the system date and time.
    Example:
    date
    Outputs the current date and time.

  1. echo: Print text or variables.
    Description: Outputs text or variable values to the terminal.
    Example:
    echo "Hello, World!"
    Prints Hello, World! to the terminal.

  1. tee: Read from standard input and write to standard output and files.
    Description: Directs output to both the terminal and a file.
    Example:
    echo "Hello" | tee file.txt
    Writes Hello to both the terminal and file.txt.

  1. nc: Read and write data across network connections.
    Description: Provides network connectivity for reading and writing data.
    Example:
    echo "Hello" | nc host port
    Sends Hello to host on port.

  1. basename: Strip directory and suffix from filenames.
    Description: Extracts the filename from a path.
    Example:
    basename /path/to/file.txt
    Returns file.txt from the path.

  1. dirname: Strip the last component from file names.
    Description: Extracts the directory path from a filename.
    Example:
    dirname /path/to/file.txt
    Returns /path/to from the path.

  1. uptime: Display system uptime.
    Description: Shows how long the system has been running.
    Example:
    uptime
    Displays the system’s uptime and load averages.

  1. whoami: Print the current username.
    Description: Shows the username of the currently logged-in user.
    Example:
    whoami
    Outputs the current username.

  1. su: Switch user.
    Description: Changes the current user to another user.
    Example:
    su username
    Switches to the user username.

  1. sudo: Execute a command as a superuser.
    Description: Runs commands with superuser privileges.
    Example:
    sudo command
    Executes command with root privileges.

  1. useradd: Create a new user account.
    Description: Adds a new user account to the system.
    Example:
    useradd username
    Creates a new user named username.

  1. passwd: Change user password.
    Description: Updates the password for a user account.
    Example:
    passwd username
    Changes the password for username.

  1. groupadd: Create a new group.
    Description: Adds a new group to the system.
    Example:
    groupadd groupname
    Creates a new group named groupname.

  1. usermod: Modify user account.
    Description: Alters user account settings.
    Example:
    usermod -aG groupname username
    Adds username to groupname.

  1. groups: Display group membership for a user.
    Description: Lists the groups a user belongs to.
    Example:
    groups username
    Shows the groups of username.

  1. chgrp: Change group ownership of a file or directory.
    Description: Changes the group ownership of a file or directory.
    Example:
    chgrp groupname file.txt
    Changes the group ownership of file.txt to groupname.

  1. wc: Count lines, words, and characters in files.
    Description: Counts lines, words, and characters in a file.
    Example:
    wc file.txt
    Shows the number of lines, words, and characters in file.txt.

  1. free: Display free and used memory in the system.
    Description: Shows memory usage and availability.
    Example:
    free -h
    Displays memory usage in a human-readable format.

  1. whereis: Locate the binary, source, and manual page files for a command.
    Description: Finds the location of a command’s binary, source, and manual pages.
    Example:
    whereis ls
    Provides locations of ls binary, source, and manual.

  1. cmp: Compare two files byte by byte.
    Description: Compares two files byte by byte and reports differences.
    Example:
    cmp file1.txt file2.txt
    Compares file1.txt and file2.txt byte by byte.

  1. diff: Compare files line by line.
    Description: Shows differences between two files line by line.
    Example:
    diff file1.txt file2.txt
    Displays line-by-line differences between file1.txt and file2.txt.

  1. shutdown: Shutdown or restart the system.
    Description: Powers off or restarts the system.
    Example:
    shutdown -h now
    Immediately shuts down the system.

  1. reboot: Reboot the system.
    Description: Restarts the system.
    Example:
    reboot
    Reboots the system immediately.

  1. ip: Show or manipulate routing, devices, policy routing, and tunnels.
    Description: Provides detailed network configuration and management.
    Example:
    ip addr show
    Displays information about network interfaces and their addresses.

  1. traceroute: Print the route packets take to a network host.
    Description: Traces the path packets take to reach a network host.
    Example:
    traceroute google.com
    Shows the path packets take to google.com.

  1. netstat: Print network connections, routing tables, and interface statistics.
    Description: Displays network connections and interface statistics.
    Example:
    netstat -tuln
    Shows network connections and listening ports.

  1. lsof: List open files.
    Description: Displays information about files opened by processes.
    Example:
    lsof
    Lists all open files and their associated processes.

  1. strace: Trace system calls and signals.
    Description: Monitors system calls and signals used by a process.
    Example:
    strace command
    Traces system calls and signals for command.

  1. perf: Performance analysis tool.
    Description: Provides performance monitoring and analysis.
    Example:
    perf top
    Displays a real-time performance monitoring view.

  1. tmux: Terminal multiplexer.
    Description: Allows multiple terminal sessions within a single window.
    Example:
    tmux
    Starts a new tmux session.

  1. screen: Terminal multiplexer.
    Description: Manages multiple terminal sessions in one window.
    Example:
    screen
    Starts a new screen session.

  1. chmod: Change file modes or Access Control Lists.
    Description: Modifies the permissions of files or directories.
    Example:
    chmod 644 file.txt
    Sets read and write permissions for the owner, and read-only permissions for others.

  1. stat: Display file or file system status.
    Description: Shows detailed information about a file or filesystem.
    Example:
    stat file.txt
    Provides detailed status information for file.txt.

  1. file: Determine file type.
    Description: Identifies the type of a file based on its content.
    Example:
    file file.txt
    Displays the file type of file.txt.

  1. alias: Create or view command aliases.
    Description: Defines shortcuts for longer commands.
    Example:
    alias ll='ls -la'
    Creates an alias ll for ls -la.

  1. unalias: Remove command aliases.
    Description: Deletes previously defined command aliases.
    Example:
    unalias ll
    Removes the alias ll.

  1. export: Set environment variables.
    Description: Defines environment variables for the current shell session.
    Example:
    export PATH=$PATH:/new/path
    Adds /new/path to the PATH environment variable.

  1. env: Display or set environment variables.
    Description: Shows or sets environment variables.
    Example:
    env
    Lists all environment variables.

  1. printenv: Print environment variables.
    Description: Displays the value of environment variables.
    Example:
    printenv PATH
    Shows the value of the PATH variable.

  1. source: Execute commands from a file in the current shell.
    Description: Runs commands from a file in the current shell environment.
    Example:
    source ~/.bashrc
    Reloads the .bashrc file in the current shell session.

  1. set: Set or unset shell options and positional parameters.
    Description: Configures shell options and parameters.
    Example:
    set -x
    Enables debugging mode in the shell.

  1. unset: Unset shell variables or functions.
    Description: Removes shell variables or functions.
    Example:
    unset VAR
    Deletes the shell variable VAR.

  1. xargs: Build and execute command lines from standard input.
    Description: Constructs and executes command lines from input.
    Example:
    find . -name '*.txt' | xargs rm
    Deletes all .txt files found in the current directory and subdirectories.

  1. crontab: Schedule periodic tasks.
    Description: Manages cron jobs for scheduled tasks.
    Example:
    crontab -e
    Edits the cron table for scheduling tasks.

  1. at: Schedule one-time tasks.
    Description: Schedules tasks to be run once at a specified time.
    Example:
    at 3pm
    Enters the at command prompt to schedule a task for 3 PM.

  1. jobs: List active jobs.
    Description: Displays jobs running in the background or stopped.
    Example:
    jobs
    Lists active jobs in the current shell.

  1. bg: Resume a suspended job in the background.
    Description: Continues a job in the background.
    Example:
    bg %1
    Resumes job number 1 in the background.

  1. fg: Bring a background job to the foreground.
    Description: Moves a background job to the foreground.
    Example:
    fg %1
    Brings job number 1 to the foreground.

  1. killall: Terminate processes by name.
    Description: Sends a signal to terminate all processes with a specific name.
    Example:
    killall processname
    Kills all processes named processname.

  1. pkill: Send signals to processes based on name and other attributes.
    Description: Sends a signal to processes matching criteria.
    Example:
    pkill -f pattern
    Kills processes matching pattern.

  1. ps aux: List all running processes with detailed information.
    Description: Provides a detailed list of all processes running on the system.
    Example:
    ps aux
    Lists all processes with detailed information.

  1. df -T: Show filesystem types.
    Description: Displays disk usage and filesystem types for mounted filesystems.
    Example:
    df -T
    Shows filesystem types and disk usage.

  1. uptime: Show how long the system has been running.
    Description: Displays the system’s uptime, number of users, and load averages.
    Example:
    uptime
    Shows how long the system has been up and its load averages.