Operations 5 min read

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.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Essential Linux File Management Commands: mkdir, cp, rm, find and More

Directory Management Commands: mkdir, rmdir

The mkdir command creates new directories, while rmdir removes empty directories.

File Management Commands: cp, mv, rm

cp

copies files or directories, mv moves or renames them, and rm deletes files.

File Viewing Commands: cat, tac, head, tail, more, less

cat

concatenates 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/passwd

Defining 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/mytest3

Find 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxcommand-lineBashfind
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.