Essential Linux Commands: A Comprehensive Reference

File and Directory Operations

  • ls: List files and directories alphabetically
  • ls -l: List file properties and attributes
  • ls -la: List files, including hidden system files
  • cd [directory name]: Change directory
  • cd [file name]: Change to the directory containing the file
  • mkdir [directory name]: Create a directory
  • rmdir [directory name]: Delete a directory
  • pwd: Display the current path
  • tree: Show the structure of directories and files graphically
  • cp [source] [destination]: Copy files
  • mv [source] [destination]: Move or rename files
  • rm [file name]: Delete files
  • rm -r [directory name]: Delete a directory recursively

Viewing File Contents

  • more [file name]: View file contents, paginated
  • ls -la | more: List files in a paged format
  • less [file name]: View file contents (similar to `more` but with more features)
  • cat [file name]: Display the entire contents of a file
  • cat [file1] [file2]: Concatenate and display multiple files
  • head -n [number] [file name]: Show the first (number) lines of a file
  • tail [file name]: Show the last lines of a file
  • tail -f [file name]: Display the last lines of a file dynamically (real-time updates)

File Manipulation

  • split: Split a file into smaller parts
  • touch [file name]: Change file timestamps
  • file [file name]: Determine file type
  • whatis [command]: Display a brief description of a command
  • wc [file name]: Count lines, words, or characters in a file
  • grep [pattern] [file name]: Search for a text pattern in a file
  • head [file name]: Display the beginning of a file
  • tail [file name]: Display the end of a file
  • tr: Replace characters in a text file
  • sed: Stream editor for text transformations
  • join: Join lines from two files based on a common field
  • paste: Merge lines from multiple files
  • uniq: Remove adjacent duplicate lines
  • cut: Select columns or fields from a file
  • ln [target] [link name]: Create links to files or folders
  • diff [file1] [file2]: Show differences between two files

File Permissions and Ownership

  • chmod [permissions] [file/directory]: Change file permissions
  • chmod g-w hello: Example to remove write permission for the group
  • chown [user] [file/directory]: Change file or directory owner
  • chgrp [group] [file/directory]: Change group ownership (use `-R` for recursive changes)

User Management

  • adduser [username]: Add a new user
  • useradd [username]: Add a new user (alternative)
  • userdel [username]: Remove a user
  • passwd [username]: Change a user’s password
  • whoami: Display the current login name
  • logname: Show the user’s login name
  • id [username]: Display user identification data
  • finger [username]: Display user information
  • chfn [username]: Change finger information
  • w: Show who is logged in and what they are doing
  • last: Display information about past user logins

System Information and Processes

  • top: Display and manage running processes in real-time
  • ps: Display a list of user processes
  • ps aux: Display a list of all processes
  • kill [process ID]: Terminate a process by its ID
  • killall [process name]: Terminate processes by name
  • time [command]: Measure the execution time of a command
  • fg: Bring a background process to the foreground
  • bg: Put a process in the background
  • &: Place at the end of a command line to run it in the background
  • nice [priority] [command]: Set the priority of a process (-20 to 19)
  • uptime: Show how long the system has been running
  • dmesg: Display kernel boot messages
  • history: Show command history
  • uname: Display operating system information
  • hostname: Display the server’s hostname
  • free: Display memory status
  • date: Show the current date and time
  • cal: Display a calendar
  • clear: Clear the terminal screen
  • env: Display environment variables
  • export: Make variables available in subshells

Disk and File System Management

  • mount [device] [mount point]: Mount a disk or device
  • mount /dev/fd0 /mnt/floppy: Example to mount a floppy drive
  • mount /mnt/cdrom: Example to mount a CD-ROM
  • umount [mount point]: Unmount a disk or device
  • df: Display disk space usage
  • du: Display disk space used by directories or files
  • mkfs [file system type] [device]: Format a disk
  • fsck [device]: Check and repair a file system
  • fdisk [device]: Manage disk partitions

Networking

  • rlogin [hostname]: Remote login to another machine
  • rsh [hostname]: Remote shell connection to another machine
  • ftp [hostname]: Connect to another machine via FTP
  • ping [hostname or IP]: Test network connectivity
  • nslookup [hostname]: Query DNS for IP address information
  • telnet [hostname or IP]: Connect to a remote computer via Telnet
  • netconf: Configure network settings
  • ntop: Display network traffic
  • route -n: Display the routing table
  • netstat: Display network status
  • ifconfig: Display network interface configuration
  • iwconfig: Display wireless network interface configuration
  • nmap [hostname or IP]: Scan the network for open ports

Package Management

  • rpm -i [package name]: Install an RPM package
  • dpkg -i [package name]: Install a Debian package

Kernel and Modules

  • lspci: Display PCI device information
  • lsmod: Display loaded kernel modules
  • modprobe [module name]: Load a kernel module
  • insmod [module name]: Insert a module into the kernel
  • rmmod [module name]: Remove a kernel module
  • updatedb: Update the file location database
  • kernelcfg: Manage kernel modules
  • make config: Configure the kernel
  • make xconfig: Configure the kernel using a graphical interface

Other Utilities

  • mail: Send and receive email
  • mesg [y/n]: Enable or disable receiving messages
  • wall [message]: Send a message to all logged-in users
  • talk [username]: Initiate a text-based chat with another user
  • banner [text]: Display a large text banner
  • bc: Command-line calculator
  • mc: Midnight Commander (file manager)
  • xkill: Terminate a graphical window
  • startx: Start the X Window System
  • xev: Display X events (keyboard and mouse)
  • setxkbmap: Configure keyboard layout
  • alias [name]='[command]’: Create an alias for a command
  • unalias [name]: Remove an alias
  • tee: Redirect output to both standard output and a file
  • find / -name [pattern] -print: Find files by a pattern
  • locate [file name]: Find files by name (uses a database)
  • whereis [command]: Locate the binary, source, and manual page files for a command
  • fuser [file or resource]: Identify processes using a file or resource
  • dump / restore: Backup and restore data

Compression and Archiving

  • gzip [file name]: Compress a file (creates a .gz file)
  • gunzip [file name.gz]: Decompress a .gz file
  • compress [file name]: Compress a file (creates a .Z file)
  • uncompress [file name.Z]: Decompress a .Z file
  • tar xvf [file name.tar]: Extract files from a .tar archive

System Shutdown and Restart

  • halt: Shut down the system
  • reboot: Restart the system
  • shutdown: Shut down or restart the system
  • init 0: Shut down the system
  • init 6: Restart the system
  • logout: Log out of the current session
  • nohup [command] &: Run a command immune to hangups and logout

Printers

  • lpq: Display print queue status
  • lpc: Printer control program
  • lprm [job ID]: Remove a print job
  • printtool: Configure printers
  • pr: Format and paginate files for printing

Keyboard Shortcuts

  • Ctrl + L: Clear the screen
  • Ctrl + Alt + F1/F2: Switch to virtual consoles
  • Ctrl + F1/F2: Switch between desktops (in a graphical environment)
  • Ctrl + Z: Suspend a process
  • Ctrl + D: End of file (EOF) or exit
  • Ctrl + C: Terminate a process
  • Tab: Autocomplete file or directory names
  • Ctrl + Backspace: Close the X Window System

Additional Notes

  • su [username]: Switch to another user (requires the user’s password)
  • sudo [command]: Execute a command with root privileges