Linux Commands

File Management

ls: List directory contents

List files in long format showing permissions, owner, group, size, and modification date:

Command: ls -l

List all files including hidden files:

Command: ls -a
cd: Change the current directory

Change to a directory relative to the current directory:

Command: cd ../subdirectory

Change to the previous directory:

Command: cd -
pwd: Print working directory

Print the current directory path:

Command: pwd

Print the current directory path without symbolic links:

Command: pwd -P
mkdir: Create a new directory

Create a directory with read, write, and execute permissions for the owner:

Command: mkdir -m 700 new_directory

Create a directory with parent directories as needed:

Command: mkdir -p path/to/new_directory
rm: Remove files or directories

Remove a file without prompting:

Command: rm -f file.txt

Remove a directory and its contents recursively:

Command: rm -r directory
cp: Copy files and directories

Copy a file, preserving mode, ownership, and timestamps:

Command: cp -p source_file destination_file

Copy a directory recursively:

Command: cp -r source_directory destination_directory
mv: Move or rename files and directories

Move a file to a new location:

Command: mv file.txt new_location/

Rename a file:

Command: mv old_file.txt new_file.txt
touch: Create an empty file or update the timestamp of an existing file

Create a new empty file:

Command: touch new_file.txt

Update the access and modification times of an existing file to the current time:

Command: touch -a -m existing_file.txt

File Permissions:

chmod: Change Permissions (Read, Write, Execute) for Users, Groups, Owners

Changing Permissions for a Script

Command: chmod +x script.sh

This Command: makes the script "script.sh" executable, allowing users to run it as a program.

Example 2: Restricting Access to a Configuration File

Command: chmod 600 config.ini

This Command: sets strict permissions on the "config.ini" file, allowing only the owner to read and write to it, while denying access to others.

chown: Changing Ownership of a Directory

Example 1: Changing Ownership of a Directory

Command: chown -R user1:group1 /var/www/html

This Command: changes the ownership of the "/var/www/html" directory and all its contents recursively to the user "user1" and the group "group1".

Example 2: Transferring Ownership of a File

Command: chown user2:group2 file.txt

This Command: changes the ownership of the file "file.txt" to "user2" and the group "group2".

chgrp: Changing Group Ownership of a Directory

Example 1: Changing Group Ownership of a Directory

Command: chgrp -R developers /var/www/project

This Command: changes the group ownership of the "/var/www/project" directory and all its contents to the "developers" group recursively.

Example 2: Assigning Group Ownership to a File

Command: chgrp admins file.txt

This Command: assigns the group ownership of the file "file.txt" to the "admins" group.

umask: Setting Default Permissions for Files

Example 1: Setting Default Permissions for Files

Command: umask 007

This Command: sets the default permissions for newly created files to allow full access for the owner and read/write permissions for the group and others.

Example 2: Configuring Default Permissions for Directories

Command: umask 022

This Command: sets the default permissions for newly created directories to allow full access for the owner and read-only access for the group and others.

Text Manipulation:

cat: Displaying File Contents

Example 1: Displaying File Contents

Command: cat filename.txt

This Command: displays the contents of the file "filename.txt" on the terminal.

Example 2: Concatenating Files

Command: cat file1.txt file2.txt > combined_file.txt

This Command: concatenates the contents of "file1.txt" and "file2.txt" into a new file named "combined_file.txt".

grep: Searching for a Pattern in a File

Example 1: Searching for a Pattern in a File

Command: grep "error" log.txt

This Command: searches for the word "error" in the file "log.txt" and displays all lines containing that pattern.

Example 2: Searching Recursively in Directory

Command: grep -r "pattern" /path/to/directory

This Command: recursively searches for the pattern "pattern" in all files within the specified directory.

sed: Replace Text in a File

Example 1: Replace Text in a File

Command: sed 's/old_text/new_text/' input.txt > output.txt

This Command: replaces occurrences of "old_text" with "new_text" in the file "input.txt" and writes the result to "output.txt".

Example 2: Deleting Lines Matching a Pattern

Command: sed '/pattern/d' file.txt > newfile.txt

This Command: deletes all lines containing the pattern "pattern" from "file.txt" and saves the result to "newfile.txt".

awk: Extracting Specific Columns from a CSV File

Example 1: Extracting Specific Columns from a CSV File

Command: awk -F',' '{print $1,$3}' data.csv

This Command: prints the first and third columns of each line in the CSV file "data.csv", with columns separated by a comma.

Example 2: Calculating Total Sales from a Sales Report

Command: awk '{sum+=$2} END {print "Total sales:", sum}' sales_report.txt

This Command: calculates the total sales by summing up the values in the second column of a sales report file "sales_report.txt".

head: Displaying First N Lines of a File

Example 1: Displaying First 10 Lines of a File

Command: head file.txt

This Command: displays the first 10 lines of the file "file.txt".

Example 2: Displaying First N Lines of a File

Command: head -n 20 file.txt

This Command: displays the first 20 lines of the file "file.txt".

tail: Displaying Last N Lines of a File

Example 1: Displaying Last 10 Lines of a File

Command: tail file.txt

This Command: displays the last 10 lines of the file "file.txt".

Example 2: Displaying Last N Lines of a File

Command: tail -n 5 file.txt

This Command: displays the last 5 lines of the file "file.txt".

System Information:

uname: Print system information

Example 1: Print detailed system information:

$ uname -a

This command is useful when you need comprehensive system information, including the kernel version, hardware architecture, and operating system details. It's commonly used for system diagnostics and troubleshooting.

Example 2: Display the machine hardware name

$ uname -m

This command specifically retrieves the machine hardware name, which can be helpful in scripting or when you need to identify the hardware architecture for compatibility purposes.

uptime: Show how long the system has been running

Example 1: Display system uptime and load averages

$ uptime

Usage: Administrators often use this command to quickly check the system's uptime and current load averages. It helps in monitoring system performance and determining if any resource constraints exist.

Example 2: Show system boot time and number of users logged in

$ uptime -p

Usage: This command provides a more concise view, particularly for checking when the system was last rebooted and how many users are currently logged in.

hostname: Print or set system name

Example 1: Print the hostname of the system

$ hostname

Usage: Retrieving the hostname is helpful when you need to identify the system within a network or when setting up network configurations.

Example 2: Set the hostname of the system

$ sudo hostnamectl set-hostname newhostname

Usage: Administrators might use this command to change the hostname of a system, which can be necessary during system setup or when reconfiguring network settings.

free: Display amount of free and used memory in the system

Example 1: Display memory usage in megabytes

$ free -m

Usage: This command provides a detailed breakdown of memory usage, helping administrators identify memory-intensive processes or potential memory leaks.

Example 2: Show memory usage in gigabytes and update every second

$ watch -n 1 free -g

Usage: By continuously monitoring memory usage in real-time, administrators can detect sudden spikes or unusual patterns, enabling proactive troubleshooting and optimization.

df: Report file system disk space usage

Example 1: Display disk space usage for all mounted filesystems

$ df -h

Usage: This command is crucial for monitoring disk space utilization across all mounted filesystems, helping administrators identify potential disk space constraints and plan for storage expansion if necessary.

Example 2: Show disk space usage only for a specific filesystem

$ df -T /mnt/data

Usage: When focusing on a specific filesystem, such as a data partition or a mounted network share, this command provides targeted information for capacity planning and resource allocation.

Process Management:

ps: Report a snapshot of the current processes

Example 1: Report a snapshot of all processes

$ ps aux

Usage: This command provides a snapshot of all running processes, along with detailed information such as process ID, CPU and memory usage, and execution status.

Example 2: Report a snapshot of specific processes

$ ps -ef | grep process_name

Usage: Using grep with ps allows filtering processes based on specific criteria, such as process name or user.

kill: Send a signal to a process

Example 1: Terminate a process by PID

$ kill PID

Usage: This command sends the default signal (SIGTERM) to the specified process ID (PID), causing the process to terminate gracefully.

Example 2: Forcefully terminate a process by PID

$ kill -9 PID

Usage: The -9 option sends the SIGKILL signal to the specified process ID, forcefully terminating the process without giving it a chance to clean up.

killall: Kill processes by name

Example 1: Terminate all processes with a specific name

$ killall process_name

Usage: This command sends the default SIGTERM signal to all processes with the specified name, prompting them to terminate gracefully.

Example 2: Forcefully terminate all processes with a specific name

$ killall -9 process_name

Usage: The -9 option sends the SIGKILL signal to all processes with the specified name, forcefully terminating them without allowing them to clean up.

pkill: Send a signal to a process based on name

Example 1: Terminate processes based on name

$ pkill process_name

Usage: This command sends the default SIGTERM signal to all processes matching the specified name, allowing for efficient termination of multiple processes.

Example 2: Forcefully terminate processes based on name

$ pkill -9 process_name

Usage: The -9 option sends the SIGKILL signal to all processes matching the specified name, forcefully terminating them without allowing them to clean up.

pgrep: List processes based on name

Example 1: List process IDs based on name

$ pgrep process_name

Usage: This command lists the process IDs of all processes matching the specified name, providing a convenient way to identify processes for further actions.

Example 2: List processes with full details based on name

$ pgrep -l process_name

Usage: The -l option provides the list of processes along with their full details matching the specified name.

htop: Interactive process viewer

Example 1: Display an interactive process viewer

$ htop

Usage: htop is an interactive process viewer that provides a more user-friendly interface compared to top. It allows users to interactively monitor and manage processes with ease.

Example 2: Sort processes by memory usage

$ htop -o MEM%

Usage: This command sorts processes by memory usage, helping users identify memory-intensive processes easily.

top: Display Linux processes

Example 1: Display dynamic process information

$ top

Usage: The top command displays dynamic information about Linux processes, including CPU and memory usage, and allows users to interactively monitor and manage processes.

Example 2: Monitor processes by sorting by CPU usage

$ top -o %CPU

Usage: This command sorts processes by CPU usage, allowing users to identify resource-intensive processes easily.

Package Management:

apt (Debian/Ubuntu) or yum (RHEL/CentOS): Package management utilities for installing, updating, and removing software packages

Example 1: Install packages

$ apt-get install package_name

Usage: This command installs the specified package and its dependencies using the apt package manager in Debian/Ubuntu-based systems.

Example 2: Install packages with yum

$ yum install package_name

Usage: This command installs the specified package and its dependencies using the yum package manager in RHEL/CentOS-based systems.

apt-get update, yum update: Update package lists

Example 1: Update package lists with apt-get

$ apt-get update

Usage: This command updates the local package lists from the repositories in Debian/Ubuntu-based systems.

Example 2: Update package lists with yum

$ yum update

Usage: This command updates the local package lists from the repositories in RHEL/CentOS-based systems.

apt-get upgrade, yum upgrade: Upgrade installed packages

Example 1: Upgrade installed packages with apt-get

$ apt-get upgrade

Usage: This command upgrades all installed packages to their latest versions in Debian/Ubuntu-based systems.

Example 2: Upgrade installed packages with yum

$ yum upgrade

Usage: This command upgrades all installed packages to their latest versions in RHEL/CentOS-based systems.

apt-get remove, yum remove: Remove packages

Example 1: Remove packages with apt-get

$ apt-get remove package_name

Usage: This command removes the specified package from the system in Debian/Ubuntu-based systems.

Example 2: Remove packages with yum

$ yum remove package_name

Usage: This command removes the specified package from the system in RHEL/CentOS-based systems.

Network Configuration:

ifconfig or ip: Display or configure network interface parameters

Example 1: Troubleshooting network interface issues with ifconfig

$ ifconfig eth0

Usage: This command displays detailed information about the network interface 'eth0', including its IP address, MAC address, and network statistics. It can help troubleshoot connectivity or configuration issues.

Example 2: Configuring a new IP address with ip

$ ip addr add 192.168.1.100/24 dev eth0

Usage: This command assigns the IP address '192.168.1.100' with a subnet mask of '24' to the network interface 'eth0'. It's useful for configuring new network parameters dynamically.

ping: Send ICMP echo request to check connectivity

Example 1: Troubleshooting network connectivity with ping

$ ping google.com

Usage: This command sends ICMP echo requests to the specified domain 'google.com' to check network connectivity. It's useful for diagnosing network reachability and latency issues.

Example 2: Continuously pinging a host for stability testing

$ ping -c 1000 -i 0.2 host.example.com

Usage: This command sends 1000 ICMP echo requests with an interval of 0.2 seconds to the host 'host.example.com' for stability testing. It helps identify intermittent network issues.

traceroute or tracepath: Trace the route taken by packets to a destination

Example 1: Diagnosing network path issues with traceroute

$ traceroute example.com

Usage: This command traces the route taken by packets to the destination 'example.com' and displays each hop along the way. It's helpful for identifying network bottlenecks and routing issues.

Example 2: Using tracepath to discover MTU along the route

$ tracepath -m 1500 example.com

Usage: This command traces the route to 'example.com' and determines the maximum transmission unit (MTU) along the path. It's useful for troubleshooting MTU-related network problems.

netstat: Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships

Example 1: Displaying active network connections

$ netstat -tuln

Usage: This command prints a list of all active TCP and UDP connections, along with listening ports and associated process IDs. It's useful for monitoring network activity and identifying open ports.

Example 2: Showing network interface statistics

$ netstat -i

Usage: This command displays statistics for each network interface, including packets transmitted and received, errors, and collisions. It's helpful for analyzing network performance and troubleshooting interface issues.

ss: Another utility to investigate sockets

Example 1: Listing all sockets

$ ss -a

Usage: This command displays a comprehensive list of all sockets, including TCP, UDP, and UNIX domain sockets. It provides detailed information about each socket, including state and associated processes.

Example 2: Showing listening TCP sockets with port numbers

$ ss -tl

Usage: This command filters the output to display only listening TCP sockets along with their port numbers. It's useful for monitoring incoming connections and identifying open ports.

nc: Netcat utility for reading from and writing to network connections

Example 1: Create a simple TCP listener with nc

$ nc -l -p 1234

Usage: This command listens for incoming TCP connections on port 1234. It's useful for setting up simple network services or debugging network communication.

Example 2: Transfer files over the network using nc

$ nc -l -p 1234 > file.txt $ nc destination_ip 1234 < file.txt

Usage: This pair of commands sets up a simple file transfer over TCP. One instance listens on port 1234 and saves incoming data to 'file.txt', while the other connects to the destination IP and sends the contents of 'file.txt'.

Firewall: iptables (legacy)

Example 1: Allow SSH connections with iptables

$ iptables -A INPUT -p tcp --dport 22 -j ACCEPT

Usage: This command adds a rule to allow incoming SSH connections on port 22. It's helpful for configuring basic firewall rules to permit specific types of traffic.

Example 2: Drop all incoming traffic from a specific IP address

$ iptables -A INPUT -s bad_ip -j DROP

Usage: This command adds a rule to drop all incoming traffic from the specified IP address 'bad_ip'. It's useful for blocking malicious or unwanted traffic.

firewalld: Firewall utilities to manage IPv4 and IPv6 packet filtering

Example 1: Allow HTTP traffic in the default zone

$ firewall-cmd --zone=public --add-service=http --permanent

Usage: This command adds a rule to allow incoming HTTP traffic in the default 'public' zone. It's useful for configuring firewall rules in a more dynamic and user-friendly manner compared to iptables.

Example 2: Block all incoming traffic from a specific IP address range

$ firewall-cmd --zone=public --add-rich-rule='rule family="ipv4" source address="10.0.0.0/24" drop'

Usage: This command adds a rich rule to block all incoming traffic from the specified IPv4 address range '10.0.0.0/24' in the 'public' zone. It demonstrates the flexibility of firewalld in defining more complex filtering rules.

User Management:

useradd, userdel: Add or delete a user account

Example 1: Add a new user with useradd

$ sudo useradd -m -s /bin/bash username

Usage: This command creates a new user account named 'username' with a home directory and sets the default shell to '/bin/bash'.

Example 2: Delete a user account with userdel

$ sudo userdel -r username

Usage: This command removes the user account 'username' along with their home directory and mail spool.

passwd: Change user password

Example 1: Change the password for a user

$ sudo passwd username

Usage: This command prompts the user to enter a new password for the account 'username'. It provides a simple way to update user passwords.

Example 2: Force a password change at next login

$ sudo passwd -e username

Usage: This command expires the password for the user 'username', forcing them to change their password the next time they log in.

su: Switch user

Example 1: Switch to the root user

$ su -

Usage: This command switches to the root user by prompting for the root password. It's useful for performing administrative tasks that require root privileges.

Example 2: Switch to another user without changing the environment

$ su -l username

Usage: This command switches to the user 'username' while preserving their environment settings. It's helpful for troubleshooting user-specific issues.

sudo: Execute a command as another user, typically the root user

Example 1: Execute a command with elevated privileges

$ sudo apt update

Usage: This command updates the package list using apt with elevated privileges. It's commonly used for system administration tasks that require root permissions.

Example 2: Execute a command as another user

$ sudo -u username command

Usage: This command executes 'command' as the user 'username' with elevated privileges. It's useful for running specific commands with different user privileges.

System Logs:

tail -f /var/log/syslog: View system logs in real-time

Example 1: Monitor system log changes in real-time

$ tail -f /var/log/syslog

Usage: This command displays the last 10 lines of the syslog file and then continuously updates the display as new log entries are added. It's useful for troubleshooting issues and monitoring system activity.

Example 2: View only log entries related to SSH

$ tail -f /var/log/syslog | grep sshd

Usage: This command filters the syslog output to show only log entries related to the SSH daemon (sshd). It helps in monitoring SSH activity and troubleshooting SSH-related issues.

journalctl: Query and display messages from the systemd journal

Example 1: Display all journal entries

$ journalctl

Usage: This command displays all journal entries, including boot messages, system events, and service logs. It's the default way to view systemd journal messages.

Example 2: Filter journal entries by a specific unit

$ journalctl -u sshd.service

Usage: This command filters journal entries to show only those related to the SSH daemon (sshd.service). It's useful for troubleshooting specific service issues.

System Services:

systemctl: Command-line tool to manage systemd services

Example 1: Start a systemd service

$ sudo systemctl start service_name

Usage: This command starts the specified systemd service. It's used to initiate a service manually or as part of a system startup process.

Example 2: Enable a systemd service to start on boot

$ sudo systemctl enable service_name

Usage: This command configures the specified systemd service to start automatically during system boot. It creates symlinks to the service unit files.

service: Command to run System V init scripts

Example 1: Start a System V init script

$ sudo service service_name start

Usage: This command starts the specified System V init script. It's commonly used in systems that use SysVinit as the init system.

Example 2: Stop a System V init script

$ sudo service service_name stop

Usage: This command stops the specified System V init script. It halts the execution of the script and terminates the associated service.

System Monitoring:

htop: Interactive process viewer

Example 1: Monitoring system resource usage with htop

$ htop

Usage: This command launches htop, an interactive process viewer that provides real-time monitoring of system resources such as CPU, memory, and disk usage. It's beneficial for DevOps professionals to identify resource-hungry processes and troubleshoot performance issues.

Example 2: Sorting processes by memory usage

$ htop -o MEM%

Usage: This command starts htop and sorts processes based on memory usage, helping DevOps teams identify memory-intensive processes quickly and optimize system resources.

top: Display Linux processes

Example 1: Monitoring system resource usage with top

$ top

Usage: This command displays Linux processes in real-time, providing information on CPU, memory, and swap usage. DevOps engineers can use top to identify resource bottlenecks and optimize system performance.

Example 2: Sorting processes by CPU usage

$ top -o %CPU

Usage: This command launches top and sorts processes based on CPU usage, enabling DevOps teams to pinpoint CPU-intensive tasks and troubleshoot performance issues.

ps: Report a snapshot of the current processes

Example 1: Listing all processes with ps

$ ps aux

Usage: This command generates a snapshot of all running processes, providing detailed information such as process ID, CPU and memory usage, and execution status. DevOps professionals can use ps to identify resource-intensive processes and manage system resources efficiently.

Example 2: Filtering processes by name

$ ps -ef | grep process_name

Usage: This command filters processes by name using grep, allowing DevOps teams to narrow down process listings and focus on specific tasks or troubleshooting activities.

vmstat: Report virtual memory statistics

Example 1: Display system-wide virtual memory statistics

$ vmstat

Usage: This command provides an overview of system-wide virtual memory statistics including processes, memory, paging, block I/O, traps, and CPU activity. DevOps engineers can use vmstat to identify memory and CPU usage patterns, and detect potential bottlenecks in the system.

Example 2: Monitor memory usage at regular intervals

$ vmstat 5

Usage: This command displays virtual memory statistics every 5 seconds, providing real-time insights into system performance and resource utilization. DevOps professionals can use this feature to monitor memory usage trends and identify abnormalities over time.

iostat: Report CPU and I/O statistics

Example 1: Display CPU and I/O statistics for all devices

$ iostat -x

Usage: This command generates a report of CPU and I/O statistics, including utilization, throughput, and latency, for all devices in the system. DevOps teams can use iostat to monitor disk performance, identify I/O bottlenecks, and optimize storage configurations.

Example 2: Monitor disk I/O activity in real-time

$ iostat -d 5

Usage: This command displays disk I/O statistics every 5 seconds, allowing DevOps engineers to monitor disk activity patterns and detect performance issues as they occur. It provides valuable insights into disk utilization and helps optimize storage resources.

sar: Collect and report system activity information

Example 1: Collect CPU utilization data for the last 24 hours

$ sar -u -f /var/log/sa/sa$(date +%d -d "yesterday")

Usage: This command retrieves CPU utilization data from the system activity files for the previous day and presents it in a readable format. DevOps teams can analyze historical CPU usage patterns and optimize system performance accordingly.

Example 2: Monitor memory and swap space usage at regular intervals

$ sar -r -S 5

Usage: This command reports memory and swap space utilization every 5 seconds, enabling DevOps professionals to track memory usage trends and identify potential memory-related issues in real-time.

nmon: System monitoring tool that displays performance data in real-time

Example 1: Start nmon and display CPU and memory statistics

$ nmon

Usage: This command starts nmon and displays real-time performance data including CPU utilization, memory usage, disk I/O, and network activity. DevOps professionals can use nmon to monitor system health and identify resource bottlenecks.

Example 2: Generate nmon data for further analysis

$ nmon -f -s 10 -c 120

Usage: This command runs nmon in data capture mode, saving performance data to a file (-f) every 10 seconds (-s) for a duration of 120 intervals (-c). DevOps teams can analyze the recorded data to gain insights into system behavior over time.

Backup and Compression:

tar: Archive files

Example 1: Create a tar archive of a directory

$ tar -cvf archive.tar directory

Usage: This command creates a tar archive named 'archive.tar' containing all files and directories within 'directory'. The options (-cvf) display the progress, verbosely list files processed, and specify the filename.

Example 2: Extract files from a tar archive

$ tar -xvf archive.tar

Usage: This command extracts files from the tar archive 'archive.tar'. The options (-xvf) display the progress, verbosely list files extracted, and extract files from the archive.

gzip: Compress files

Example 1: Compress a file with gzip

$ gzip filename

Usage: This command compresses the file 'filename' using gzip compression algorithm. It replaces the original file with the compressed version, appending '.gz' to the filename.

Example 2: Decompress a gzip-compressed file

$ gzip -d filename.gz

Usage: This command decompresses the gzip-compressed file 'filename.gz'. The option (-d) instructs gzip to decompress the file, restoring the original uncompressed file.

bzip2: Compress files

Example 1: Compress a file with bzip2

$ bzip2 filename

Usage: This command compresses the file 'filename' using the bzip2 compression algorithm. It replaces the original file with the compressed version, appending '.bz2' to the filename.

Example 2: Decompress a bzip2-compressed file

$ bzip2 -d filename.bz2

Usage: This command decompresses the bzip2-compressed file 'filename.bz2'. The option (-d) instructs bzip2 to decompress the file, restoring the original uncompressed file.

xz: Compress files

Example 1: Compress a file with xz

$ xz filename

Usage: This command compresses the file 'filename' using the xz compression algorithm. It replaces the original file with the compressed version, appending '.xz' to the filename.

Example 2: Decompress an xz-compressed file

$ xz -d filename.xz

Usage: This command decompresses the xz-compressed file 'filename.xz'. The option (-d) instructs xz to decompress the file, restoring the original uncompressed file.

rsync: Synchronize files and directories between two locations

Example 1: Synchronize files and directories locally

$ rsync -av source_directory/ destination_directory

Usage: This command synchronizes files and directories from 'source_directory' to 'destination_directory'. The options (-av) maintain file permissions, enable verbose output, and recursively synchronize directories.

Example 2: Synchronize files and directories over SSH

$ rsync -avz -e ssh source_directory/ user@remote_host:destination_directory

Usage: This command synchronizes files and directories from 'source_directory' to 'destination_directory' on a remote host using SSH. The options (-avz) maintain permissions, enable compression, and provide verbose output, while (-e ssh) specifies the SSH protocol.

dd: Convert and copy files

Example 1: Create a disk image with dd

$ dd if=/dev/sda of=disk_image.img

Usage: This command creates a disk image 'disk_image.img' from the contents of '/dev/sda'. The 'if' option specifies the input file (source), and 'of' specifies the output file (destination).

Example 2: Copy data between disks with dd

$ dd if=/dev/sda of=/dev/sdb bs=4M conv=sync

Usage: This command copies data from '/dev/sda' to '/dev/sdb' with a block size of 4 megabytes and synchronizes I/O during copying. It's useful for disk cloning and data migration.