Linux Professional Institute LPIC-1 Exam 101
GNU and Unix Commands
Perform Basic File Management Part 1
In this guide, you’ll master essential Linux file operations—listing, creating, copying, moving, and deleting files and directories—to streamline your workflow on any Unix-like system.
Table of Contents
- Key Concepts
- Listing Files and Directories
- Filesystem Structure
- Creating Files and Directories
- Copying Files and Directories
- Moving and Renaming
- Deleting Files and Directories
- Summary of Commands
- References
Key Concepts
Before you begin, make sure you understand:
- The Linux filesystem tree and hierarchy
- The difference between absolute paths and relative paths
- How to navigate directories with
cd
and identify your location withpwd
Note
Absolute paths start at the root directory /
while relative paths are based on your current working directory.
Listing Files and Directories
Use the ls
command to display directory contents:
$ ls
Documents Desktop Downloads Music Pictures Videos
Show hidden files (those starting with a dot) with -a
:
$ ls -a
. .. .bashrc .profile Documents Desktop Downloads Music Pictures Videos
For a detailed (long) listing including permissions, ownership, size, and timestamp, add -l
:
$ ls -l /var/log
total 4064
drwxr-xr-x 2 root root 4096 Oct 18 22:52 anaconda
drw------- 2 root root 4096 Oct 18 22:53 audit
-rw------- 1 root root 19524 Nov 1 17:56 boot.log
...
Combine options to save time:
$ ls -al # same as ls -a -l
$ ls -ahl # human-readable sizes with -h
Filesystem Structure
Linux organizes files in an inverted tree structure:
- Root directory:
/
- Standard subdirectories:
/home
,/var
,/etc
,/usr
, etc. - Each folder can contain files and more subdirectories
Absolute Paths
Absolute paths always begin at /
.
Example:
/home/aaron/documents/invoice.pdf
Relative Paths
Relative paths depend on your current directory. Check it with:
$ pwd
/home/aaron
Change directories using cd
:
$ cd /var/log # absolute path
$ cd /home/aaron # absolute path
$ cd .. # up one level
$ cd documents # down into current dir’s "documents"
From /home/aaron
, these relative paths resolve to:
documents/invoice.pdf
→/home/aaron/documents/invoice.pdf
invoice.pdf
→/home/aaron/invoice.pdf
../invoice.pdf
→/home/invoice.pdf
../../invoice.pdf
→/invoice.pdf
Additional cd
shortcuts:
$ cd / # go to root
$ cd # go to your home directory
$ cd - # switch to previous directory
Creating Files and Directories
Create an empty file:
$ touch receipt.pdf
Create a new directory:
$ mkdir receipts
Copying Files and Directories
Use cp [source] [destination]
:
Copy a file into a directory:
$ cp receipt.pdf receipts/
Copy and rename:
$ cp receipt.pdf receipts/receipt_copy.pdf
Copy a directory recursively:
$ cp -r receipts/ backup_of_receipts/
Ensure
backup_of_receipts
does not already contain areceipts
subdirectory.
Moving and Renaming
Use mv [source] [destination]
to move or rename:
$ mv receipt.pdf receipts/
$ mv receipts/receipt.pdf receipts/old_receipt.pdf
$ mv receipts/ old_receipts/
mv
works seamlessly on both files and directories.
Deleting Files and Directories
Warning
rm -r
permanently deletes directories and their contents. Use with caution to avoid data loss.
Remove a file:
$ rm invoice.pdf
Remove a directory recursively:
$ rm -r invoices/
Always include -r
when deleting directories.
Summary of Commands
Command | Description | Example |
---|---|---|
ls | List directory contents | ls -ahl /var/log |
pwd | Print working directory | pwd |
cd | Change directory | cd /home/aaron/documents |
touch | Create an empty file | touch newfile.txt |
mkdir | Create a new directory | mkdir project |
cp | Copy files or directories | cp -r src/ dest/ |
mv | Move or rename files and directories | mv oldname newname |
rm | Remove files or directories | rm -r obsolete_folder/ |
References
Watch Video
Watch video content