Linux Commands - List of Linux Command and there uses...

 

Comprehensive list of common Linux commands and their uses. This list includes basic commands for file manipulation, system monitoring, and more. Note that Linux commands can vary slightly between distributions and versions.

File and Directory Operations

  • ls: List directory contents.

    • ls -l: Long format.
    • ls -a: Include hidden files.
  • cd: Change directory.

    • cd ..: Move up one directory.
  • pwd: Print working directory.

  • mkdir: Make directories.

    • mkdir -p path/to/directory: Create nested directories.
  • rmdir: Remove empty directories.

  • rm: Remove files or directories.

    • rm -r directory: Remove directories and their contents.
    • rm -f file: Force removal without prompting.
  • cp: Copy files or directories.

    • cp file1 file2: Copy file1 to file2.
    • cp -r dir1 dir2: Copy directory dir1 to dir2.
  • mv: Move or rename files or directories.

    • mv file1 file2: Rename file1 to file2.
    • mv file dir/: Move file to directory dir.
  • touch: Create an empty file or update the timestamp of an existing file.

  • find: Search for files in a directory hierarchy.

    • find /path -name filename: Search for files by name.
  • locate: Find files by name using a database.

    • locate filename: Locate files matching the name.
  • updatedb: Update the database used by locate.

  • grep: Search for text in files using patterns.

    • grep pattern file: Search for pattern in file.
  • cat: Concatenate and display file content.

    • cat file: Display file content.
  • more: View file content one page at a time.

    • more file: View file content interactively.
  • less: View file content with backward and forward navigation.

    • less file: View file content interactively.
  • head: Display the beginning of a file.

    • head -n 10 file: Show the first 10 lines.
  • tail: Display the end of a file.

    • tail -n 10 file: Show the last 10 lines.
    • tail -f file: Follow the end of a file (useful for logs).
  • diff: Compare files line by line.

    • diff file1 file2: Show differences between two files.
  • chmod: Change file permissions.

    • chmod 755 file: Set file permissions.
  • chown: Change file owner and group.

    • chown user:group file: Change owner and group of file.
  • stat: Display file or filesystem status.

    • stat file: Show detailed file information.

System Information and Management

  • uname: Print system information.

    • uname -a: Print all available system information.
  • top: Display real-time system processes and resource usage.

  • htop: Interactive process viewer (requires installation).

  • ps: Report process status.

    • ps aux: Show detailed information about all processes.
  • df: Report disk space usage.

    • df -h: Show disk usage in human-readable format.
  • du: Estimate file space usage.

    • du -sh directory: Show total size of directory.
  • free: Display memory usage.

    • free -h: Show memory usage in human-readable format.
  • uptime: Show how long the system has been running.

  • shutdown: Shut down or restart the system.

    • shutdown -h now: Shut down immediately.
    • shutdown -r now: Restart immediately.
  • reboot: Restart the system.

  • dmesg: Print kernel ring buffer messages.

Networking

  • ifconfig: Configure network interfaces (deprecated, use ip instead).

  • ip: Show/manipulate routing, devices, and tunnels.

    • ip addr: Show network interfaces and their IP addresses.
    • ip link: Show network device status.
  • ping: Send ICMP ECHO_REQUEST to network hosts.

    • ping host: Check connectivity to a host.
  • traceroute: Trace the route packets take to a network host.

    • traceroute host: Show the route packets take.
  • netstat: Print network connections, routing tables, and interface statistics.

    • netstat -tuln: Show listening ports and their addresses.
  • ss: Utility to investigate sockets.

    • ss -tuln: Show listening sockets.
  • wget: Download files from the web.

    • wget url: Download file from URL.
  • curl: Transfer data from or to a server.

    • curl -O url: Download file from URL.

User and Group Management

  • whoami: Print the current logged-in user.

  • id: Print user and group information.

    • id user: Show user ID and group IDs.
  • useradd: Add a new user.

    • useradd username: Create a new user.
  • usermod: Modify a user account.

    • usermod -aG group username: Add user to a group.
  • userdel: Delete a user account.

    • userdel username: Remove a user account.
  • groupadd: Add a new group.

    • groupadd groupname: Create a new group.
  • groupdel: Delete a group.

    • groupdel groupname: Remove a group.

Package Management

  • apt-get (Debian/Ubuntu): Package handling utility.

    • apt-get update: Update package lists.
    • apt-get install package: Install a package.
    • apt-get remove package: Remove a package.
  • yum (CentOS/RedHat): Package manager.

    • yum update: Update all packages.
    • yum install package: Install a package.
    • yum remove package: Remove a package.
  • dnf (Fedora): Next-generation package manager.

    • dnf install package: Install a package.
    • dnf remove package: Remove a package.
  • zypper (openSUSE): Command-line interface of ZYpp package manager.

    • zypper install package: Install a package.
    • zypper remove package: Remove a package.

Archiving and Compression

  • tar: Archive files.

    • tar -cvf archive.tar files: Create an archive.
    • tar -xvf archive.tar: Extract an archive.
    • tar -czvf archive.tar.gz files: Create a compressed archive.
    • tar -xzvf archive.tar.gz: Extract a compressed archive.
  • gzip: Compress files.

    • gzip file: Compress file to file.gz.
  • gunzip: Decompress files.

    • gunzip file.gz: Decompress file.gz.
  • bzip2: Compress files.

    • bzip2 file: Compress file to file.bz2.
  • bunzip2: Decompress files.

    • bunzip2 file.bz2: Decompress file.bz2.
  • zip: Package and compress files.

    • zip archive.zip files: Create a zip archive.
  • unzip: Extract zip files.

    • unzip archive.zip: Extract zip archive.

Permissions and Ownership

  • chmod: Change file permissions.

    • chmod 755 file: Set read, write, and execute permissions.
  • chown: Change file owner and group.

    • chown user:group file: Change owner and group.
  • chgrp: Change group ownership.

    • chgrp group file: Change the group of a file.

System Monitoring

  • top: Display real-time system processes.

  • htop: Interactive process viewer (requires installation).

  • iotop: Display I/O usage by processes (requires installation).

  • vmstat: Report virtual memory statistics.

  • sar: Collect, report, or save system activity information (part of sysstat package).

Text Processing

  • awk: Pattern scanning and processing language.

    • awk '{print $1}' file: Print the first column.
  • sed: Stream editor for filtering and transforming text.

    • sed 's/old/new/g' file: Replace 'old' with 'new' in file.
  • cut: Remove sections from each line of files.

    • cut -d',' -f1 file: Extract the first field from a comma-separated file.
  • sort: Sort lines of text files.

    • sort file: Sort the contents of file.
  • uniq: Report or remove duplicate lines.

    • uniq file: Remove duplicate lines from file.
  • tr: Translate or delete characters.

    • tr 'a-z' 'A-Z' < file: Convert lowercase to uppercase.

Shell Scripting

  • sh: Shell command interpreter.

    • sh script.sh: Run a shell script.
  • bash: Bourne Again Shell, an improved shell.

    • bash script.sh: Run a shell script.
  • source: Execute commands from a file in the current shell.

    • source script.sh: Run commands from script.sh in the current shell.

Miscellaneous

  • alias: Create or list aliases.

    • alias ll='ls -l': Create an alias.
  • history: Show command history.

  • man: Display the manual of a command.

    • man command: Show the manual for command.
  • echo: Display a line of text.

    • echo "Hello, World!": Print text to the terminal.
  • date: Display or set the system date and time.

    • date: Show the current date and time.
  • cal: Display a calendar.

    • cal: Show the current month's calendar.
  • clear: Clear the terminal screen.

System Administration

  • systemctl: Control the systemd system and service manager.

    • systemctl start service: Start a service.
    • systemctl stop service: Stop a service.
    • systemctl status service: Check the status of a service.
  • journalctl: Query and display messages from the journal.

    • journalctl -xe: Show the most recent entries with errors.

This list covers many of the essential commands you'll use in a Linux environment. For more detailed information and additional commands, you can refer to the man pages (man command) or online documentation.

Previous Post Next Post