Study guide
5.6 Basic File Management: cp, mv, rm, touch, mkdir, rmdir (103.3)
LPIC-1 Linux Administrator — Exam 101 101-500
Track your progress as you read
Finished sections get a check mark.
1 Exam Overview & Study Strategy
1.1 LPIC-1 101-500 Exam Structure & Blueprint 1.2 Command Line & Shell Fundamentals for Exam Success 1.3 Fill-in-the-Blank Strategies & Common Traps
2 Topic 101: System Architecture
2.1 Hardware Discovery, Sysfs, Procfs & Kernel Modules (101.1) 2.2 Udev, Dbus & Device Management (101.1) 2.3 BIOS vs. UEFI & System Boot Process (101.2) 2.4 Kernel Initialization, Initramfs & System Logs (101.2) 2.5 Systemd Boot Targets & Unit Management (101.3) 2.6 SysVinit Runlevels, Telinit & System Shutdown (101.3)
3 Topic 102: Linux Installation & Boot Management
3.1 Hard Disk Layout, Partition Schemes & Swap Design (102.1) 3.2 LVM & Standard Mount Point Allocation (102.1) 3.3 GRUB 2 Configuration & Troubleshooting (102.2) 3.4 Legacy GRUB & Alternative Boot Loaders (102.2) 3.5 Managing Shared Libraries & ldconfig (102.3) 3.6 Linux as a Virtualization Guest & Cloud Instances (102.6)
4 Topic 102: Package Management Systems
4.1 Debian Low-Level Package Management with dpkg (102.4) 4.2 High-Level Debian Package Management: apt, apt-get & apt-cache (102.4) 4.3 RPM Package Management with rpm (102.5) 4.4 YUM, DNF & Zypper Package Management (102.5) 4.5 Package Repositories & Integrity Verification (102.4/102.5) 4.6 Universal Linux Packages: Snap, Flatpak & AppImage (102.4/102.5)
5 Topic 103: Command Line & Text Processing
5.1 Shell Environment, Environment Variables & Aliases (103.1) 5.2 Command History, Quoting & Expansion (103.1) 5.3 Basic Text Filters: cat, head, tail, cut, paste, nl, od (103.2) 5.4 Advanced Text Filters: sort, uniq, wc, tr, split, less & Checksums (103.2) 5.5 Stream Editing with sed (103.2) 5.6 Basic File Management: cp, mv, rm, touch, mkdir, rmdir (103.3) 5.7 Archiving and Compression: tar, gzip, bzip2, xz, cpio & dd (103.3)
6 Topic 103: Streams, Processes, Regex & Vi
6.1 Standard Streams, Redirection & File Descriptors (103.4) 6.2 Pipelines, tee & xargs (103.4) 6.3 Process Monitoring: ps, top, free, watch, pgrep, pstree & uptime (103.5) 6.4 Signals, kill, Job Control, nohup, screen & tmux (103.5) 6.5 Process Priorities: nice & renice (103.6) 6.6 Regular Expressions & grep, egrep, fgrep (103.7) 6.7 vi / vim Modes, plus nano, Emacs & EDITOR Awareness (103.8)
7 Topic 104: Devices, Partitions & Filesystems
7.1 Block Devices, fdisk & gdisk (104.1) 7.2 GNU Parted & Partition Table Management (104.1) 7.3 Creating Filesystems: mkfs, ext4, XFS, VFAT/exFAT & Btrfs (104.1) 7.4 Filesystem Integrity: fsck, e2fsck, xfs_repair, xfs_fsr & xfs_db (104.2) 7.5 Monitoring Disk Usage: df, du & tune2fs (104.2) 7.6 Managing Swap Space: mkswap, swapon & swapoff (104.1/104.2)
8 Topic 104: Mounts, Permissions, Links & FHS
8.1 Mounting and Unmounting Filesystems: mount & umount (104.3) 8.2 Persistent Mounts: /etc/fstab, UUIDs & systemd mount units (104.3) 8.3 Standard File Permissions: chmod, chown, chgrp & umask (104.5) 8.4 Special Permissions: SUID, SGID & Sticky Bit (104.5) 8.5 Hard Links vs. Symbolic Links: ln & Inodes (104.6) 8.6 Filesystem Hierarchy Standard (FHS) & File Location (104.7)
5.6 Basic File Management: cp, mv, rm, touch, mkdir, rmdir (103.3)
Key Takeaways Explain This Topic AI
cp copies files and trees; -a (--archive) is equivalent to -dpR and preserves permissions, timestamps, ownership, and symbolic links.
mv renames or moves files; moving across filesystems copies data and deletes original, whereas same-filesystem moves only update directory entries.
rm removes directory entries and unlinks inodes; -r recurses directories and -f forces removal without prompting.
touch updates access (-a) and modification (-m) timestamps or creates 0-byte files; explicit dates use -t or -d.
mkdir -p creates nested parent directories idempotently, while file uses magic numbers in file headers rather than file extensions to identify types.
Last updated: August 2026
5.6 Basic File Management: cp, mv, rm, touch, mkdir, rmdir (103.3)
Quick Summary: Linux systems administrators manage files and directory structures using core utilities: cp (copying with attribute preservation), mv (moving/renaming), rm (unlinking and recursive deletion), touch (timestamp manipulation), mkdir (directory creation), rmdir (removing empty directories), file (header magic number classification), and ls (directory listing). Mastery of exact flag behaviors is essential for Topic 103.3.
1. cp : Copying Files and Directories
The cp utility creates duplicate copies of files and directory trees.
Essential cp Command-Line Flags
- Flag Long Option Function & Description
- r / -R --recursive Copies directories and their subtrees recursively
- p --preserve=mode,ownership,timestamps Preserves file permissions (mode), ownership (UID/GID), and timestamps
- a --archive Archive mode: Preserves all attributes, recursion, and symbolic links. Equivalent to -dpR
- d --no-dereference Copies symbolic links as symbolic links rather than copying the target files
- i --interactive Prompts for confirmation before overwriting an existing destination file
- f --force If destination file cannot be opened, removes it first and tries again; never prompts
- u --update Copies only when source file is newer than destination or destination is missing
- s --symbolic-link Creates symbolic links instead of copying file contents
- l --link Creates hard links instead of copying file contents
- v --verbose Displays detailed progress showing each file copied
-b --backup Creates a backup of each existing destination file ( file~ ) before overwriting # Creating an exact archive backup of /etc preserving all ownership, permissions, and symlinks:
sudo cp -a /etc /backup/etc_20260829
# Updating a destination directory with only modified or new source files:
cp -uv /src/* /opt/destination/
💡 LPIC-1 Exam Fill-in-the-Blank Alert: Which cp option flag is identical to -dpR and enables full archive copying (preserving links, ownership, permissions, and timestamps)? The answer is -a (or --archive ).
- 2. mv and rm : Moving, Renaming, and Removing
- The mv Utility
mv moves or renames files and directories.
Same Filesystem: Only updates directory entries; the inode number and disk data blocks remain unchanged.
Cross-Filesystem: Copies the file data blocks to the target filesystem, allocates a new inode, and removes the original source.
- Flag Long Option Behavior
- i --interactive Prompts before overwriting an existing destination file
- f --force Overwrites destination files without prompting
- u --update Moves only when source is newer or destination is missing
- n --no-clobber Does not overwrite an existing destination file
- v --verbose Prints source and destination names during moves
- The rm Utility
rm removes hard links from directory structures (unlinking). When a file's hard link count reaches 0 and no running processes hold open file descriptors to it, the kernel frees its storage blocks.
- Flag Long Option Behavior
- r / -R --recursive Removes directories and their contents recursively
- f --force Ignores non-existent files, never prompts, suppresses error codes
- i --interactive Prompts before every file removal
- I N/A Prompts once before removing more than 3 files or recursing
-d --dir Removes empty directories (identical to rmdir ) # Safely removing a directory tree with a single confirmation prompt:
rm -rI /tmp/build_artifacts
# Removing files that have leading hyphens (preventing flag confusion):
rm -- -rf_malicious_filename.txt
3. touch : Timestamp Modification & File Creation
Every file in a Linux filesystem maintains three primary timestamps:
atime (Access Time): Last time the file's contents were read (e.g., via cat , grep ).
mtime (Modification Time): Last time the file's contents were modified/written.
ctime (Change Time): Last time the file's inode metadata or permissions were altered (updated automatically by kernel; cannot be set manually).
If the target file does not exist, touch creates a new empty 0-byte regular file.
Essential touch Command-Line Flags
- Flag Long Option Function & Description
- a N/A Changes the access time ( atime ) only
- m N/A Changes the modification time ( mtime ) only
- c / -h --no-create Do not create file if it does not already exist (updates timestamps only)
- d '<string>' --date Uses human-readable date string instead of current time
- t <stamp> N/A Uses explicit format: [[CC]YY]MMDDhhmm[.ss]
-r <file> --reference Copies timestamps from <file> to the target file # Setting explicit timestamp: August 29, 2026, at 14:30:00 (Format: YYYYMMDDhhmm.ss):
$ touch -t 202608291430.00 release.tar.gz
# Setting date using human-readable string:
- $ touch -d "2026-08-29 14:30:00" release.tar.gz
- $ touch -d "3 days ago" file.log
# Updating timestamp only if file exists (no new file created):
- $ touch -c /tmp/optional_lockfile.pid
- 4. mkdir and rmdir : Directory Management
mkdir (Make Directory):
-p ( --parents ): Creates parent directories as needed without error if they already exist ( idempotent ). E.g., mkdir -p /opt/app/releases/v2/config .
-m <mode> ( --mode ): Sets octal or symbolic permissions at creation time (e.g., mkdir -m 700 /home/user/.ssh ).
-v ( --verbose ): Displays a message for each created directory.
rmdir (Remove Directory):
Removes empty directories. Fails with Directory not empty if any files, subdirectories, or hidden dotfiles exist.
-p ( --parents ): Removes directory and its parent ancestors if they become empty (e.g., rmdir -p a/b/c deletes c , then b if empty, then a if empty).
5. file : File Classification via Magic Numbers
The file command determines the true data type of a file by inspecting header bytes and signatures (known as magic numbers stored in /usr/share/misc/magic ), rather than relying on file extensions.
Essential file Flags
-b ( --brief ): Brief mode; omits the filename prefix from output lines.
-z ( --uncompress ): Looks inside compressed files (e.g., inspects contents of .gz archives).
-i ( --mime ): Outputs MIME type strings (e.g., text/plain; charset=utf-8 or application/x-pie-executable ).
-L ( --dereference ): Follows symbolic links to determine the target's type. $ file /bin/bash
/bin/bash: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked...
- $ file -b -i /etc/passwd
- text/plain; charset=us-ascii
- $ file -z backup.tar.gz
- backup.tar.gz: POSIX tar archive (gzip compressed data...)
- 6. ls : Directory Listing Options Reference
Flag Long Option Function & Description
-a --all Lists all files including hidden files starting with . as well as . and ..
-A --almost-all Lists all files including hidden files, but excludes . and ..
- l N/A Long listing format (permissions, link count, owner, group, size, mtime, name)
- h --human-readable Displays file sizes with units (K, M, G) in powers of 1024 (used with -l )
- t N/A Sorts listing by modification time ( mtime ), newest first
- r --reverse Inverts sort order (e.g., ls -ltr lists oldest first, newest at the bottom)
- R --recursive Lists all subdirectories recursively
- d --directory Lists directory entries themselves, not their contents (e.g., ls -ld /var/log )
- i --inode Prints the internal filesystem index number (inode) of each file
- S N/A Sorts files by file size, largest first
- 1 N/A Lists one file per line (ideal for scripts and pipelines)