~2 min read • Updated Jul 18, 2025
Linux offers a flexible terminal interface for managing files and directories. While graphical tools are useful for basic tasks, the command-line interface (CLI) gives users access to advanced operations and precise control over file organization.
Basic File and Directory Commands
- cp: Copy files and directories
- mv: Move or rename files and directories
- mkdir: Create directories
- rm: Delete files and directories
- ln: Create hard or symbolic links
Using Wildcards to Select Files
Wildcards (globbing patterns) help match multiple filenames using character-based rules:
| Pattern | Meaning |
|---|---|
* | Matches any number of characters |
? | Matches a single character |
[abc] | Matches one of the listed characters |
[!abc] | Matches any character except those listed |
[[:digit:]] | Matches any digit |
Creating Directories with mkdir
mkdir dir1 dir2 dir3This creates three directories: dir1, dir2, and dir3.
Copying Files with cp
cp file1 file2 # Simple copy
cp -i file1 file2 # Prompt before overwrite
cp -r dir1 dir2 # Recursively copy directoriesUseful Options:
| Option | Description |
|---|---|
| -a | Preserve attributes (owner, permissions) |
| -u | Copy only newer or missing files |
| -v | Verbose output |
Moving and Renaming with mv
mv file1 file2 # Rename file1 to file2
mv file1 file2 dir1 # Move to directoryDeleting with rm
rm file1 # Simple delete
rm -r dir1 # Recursive directory deletion
rm -rf dir1 # Force delete without promptCreating Links with ln
Hard Link:
ln file fun-hardSymbolic Link:
ln -s file fun-symHard Link vs Symbolic Link
| Feature | Hard Link | Symbolic Link |
|---|---|---|
| Points To | File inode | File path |
| Partition Scope | Same partition only | Cross-partition allowed |
| File Removal | Link remains valid | Link breaks |
Setting Up a Test Environment
cd ~
mkdir playground
cd playground
mkdir dir1 dir2Copy a system file for testing:
cp /etc/passwd .Renaming and Moving Files
mv passwd fun
mv fun dir1
mv dir1/fun dir2
mv dir2/fun .Creating Hard and Symbolic Links
ln fun fun-hard
ln fun dir1/fun-hard
ln -s fun fun-sym
ln -s ../fun dir1/fun-symDeleting Links and Files
rm fun-hard # Decreases link count
rm -i fun # Deletes original file
rm fun-sym # Deletes broken symlinkCleaning Up the Playground
rm -r playgroundConclusion
Linux’s CLI tools offer robust and precise control for managing files, directories, and links. By mastering commands like cp, mv, rm, mkdir, and ln, along with wildcard usage and symbolic link behaviors, users gain the ability to organize and manipulate the file system efficiently.
Written & researched by Dr. Shahin Siami