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

  1. Key Concepts
  2. Listing Files and Directories
  3. Filesystem Structure
  4. Creating Files and Directories
  5. Copying Files and Directories
  6. Moving and Renaming
  7. Deleting Files and Directories
  8. Summary of Commands
  9. 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 with pwd

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"

The image shows a directory structure with a command line interface on the left. The directory tree includes folders like "home," "var," and "root," with a file named "Invoice.pdf" under "aaron/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 a receipts 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

CommandDescriptionExample
lsList directory contentsls -ahl /var/log
pwdPrint working directorypwd
cdChange directorycd /home/aaron/documents
touchCreate an empty filetouch newfile.txt
mkdirCreate a new directorymkdir project
cpCopy files or directoriescp -r src/ dest/
mvMove or rename files and directoriesmv oldname newname
rmRemove files or directoriesrm -r obsolete_folder/

References

Watch Video

Watch video content

Previous
Process Text Streams Using Filters