~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:


PatternMeaning
*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 dir3

This 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 directories

Useful Options:


OptionDescription
-aPreserve attributes (owner, permissions)
-uCopy only newer or missing files
-vVerbose output

Moving and Renaming with mv


mv file1 file2       # Rename file1 to file2
mv file1 file2 dir1 # Move to directory

Deleting with rm


rm file1             # Simple delete
rm -r dir1 # Recursive directory deletion
rm -rf dir1 # Force delete without prompt

Creating Links with ln


Hard Link:


ln file fun-hard

Symbolic Link:


ln -s file fun-sym

Hard Link vs Symbolic Link


FeatureHard LinkSymbolic Link
Points ToFile inodeFile path
Partition ScopeSame partition onlyCross-partition allowed
File RemovalLink remains validLink breaks

Setting Up a Test Environment


cd ~
mkdir playground
cd playground
mkdir dir1 dir2

Copy 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-sym

Deleting Links and Files


rm fun-hard          # Decreases link count
rm -i fun # Deletes original file
rm fun-sym # Deletes broken symlink

Cleaning Up the Playground


rm -r playground

Conclusion


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