afm719 / Cloud-Computing-Arahi

0 stars 0 forks source link

Basic linux commands #7

Open afm719 opened 1 month ago

afm719 commented 1 month ago

Basic Commands

  1. pwd: Print the current working directory.
  2. ls: List files and directories in the current directory.
    • ls -l: List files in long format (detailed view).
    • ls -a: Show hidden files (those starting with .).
  3. cd: Change the current directory.
    • cd ..: Go up one directory.
    • cd ~: Go to the home directory.
  4. mkdir <directory_name>: Create a new directory.
  5. rmdir <directory_name>: Remove an empty directory.
  6. rm <file_name>: Remove a file.
    • rm -r <directory_name>: Remove a directory and its contents recursively.
  7. touch <file_name>: Create a new empty file or update the timestamp of an existing file.
  8. cp <source> <destination>: Copy files or directories.
    • cp -r <source_directory> <destination_directory>: Copy a directory recursively.
  9. mv <source> <destination>: Move or rename files or directories.
  10. cat <file_name>: Concatenate and display the contents of a file.
  11. less <file_name>: View the contents of a file one page at a time.
  12. head <file_name>: Display the first 10 lines of a file.
  13. tail <file_name>: Display the last 10 lines of a file.
    • tail -f <file_name>: Continuously monitor the end of a file for new lines.

System Information

  1. df -h: Show disk space usage in a human-readable format.
  2. du -h <directory_name>: Show disk usage of a directory and its subdirectories.
  3. top: Display active processes and system resource usage.
  4. htop: Enhanced version of top with a user-friendly interface (needs to be installed).
  5. uname -a: Display system information (kernel version, architecture, etc.).
  6. free -h: Show memory usage in a human-readable format.
  7. lscpu: Display information about the CPU architecture.

User Management

  1. whoami: Display the current logged-in user.
  2. adduser <username>: Create a new user.
  3. deluser <username>: Delete a user.
  4. passwd <username>: Change the password for a user.
  5. su <username>: Switch to another user (requires password).
  6. sudo <command>: Execute a command with superuser (admin) privileges.

Package Management (APT)

  1. sudo apt update: Update the package list.
  2. sudo apt upgrade: Upgrade installed packages to their latest versions.
  3. sudo apt install <package_name>: Install a new package.
  4. sudo apt remove <package_name>: Remove an installed package.
  5. sudo apt search <package_name>: Search for a package in the repositories.
  6. sudo apt show <package_name>: Show details about a package.

Networking

  1. ifconfig: Display network interfaces and their configurations (deprecated; use ip).
  2. ip a: Show all network interfaces and their IP addresses.
  3. ping <hostname>: Check connectivity to a host by sending ICMP echo requests.
  4. traceroute <hostname>: Show the route packets take to a network host.
  5. netstat -tuln: Display active network connections and listening ports.
  6. curl <url>: Fetch content from a URL.

File Permissions

  1. chmod <permissions> <file_name>: Change the permissions of a file or directory.
    • chmod 755 <file_name>: Set read, write, and execute permissions for the owner, and read and execute permissions for group and others.
  2. chown <user>:<group> <file_name>: Change the ownership of a file or directory.

Searching and Finding Files

  1. find <directory> -name <file_name>: Search for files in a directory hierarchy.
  2. grep <pattern> <file_name>: Search for a specific pattern in a file.
  3. locate <file_name>: Quickly find the location of a file (requires mlocate package to be installed).

System Control

  1. shutdown: Shut down the system.
    • shutdown -h now: Shut down immediately.
  2. reboot: Restart the system.
  3. systemctl <action> <service_name>: Control system services (start, stop, restart, enable, disable).

Miscellaneous

  1. history: Show the command history.
  2. clear: Clear the terminal screen.
  3. echo <text>: Display a line of text.
  4. man <command>: Display the manual page for a command, providing details on its usage.

File and Directory Operations

  1. find <directory> -type f -name <file_name>: Find files by name in a specific directory.
  2. find <directory> -type d -name <directory_name>: Find directories by name.
  3. cp -i <source> <destination>: Copy files with confirmation before overwriting.
  4. mv -i <source> <destination>: Move files with confirmation before overwriting.
  5. rm -i <file_name>: Remove a file with confirmation.
  6. mkdir -p <directory_path>: Create a directory and parent directories as needed.
  7. tree: Display a directory structure in a tree format (requires installation).
  8. rename <expression> <replacement> <files>: Rename files based on a regex expression (use with caution).

Text Processing

  1. sort <file_name>: Sort lines in a text file.
  2. uniq <file_name>: Report or omit repeated lines in a file.
  3. wc <file_name>: Count lines, words, and characters in a file.
  4. cut -d <delimiter> -f <field_number> <file_name>: Extract specific fields from a file.
  5. awk '{print $1}' <file_name>: Process and analyze text files (prints the first column).
  6. sed 's/<pattern>/<replacement>/' <file_name>: Stream editor for filtering and transforming text.

System Monitoring and Management

  1. vmstat: Report virtual memory statistics.
  2. iostat: Report CPU and I/O statistics (requires installation).
  3. mpstat: Show CPU usage (requires installation).
  4. uptime: Show how long the system has been running and load averages.
  5. ps aux: Display a snapshot of current processes with detailed information.
  6. kill <pid>: Terminate a process by its process ID.
  7. killall <process_name>: Terminate all processes by name.
  8. pkill <pattern>: Kill processes based on a pattern.

User and Group Management

  1. groups <username>: Display the groups a user belongs to.
  2. usermod -aG <group_name> <username>: Add a user to a group.
  3. chgrp <group_name> <file_name>: Change the group ownership of a file.
  4. visudo: Safely edit the sudoers file to manage user privileges.

Networking

  1. ifup <interface>: Bring a network interface up (e.g., ifup eth0).
  2. ifdown <interface>: Bring a network interface down (e.g., ifdown eth0).
  3. ip route: Show the routing table.
  4. nslookup <domain>: Query DNS to obtain domain name or IP address mapping.
  5. wget <url>: Download files from the web.
  6. scp <source> <destination>: Securely copy files between hosts over SSH.
  7. ssh <username>@<host>: Connect to a remote server via SSH.
  8. iptables -L: List firewall rules (requires sudo privileges).
  9. hostname: Display the current hostname of the system.
  10. curl -I <url>: Fetch the HTTP headers of a URL.

Disk and Filesystem Management

  1. lsblk: List all block devices (disks and partitions).
  2. fdisk -l: List disk partitions (requires sudo).
  3. mount <device> <mount_point>: Mount a filesystem.
  4. umount <mount_point>: Unmount a filesystem.
  5. fsck <device>: Check and repair a filesystem.
  6. dd if=<input_file> of=<output_file>: Convert and copy files (often used for disk images).
  7. truncate -s 0 <file_name>: Reduce the size of a file to zero bytes.
  8. xfs_repair <device>: Repair an XFS filesystem (requires the device to be unmounted).

Package Management (Advanced)

  1. sudo apt autoremove: Remove unnecessary packages that were automatically installed.
  2. sudo apt list --upgradable: List packages that can be upgraded.
  3. sudo dpkg -i <package.deb>: Install a .deb package manually.
  4. sudo dpkg --configure -a: Reconfigure packages that were not configured correctly.
  5. apt-cache search <package_name>: Search for a package in the repository cache.

Backup and Compression

  1. tar -czvf <archive_name>.tar.gz <directory>: Create a compressed tarball.
  2. tar -xzvf <archive_name>.tar.gz: Extract a compressed tarball.
  3. zip <zip_file>.zip <file1> <file2>: Create a zip archive.
  4. unzip <zip_file>.zip: Extract a zip archive.
  5. rsync -av <source> <destination>: Sync files and directories between locations.

Miscellaneous

  1. alias <shortcut>='<command>': Create an alias for a command.
  2. unalias <shortcut>: Remove an alias.
  3. date: Display the current date and time.
  4. cal: Show the calendar for the current month.
  5. bc: Basic calculator for mathematical operations.
  6. ssh-keygen: Generate SSH key pairs for secure authentication.

Permissions and Ownership

  1. chmod +x <file_name>: Make a script executable.
  2. stat <file_name>: Display detailed file or filesystem status.
  3. getfacl <file_name>: Get file access control lists (requires installation).
  4. setfacl -m u:<username>:rwx <file_name>: Set file access control lists for specific users.