Basic Linux Terminal Commands

File & Directory Commands

  • ls: List directory contents.
  • cd directory_name: Change directory.
  • pwd: Print working directory.
  • mkdir directory_name: Create a directory.
  • rmdir directory_name: Remove an empty directory.
  • cat file: Display file content.
  • cp source destination: Copy files or directories.
  • mv source destination: Move or rename files or directories.
  • stat file: Display file or file system status.
  • stat -f file: Display file system status.
  • wc -c file: Count bytes in a file.
  • zcat file.gz: Display content of a gzipped file.
  • tar -xf filename: Extract files from a tar archive.
  • rm -rf directory_name: Remove a directory and its contents recursively and forcefully.

System Information

  • df: Display disk space usage.
  • lspci: Display PCI hardware information.
  • uname -a: Display kernel information.
  • cat /proc/version: Display kernel version and compiler.
  • cat /proc/modules: List loaded kernel modules.
  • cat /proc/meminfo: Display memory information.
  • cat /proc/cpuinfo: Display CPU information.
  • cat /proc/devices: Display device information.
  • dmesg: Display kernel ring buffer messages.
  • hostname: Display system hostname.
  • date: Display or set the system date and time.
  • date -u: Display date and time in UTC.
  • cal: Display a calendar.
  • uptime: Display system uptime, users, and load average.
  • tty: Print the terminal file name.

Process Management

  • ps aux: Display running processes.
  • top: Display dynamic process information. (Press ‘z’ for color)
  • pstree: Display processes in a tree format.
  • kill PID: Send signal to process ID. Example: kill 8088
  • Ctrl + C: Interrupt/terminate a running process.
  • Ctrl + Z: Suspend a process.

System Control & Shutdown

  • poweroff or sudo init 0: Shut down the system.
  • reboot or init 6: Restart the system.
  • Ctrl + Alt + F[1-6]: Switch to a virtual terminal (TTY).
  • Ctrl + Alt + Del: Initiate system shutdown/reboot (behavior configurable).

Text Editing (Vi)

  • vi file: Edit a file using Vi editor.
  • :wq (in Vi): Save changes and exit.
  • :q! (in Vi): Exit without saving changes.

Package Management

  • apt-get update: Update package list (Debian/Ubuntu).
  • apt-get upgrade: Upgrade installed packages (Debian/Ubuntu).
  • yum list installed | less: List installed packages using yum, paginated (RHEL/CentOS).
  • rpm -i package.rpm: Install an RPM package.
  • rpm -e package_name: Uninstall an RPM package.
  • rpm -U package.rpm: Upgrade an RPM package.

Networking (SysVinit)

  • /etc/init.d/networking start: Start networking service.
  • /etc/init.d/networking restart: Restart networking service.
  • /etc/init.d/networking stop: Stop networking service.

User Management

  • su: Switch user (default to root).
  • su username: Switch to specified user.
  • passwd: Change user password.
  • who -H: Display who is logged in with headers.
  • users: Display usernames of logged-in users.
  • id: Display user and group information.

Help & History

  • man command: Display the manual page for a command.
  • man –help: Display help for the man command.
  • info command: Display info page for a command.
  • history: Display command history.
  • fc -l: List recent commands.

Utilities

  • clear: Clear the terminal screen.
  • bc: Open the arbitrary precision calculator.
  • quit (in bc): Exit bc.
  • eject cdrom: Open the CD-ROM tray.
  • eject -t cdrom: Close the CD-ROM tray.

Viewing File Content

  • less file: Display file content page by page.
  • more file: Display file content page by page.
  • cat file | less: Display file content page by page using less.
  • cat file | more: Display file content page by page using more.

Terminal Control

  • Ctrl + S: Pause terminal output.
  • Ctrl + Q: Resume terminal output.