dd Command Tutorial for Sysadmins

I think I only used the dd command less than ten times in my Linux sysadmin life. So, I decided to put together a simple dd Command Tutorial for Sysadmins. But, first I had to brew my favorite Caturra coffee variety and check out their Specialty Coffee news section.

What is dd?

dd is a low-level copying tool in Linux/UNIX. Unlike cp, it works at the raw byte level, meaning it can copy anything: files, partitions, disks, even memory.
This makes it invaluable for backups, recovery, cloning, and troubleshooting.

Basic Syntax

dd if=<input> of=<output> [options]

if= → input file/device (source)
of= → output file/device (destination)
bs= → block size (how much data to read/write at once)
count= → how many blocks to copy
status=progress → show progress bar (modern feature)

Real-Life Use Cases for Sysadmins

Backup the first 512 bytes (bootloader + partition table):

sudo dd if=/dev/sda of=mbr_backup.img bs=512 count=1

Restore it if corrupted:

sudo dd if=mbr_backup.img of=/dev/sda bs=512 count=1

Clone a Full Disk

sudo dd if=/dev/sda of=/dev/sdb bs=4M status=progress

Makes /dev/sdb a bootable copy of /dev/sda.

Useful for migrations or duplicating lab servers.

Create a Disk Image

sudo dd if=/dev/sda of=disk_backup.img bs=4M status=progress

Creates an image file (disk_backup.img) you can compress or transfer.

Write an ISO to USB

sudo dd if=ubuntu.iso of=/dev/sdb bs=4M status=progress oflag=sync

Common method for creating bootable USB drives.

Wipe a Disk Securely

Overwrite a disk with zeros:

sudo dd if=/dev/zero of=/dev/sdb bs=1M status=progress

Overwrite with random data:

sudo dd if=/dev/urandom of=/dev/sdb bs=1M status=progress

Careful: This destroys all data on the target disk.

Performance Testing (Disk Speed)

Write test:

dd if=/dev/zero of=testfile bs=1G count=1 oflag=dsync

Read test:

dd if=testfile of=/dev/null bs=1G count=1

Partial File Copy (Skip & Limit)

Copy the first 100MB of a file:

dd if=bigfile.iso of=sample.iso bs=1M count=100

Skip first 50MB and copy the next 100MB:

dd if=bigfile.iso of=part.iso bs=1M skip=50 count=100

Create Swap File

sudo dd if=/dev/zero of=/swapfile bs=1M count=2048
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Makes a 2GB swap file.

Safety Tips

Always double-check if= and of= before pressing Enter.

Use lsblk or fdisk -l to confirm disk names.

Practice with small files before using real disks.

Quick Reference Cheatsheet

  • Backup MBR: dd if=/dev/sda of=mbr.img bs=512 count=1
  • Clone disk: dd if=/dev/sda of=/dev/sdb bs=4M status=progress
  • ISO → USB: dd if=linux.iso of=/dev/sdb bs=4M status=progress
  • Wipe disk: dd if=/dev/zero of=/dev/sdb bs=1M status=progress
  • Create swap: dd if=/dev/zero of=/swapfile bs=1M count=2048

Contact me if you have any questions. If you like my work consider supporting me by shopping one of my coffee mugs and T-Shirt designs using my Shop here.

Managing Users in macOS via Terminal

macOS is UNIX-based, so you can use standard BSD commands like dscl (Directory Service Command Line) for managing users in macos and groups as well. The reason I found this useful is that you can remote using SSH to any mac and make this changes. You don’t need to rely on the GUI. Especially if you’re connecting from a different OS such as Windows or Linux.

Some of these commands require sudo because they modify system accounts. Before I tested these I had to brew a nice Sidra coffee variety at home using my Moka pot.

Check existing users

dscl . list /Users

Means the local directory (your Mac).
This lists all user accounts (system + human).

Add a new user

Create a local user paco with a home directory.

sudo sysadminctl -addUser paco -fullName "Paco Raban" -password "Secret123"

Creates the user paco.
fullName sets the display name.
password sets the login password.
Automatically creates /Users/paco.

Another way with dscl (more manual way):

sudo dscl . -create /Users/john
sudo dscl . -create /Users/john UserShell /bin/bash
sudo dscl . -create /Users/john RealName "John Doe"
sudo dscl . -create /Users/john UniqueID 501
sudo dscl . -create /Users/john PrimaryGroupID 20
sudo dscl . -create /Users/john NFSHomeDirectory /Users/john
sudo dscl . -passwd /Users/john Secret123
sudo createhomedir -c -u john

Note: UniqueID must be unique (start from 501 upward for normal users).

Remove a user

sudo sysadminctl -deleteUser paco

This deletes the user and their home directory.

Add a user to the admin group

sudo dseditgroup -o edit -a paco -t user admin

–a paco → add user paco.
admin group → macOS admin privileges.

Remove a user from a group

sudo dseditgroup -o edit -d paco -t user admin

List members of a group

dscl . -read /Groups/admin GroupMembership

If the Mac is joined to Active Directory (AD)

  • The local user commands stay the same, but:
    • You don’t create AD users with dscl; those come from the AD server.
    • Group membership changes must be done on the AD domain controller, unless you are adding an AD user to a local Mac group.
  • Example: Add an AD user to local admin group:
sudo dseditgroup -o edit -a "ADDOMAIN\\paco" -t user admin

You must use the AD short name and escape the backslash (\\).

Managing Users in macOS using the Terminal

This task is easier than what I expected. So useful to know some Terminal commands. Let me know what you think.

Always contact me if you have any questions. Grab one of my designs in my shop if you like to support me. Thanks!

10 practical Linux Text-filter examples

Hola! I put together a mini Linux text-filter examples using a data.csv file. I have copy/paste it below for your reference.
I’m going to use commands like cut, grep, awk, sort, uniq, head, tail, and wc.
I’ll explain each example and you can run them on your Linux command line. But first, I needed to grab a good beer and get inspired.

data.csv sample file: (you can copy/paste it into your terminal)

Name,Age,Department,Salary
Alice,30,HR,45000
Bob,25,IT,50000
Charlie,35,Finance,55000
Diana,28,Marketing,47000
Ethan,40,IT,60000
Fiona,32,Finance,53000
George,29,HR,46000
Hannah,31,Marketing,48000

Show only the names from the CSV

cut -d',' -f1 data.csv

-d',' → delimiter is a comma.
-f1 → first field only.

Show only employees in the IT department

grep ",IT," data.csv

Searches for lines containing ,IT, to avoid partial matches.

Show employees earning more than 50,000

awk -F',' '$4 > 50000' data.csv

-F',' → set field separator to comma.
$4 > 50000 → filter where Salary (field 4) is greater than 50,000.

Sort employees by Salary (highest first)

sort -t',' -k4 -nr data.csv

-t',' → delimiter comma.
-k4 → sort by 4th column (Salary).
-n → numeric sort.
-r → reverse order.

Count how many employees are in each department

cut -d',' -f3 data.csv | sort | uniq -c

First cuts the Department column.
Sorts it.
uniq -c → shows counts.

Show only the first 3 employees in the file

head -n 3 data.csv

Show the last 2 employees in the file

tail -n 2 data.csv

Find all employees with names starting with “A”

grep "^A" data.csv

^A → regex meaning “starts with A”.

Add $1000 to each employee’s salary (display only)

awk -F',' '{if(NR==1){print $0} else {$4=$4+1000; OFS=","; print}}' data.csv

Leaves the header row intact (NR==1).
Adds 1000 to field 4 for all other rows.

Count total employees in the file (excluding header)

tail -n +2 data.csv | wc -l

tail -n +2 → skip header.
wc -l → line count.

I hope these Linux text-filter examples are useful for you. If you like to support me please consider buying one of my T-Shirt or coffee mugs designs in my shop. Thanks!

Work on the Linux command line fundamentals

The work on the Linux command line topic is fundamental to your day-to-day work as a Linux administrator. Below is a breakdown of each area and command, with simple explanations and practical command-line examples you can try. But, first I need to brew coffee at home – Very important!

Use single shell commands and one-line command sequences

You can chain commands together using:

  • ; to run commands sequentially
  • && to run next command only if the previous one succeeds
  • || to run next command only if the previous one fails

Give it a shot, open your Terminal and run the below Linux commands examples:

echo "Hello" ; echo "World"
mkdir test && cd test
ping -c 1 8.8.8.8 || echo "Ping failed"

Use and modify the shell environment Define, reference, and export environment variables

NAME="Linux"
echo $NAME           # Referencing variable
export CITY="NYC"    # Makes it available to sub-processes
env | grep CITY      # See exported variable
unset NAME           # Removes the variable

Use and edit command history

history              # List previous commands
!42                  # Run command number 42
!!                   # Repeat last command
!ls                  # Run last 'ls' command

Edit .bash_history manually:

nano ~/.bash_history

Invoke commands inside and outside the path

echo $PATH                     # Shows where shell looks for executables
ls /usr/bin                   # Inside PATH
./my_script.sh                # Outside PATH, run with relative path

To add your own folder to PATH:

export PATH=$PATH:$HOME/bin

Important Linux Bash Commands and Tools

CommandPurpose & Example
bashStart a bash shell: bash
echoPrint to screen: echo "Hello $USER"
envShow current environment: env
exportExport variable: export VAR=value
pwdPrint current directory: pwd
setSet or show shell variables: `set
unsetRemove variable: unset VAR
typeShow how command is interpreted: type ls
whichShow full path of command: which bash
manManual pages: man ls, man bash
unameInfo about system: uname -a
historyList shell history: history
.bash_historyFile storing history: cat ~/.bash_history

Quoting in Bash (VERY Important)

TypeDescriptionExample
Double "Expands variablesecho "User: $USER"
Single 'Literal value, no expansionecho 'User: $USER'
Backticks ` or $(...)Command substitutionecho $(date)

Give this command a shot:

export MYNAME="Linux Admin" && echo "Welcome $MYNAME" && date >> ~/session.log && type echo

What do you mean double ” expands variables?

When we say double quotes " " expand variables, we mean that the shell will interpret variables or commands inside the quotes, instead of treating them as plain text.

Brew a Caturra coffee variety and run this example next:

USER="alex"
echo "Hello $USER"
Output will be:
Hello alex

Inside double quotes "Hello $USER", the $USER is expanded to its value: alex.

But with single quotes ' ', nothing is expanded:

USER="alex"
echo 'Hello $USER'

Output will be:

Hello $USER

Debian Package Management Linux Commands

Jumping between Debian and RedHat based Linux distros can be confusing sometimes for me. This is why I decided to create this short Debian Package Management guide. But, first I need to brew a good cup of Catimor coffee variety at home.

Brief terms:

dpkg – Low-level tool to manage .deb packages.

apt, apt-get, apt-cache – High-level front ends for package management (use online repositories).

Install, Upgrade, and Uninstall Debian Packages

Install a .deb package (local file):

sudo dpkg -i package-name.deb

Fix missing dependencies (after installing a .deb manually):

sudo apt -f install

Upgrade an installed package:

sudo apt upgrade package-name

Or all upgrade ALL packages:

sudo apt update && sudo apt upgrade

Uninstall a package (local):

sudo dpkg -r package-name

Remove completely with configuration files:

sudo dpkg -P package-name

Install from the repository:

sudo apt install package-name

Find Packages Containing Specific Files or Libraries

Search for a file in installed packages:

dpkg -S /path/to/file

For example:

dpkg -S /bin/ln

Obtain Package Info: Version, Content, Dependencies, etc.

Check if a package is installed:

dpkg -l | grep package-name

Show details about a package:

dpkg -s package-name

List files installed by a package:

dpkg -L package-name

Show dependencies of a package:

apt depends package-name

Show reverse dependencies (who depends on it):

apt rdepends package-name

Common apt commands:

TaskCommand
Update repo listsudo apt update
Install a packagesudo apt install htop
Upgrade installed packagessudo apt upgrade
Remove a packagesudo apt remove package-name
Full removal (with config)sudo apt purge package-name
Clean downloaded filessudo apt clean
Autoremove unused packagessudo apt autoremove

If you like this article and want to support me consider buying a T-Shirt or coffee mug from my shop. Thanks.

Linux SysVinit (runlevels) and systemd (targets) commands

Reviewing the differences between Linux SysVinit (runlevels) and Systemd (targets) commands was something I was always curious to learn. After taking a walk in New York City during the summer I decided to put this list together.

How to see the current runlevel in Linux?

SysVinit (older systems)

Default runlevel is set in: /etc/inittab
Example line:

id:3:initdefault:

This means runlevel 3 (multi-user, no GUI).

systemd (modern systems)

Use this command to check it out:

systemctl get-default

You might get:

graphical.target

This means this is set to graphical mode using GUI for Linux.

If you want to switch to multi-user mode (non-GUI), the run:

sudo systemctl set-default multi-user.target

Change between runlevels / boot targets

On SysVinit, you can use this command:

sudo init 3   # switch to runlevel 3
sudo init 1   # single-user mode

When using systemd Linux box, do this:

To change to multi-user (non-GUI):

sudo systemctl isolate multi-user.target

To switch to GUI:

sudo systemctl isolate graphical.target

Single-user mode (rescue mode):

sudo systemctl isolate rescue.target

Below is a brief table summary for the commands in Linux for both SysVinit and systemd:

TaskSysVinit Commandsystemd Command
View current runlevelrunlevelsystemctl get-default
Change runlevelinit 3systemctl isolate multi-user.target
Set default runlevelEdit /etc/inittabsystemctl set-default target
Shutdown nowshutdown -h nowshutdown -h now
Reboot nowrebootreboot
Send user warningwall "message"wall "message"
Kill a processkill PIDkill PID
Power managementacpidacpid + journalctl

Hopefully this helps someone out there. It helps me to review the Linux basics. I usually tend to forget them. If you like my content consider grabbing one of my T-Shirt of coffee mugs designs in my ITPro Helper shop. Thanks!

Linux Boot Troubleshooting Flowchart

Below is a short Linux boot troubleshooting flowchart I put together. Its mainly for my own reference and also to share it with anyone wanting to learn. After brewing a good cup of Caturra coffee at home. I put together this simple flowchart:

[ Start ]
↓
[ Power on the system ]
↓
[ BIOS/UEFI screen appears? ]
├─ No → Check power, motherboard, or display
└─ Yes
↓
[ Is boot device detected (e.g., disk)? ]
├─ No → Check BIOS/UEFI settings & boot order
└─ Yes
↓
[ GRUB menu appears? ]
├─ No → Reinstall GRUB using live CD/USB
└─ Yes
↓
[ Can you boot a kernel from GRUB? ]
├─ No → Use GRUB shell (grub>) to find kernel & initrd
└─ Yes
↓
[ Kernel loads or shows panic? ]
├─ Panic → Check for missing initramfs or incorrect root
└─ Loads
↓
[ System hangs or gives error after kernel load? ]
├─ Yes → Inspect initramfs and boot logs
└─ No
↓
[ Reaches login screen or prompt? ]
├─ No → Check systemd/journalctl logs (journalctl -xb)
└─ Yes → System boot successful

Let me know what you think in the comments section below. I also have a few ITPro Helper IT T-Shirts and coffee mugs in my shop. If you like any you can place an order. Thanks!

Linux bootloader(GRUB) common commands

This is a topic that I haven’t reviewed much or probably nothing at all. When your Linux system boots, GRUB loads the Linux kernel and passes its options. These kernel options can help us:

  • Debug boot issues
  • Enable or disable hardware drivers
  • Enter specific modes (like single-user)

When to use bootloader GRUB command at boot time?

  • Troubleshooting boot problems
  • Disabling a problematic device driver
  • Entering rescue or single-user mode
  • Disabling graphical splash or enabling logs
  • Passing custom memory or CPU settings

You can pass kernel command parameters to GRUB at boot time or make it permanent. For now, I’m going to decide which coffee from Latin America I’m going to brew at home.

Pass kernel parameters temporarily

Interrupt GRUB at boot time and when the menu appears do:

Press e to edit the boot entry.

You may see this line:

linux   /boot/vmlinuz-5.15.0-91-generic root=UUID=xxxx ro quiet splash

You can append options at the end of the line starting with linux. For example to boot into single-user mode:

linux   /boot/vmlinuz-... root=UUID=... ro single

or

linux   /boot/vmlinuz-... root=UUID=... ro init=/bin/bash

Common used kernel boot options

OptionPurposeExample Usage
singleBoot into single-user modelinux ... ro single
init=/bin/bashStart with Bash shell instead of init/systemdlinux ... ro init=/bin/bash
nomodesetPrevent kernel mode-setting (graphics troubleshooting)linux ... ro quiet splash nomodeset
quietSuppresses most boot messageslinux ... ro quiet
splashShow splash screenlinux ... ro splash
noapic, nolapicDisables APIC / Local APIC (used for IRQ troubleshooting)linux ... noapic nolapic
acpi=offDisables ACPI (power management, battery issues)linux ... acpi=off
mem=512MLimit usable memorylinux ... mem=512M
root=/dev/sdXnSpecify root device (overrides default)linux ... root=/dev/sda1

Make changes permanent if you want

Edit /etc/default/grub with your favorite editor. I like to use vim.

Find this line:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

Modify it using the options in the table above. For example you can do:

GRUB_CMDLINE_LINUX_DEFAULT="quiet single nomodeset"

Then update GRUB:

sudo update-grub      # Debian/Ubuntu
sudo grub2-mkconfig -o /boot/grub2/grub.cfg   # RHEL/CentOS

View the current kernel command line configuration

You can simply run this command in your Terminal:

cat /proc/cmdline

You should see something like this:

Linux bootloader(GRUB) common commands

Keep in mind the below for Linux bootloader

  • Always test kernel parameters temporarily first.
  • If a parameter causes issues, reboot and remove it.
  • Kernel parameters are space-separated.

How to detect storage devices in Linux

One of my clients wanted to find out how to detect storage devices in Linux for one of her servers in a remote location. After brewing a good cup of Catimor coffee variety at home I decided to take on this one. It took me a some time to find the Linux terminal commands for it. But, I got them and I’m sharing this simple commands. Check out below.

Look at vendor, product, logical name and etc

sudo lshw -class disk

This one gives you the most details about all your storage devices in Linux. The sample output is something like this:

*-cdrom                   
       description: DVD-RAM writer
       product: VMware SATA CD00
       vendor: NECVMWar
       physical id: 0.0.0
       bus info: scsi@3:0.0.0
       logical name: /dev/cdrom
       logical name: /dev/sr0
       version: 1.00
       capabilities: removable audio cd-r cd-rw dvd dvd-r dvd-ram
       configuration: ansiversion=5 status=open
  *-disk:0
       description: SCSI Disk
       product: Virtual disk
       vendor: VMware
       physical id: 0.0.0
       bus info: scsi@0:0.0.0
       logical name: /dev/sda
       version: 2.0
       size: 60GiB (64GB)
       capabilities: gpt-1.00 partitioned partitioned:gpt
       configuration: ansiversion=6 guid=491452eb-c164-4724-bd11-f462e3e95a27 logicalsectorsize=512 sectorsize=512
  *-disk:1
       description: SCSI Disk
       product: Virtual disk
       vendor: VMware
       physical id: 0.1.0
       bus info: scsi@0:0.1.0
       logical name: /dev/sdb
       version: 2.0
       size: 100GiB (107GB)
       capabilities: gpt-1.00 partitioned partitioned:gpt
       configuration: ansiversion=6 guid=02c96157-7141-4b33-8137-0064b3c8fef2 logicalsectorsize=512 sectorsize=512

Another handy command to find specific storage device info in Linux is:

sudo smartctl -i /dev/sdb (or your device name)

You should get a similar output to this one:

smartctl 7.1 2019-12-30 r5022 [x86_64-linux-4.18.0-477.21.1.el8_8.x86_64] (local build)
Copyright (C) 2002-19, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF INFORMATION SECTION ===
Vendor:               VMware
Product:              Virtual disk
Revision:             2.0
Compliance:           SPC-4
User Capacity:        107,374,182,400 bytes [107 GB]
Logical block size:   512 bytes
LU is thin provisioned, LBPRZ=1
Rotation Rate:        Solid State Device
Device type:          disk
Local Time is:        Wed Jul 23 10:04:27 2025 CDT
SMART support is:     Unavailable - device lacks SMART capability.

Finally, if you just want to find out if the storage device in you Linux box is Virtual or Physical you can use:

cat /sys/block/sdb/device/model

For this Linux box the output was:

Virtual disk

I’m sure there are many other commands to find information about the storage devices attached to your Linux server. You can share them in the comments section if you like. Thank you and have a great day!

Linux Directory Structure in Brief

I’m creating this Linux directory structure table as a quick reference for the future. I tend to forget what/where things are in Linux sometimes. Hope this brief information helps somebody else learning about Linux in general. Run an ls -l command to see the contents of each directory.

DirectoryDescription
/Where everything begins. You will see mainly directories.
/bootLinux kernel and boot loader files are kept. The kernel is a file called vmlinuz.
/etcContains configuration files for the system. All files should mostly be text files. Important files to remember in this directory:
/etc/passwd: This is where user’s accounts are defined.
/etc/fstab: This file defines the system’s disk drives. Contains a list of devices the system mounts at boot time.
/etc/hosts: Contains hostnames, IP addresses known to the system.
/etc/init.d: Scripts that start some system services at boot.
/bin, /usr/binThe /bin directory contains essential programs for the system. The /usr/bin has applications for the system’s users.
/sbin, /usr/sbinMainly programs for system administration, mostly for use by the superuser.
/usrContain files that support user applications. For example:
/usr/share/X11: Support for the X Window system.
/usr/share/dict: Dictionaries and spell checking for Linux.
/usr/share/doc: Documentation files in many formats.
/usr/share/man: Man pages live here.
/usr/localUse for the installation of software and other files for use on the local machine. Software that is not part of the OS goes here. Official OS software goes at /usr/bin. You should install software here. Usually, in the /usr/local/bin directory.
/varContains files that change when the system is running. For example log files in the /var/log. Also, holds files in queue for some process in the /var/spool for example print jobs and mail (in the case the system runs local mail)
/libShared libraries (similar to DLLs in Windows) are kept here.
/homeUsers keep their personal files/work. This should be the only location users can write.
/rootSuper user home directory.
/tmpPrograms can write their temporary files here.
/devIt contains devices that are available to the system. In Linux (Unix), devices are treated like files. You can read and write devices as though they were files. For example, /dev/sda is the first hard drive in the system. All the devices that the kernel understands are represented here.
/procThere are a group of numbered entries in this directory that correspond to all the processes running on the system. In addition, there are a number of named entries that permit access to the current configuration of the system. Many of these entries can be viewed. Try viewing /proc/cpuinfo. This entry will tell you what the kernel thinks of the system’s CPU.
/mediaThe /media directory is used by the automatic device mounting mechanisms found in modern desktop oriented Linux distributions. To see what devices and mount points are used, type mount. This directory is mainly used for the system to mount temporary devices such as USB disks and etc..

As always, you can contact me if you have any questions. For now, I’m going to brew an unique Caturra coffee variety from Panama at home. Thanks!