Post

Common Linux Commands

The Linux command line is a text interface to your computer. Often referred to as the shell, terminal, console, prompt or various other names, it can give the appearance of being complex and confusing to use. Yet the ability to copy and paste commands from a website, combined with the power and flexibility the command line offers, means that using it may be essential when trying to follow instructions online, including many on this very website!

File and Directory Management

  • ls - List directory contents
    1
    2
    3
    
    ls
    ls -l
    ls -a
    
  • cd - Change directory
    1
    2
    3
    
    cd /path/to/directory
    cd ..
    cd ~
    
  • pwd - Print working directory
    1
    
    pwd
    
  • mkdir - Create a new directory
    1
    2
    
    mkdir directory_name
    mkdir -p /path/to/directory
    
  • rmdir - Remove an empty directory
    1
    
    rmdir directory_name
    
  • rm - Remove files or directories
    1
    2
    
    rm file_name
    rm -r directory_name
    
  • cp - Copy files or directories
    1
    2
    
    cp source_file destination_file
    cp -r source_directory destination_directory
    
  • mv - Move or rename files or directories
    1
    2
    
    mv source_file destination_file
    mv old_directory_name new_directory_name
    
  • touch - Create an empty file or update the timestamp of an existing file
    1
    
    touch file_name
    
  • find - Search for files in a directory hierarchy
    1
    
    find /path/to/search -name "file_name"
    

File Viewing and Editing

  • cat - Concatenate and display file content
    1
    
    cat file_name
    
  • less - View file content one screen at a time
    1
    
    less file_name
    
  • more - View file content one screen at a time
    1
    
    more file_name
    
  • head - Display the first few lines of a file
    1
    2
    
    head file_name
    head -n 10 file_name
    
  • tail - Display the last few lines of a file
    1
    2
    
    tail file_name
    tail -n 10 file_name
    
  • nano - Simple text editor in the terminal
    1
    
    nano file_name
    
  • vi or vim - Advanced text editor in the terminal
    1
    2
    
    vi file_name
    vim file_name
    

System Information and Management

  • top - Display real-time system information
    1
    
    top
    
  • ps - Display information about active processes
    1
    2
    
    ps
    ps aux
    
  • df - Display disk space usage
    1
    2
    
    df
    df -h
    
  • du - Estimate file space usage
    1
    2
    3
    
    du
    du -h
    du -sh directory_name
    
  • free - Display memory usage
    1
    2
    
    free
    free -h
    
  • uname - Display system information
    1
    2
    
    uname
    uname -a
    

Networking

  • ping - Send ICMP ECHO_REQUEST to network hosts
    1
    
    ping host_name_or_ip
    
  • ifconfig - Configure a network interface (deprecated, use ip instead)
    1
    
    ifconfig
    
  • ip - Show/manipulate routing, devices, policy routing, and tunnels
    1
    2
    
    ip address
    ip link
    
  • netstat - Network statistics (deprecated, use ss instead)
    1
    
    netstat
    
  • ss - Utility to investigate sockets
    1
    2
    
    ss
    ss -tuln
    
  • scp - Securely copy files between hosts
    1
    
    scp source_file user@remote_host:/path/to/destination
    
  • wget - Non-interactive network downloader
    1
    
    wget url
    
  • lsof - List open files, useful to check ports
    1
    
    lsof -i :port_number
    
  • kill - Terminate a process by PID
    1
    2
    
    kill pid
    kill -9 pid
    

Package Management

  • apt-get - APT package handling utility (Debian/Ubuntu)
    1
    2
    3
    
    sudo apt-get update
    sudo apt-get install package_name
    sudo apt-get remove package_name
    
  • yum - Package manager (Red Hat/CentOS)
    1
    2
    3
    
    sudo yum update
    sudo yum install package_name
    sudo yum remove package_name
    
  • dnf - Package manager (Fedora)
    1
    2
    3
    
    sudo dnf update
    sudo dnf install package_name
    sudo dnf remove package_name
    

Permissions and Ownership

  • chmod - Change file modes or Access Control Lists
    1
    2
    
    chmod 755 file_name
    chmod -R 755 directory_name
    
  • chown - Change file owner and group
    1
    2
    
    chown user_name:group_name file_name
    chown -R user_name:group_name directory_name
    

Archiving and Compression

  • tar - Store, list, or extract files in an archive
    1
    2
    3
    4
    
    tar -cvf archive_name.tar directory_name
    tar -xvf archive_name.tar
    tar -czvf archive_name.tar.gz directory_name
    tar -xzvf archive_name.tar.gz
    
  • zip - Package and compress files
    1
    2
    
    zip archive_name.zip file1 file2
    zip -r archive_name.zip directory_name
    
  • unzip - Extract compressed files from a ZIP archive
    1
    
    unzip archive_name.zip
    

Miscellaneous

  • echo - Display a line of text
    1
    
    echo "Hello, World!"
    
  • date - Display or set the system date and time
    1
    2
    
    date
    date -s "2024-07-31 12:34:56"
    
  • whoami - Print the current user name
    1
    
    whoami
    
  • man - Display the manual for a command
    1
    
    man command_name
    
  • history - Display the command history
    1
    
    history
    
This post is licensed under CC BY 4.0 by the author.