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.
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 |
mkdir dir1 dir2 dir3
This creates three directories: dir1
, dir2
, and dir3
.
cp file1 file2 # Simple copy
cp -i file1 file2 # Prompt before overwrite
cp -r dir1 dir2 # Recursively copy directories
Option | Description |
---|---|
-a | Preserve attributes (owner, permissions) |
-u | Copy only newer or missing files |
-v | Verbose output |
mv file1 file2 # Rename file1 to file2
mv file1 file2 dir1 # Move to directory
rm file1 # Simple delete
rm -r dir1 # Recursive directory deletion
rm -rf dir1 # Force delete without prompt
ln file fun-hard
ln -s file fun-sym
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 |
cd ~
mkdir playground
cd playground
mkdir dir1 dir2
Copy a system file for testing:
cp /etc/passwd .
mv passwd fun
mv fun dir1
mv dir1/fun dir2
mv dir2/fun .
ln fun fun-hard
ln fun dir1/fun-hard
ln -s fun fun-sym
ln -s ../fun dir1/fun-sym
rm fun-hard # Decreases link count
rm -i fun # Deletes original file
rm fun-sym # Deletes broken symlink
rm -r playground
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.