Master Essential Linux File Management Commands: mkdir, cp, rm, find and More
This guide walks you through fundamental Linux shell commands for creating, moving, copying, viewing, and searching files—including mkdir, rmdir, cp, mv, rm, cat, tac, head, tail, more, less, and find—plus useful examples, status codes, and pattern‑matching tricks.
Directory Management Commands: mkdir, rmdir
The mkdir command creates new directories, while rmdir removes empty directories.
File Management Commands: cp, mv, rm
cpcopies files or directories, mv moves or renames them, and rm deletes files.
File Viewing Commands: cat, tac, head, tail, more, less
catconcatenates and displays file contents; tac does the same in reverse order. head shows the beginning of a file, tail shows the end. more and less provide paginated viewing.
Command Execution Status
Bash stores the exit status of the last command in $?. Use echo $? to display it. A status of 0 means success; 1‑255 indicate various failures.
Advanced Directory Creation Examples
Create multiple directories with brace expansion:
(1) mkdir /tmp/{a,b}_{c,d} (2) mkdir -P /tmp/mylinux/{bin,boot/grub,dev,etc/{rc.d/init.d,sysconfig/network-scripts},lib/modules,lib64,proc,sbin,sys,tmp,usr/local/{bin,sbin},var/{lock,log,run}}File Metadata
Metadata includes permissions, owner/group, timestamps, size, and type.
Viewing Metadata with stat
Example:
# stat /etc/passwdDefining Aliases
Use the alias command to create shortcuts for other commands.
Pattern Matching Examples
List directories matching complex patterns:
ls -d /var/l*[0-9][^0-9] ls -d /etc/[0-9]*[^0-9] ls -d /etc/[^[:alpha:]][[:alpha:]]* mkdir /tmp/tfile-$(date +"%Y-%m-%d-%H-%M-%S") cp -r /etc/p*[^0-9] /tmp/mytest1 cp -r /etc/*.d /tmp/mytest2 cp -r /etc/[lmn]*.conf /tmp/mytest3Find Command Overview
The find command searches for files within a directory hierarchy.
How It Works
It traverses directories recursively, evaluating each file against specified criteria.
Advantages and Disadvantages
Advantages: precise searching and real‑time results. Disadvantages: can be resource‑intensive and slower on large file systems.
Typical Usage
Common patterns include locating files by name, type, size, or modification time.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
