Buffl

Linux File and Directory Management

as
von abdullah S.

Commands for Listing and Viewing


ls (list)

  • Purpose: Lists directory contents

  • Common Options:

    • -a = Show all files (including hidden files starting with .)

    • -l = Long listing format (shows permissions, owner, size, date)

    • -al = Combined (often aliased to ll)

pwd (print working directory)

  • Purpose: Shows the full path of current directory

  • Usage: pwd

  • Output: /home/username

cd (change directory)

  • Purpose: Navigate between directories

  • Special Characters:

    • . (dot) = Current directory

    • .. (dot dot) = Parent directory

    • - (dash) = Previous working directory

    • ~ (tilde) = User's home directory

Examples:

cd /home/user # Absolute path

cd ~ # Home directory

cd .. # Parent directory

cd - # Previous directory


cat (concatenate)

  • Purpose: Display file contents in standard output

  • Usage: cat filename

  • Note: Good for viewing small text files

vi (visual editor)

  • Purpose: Text editor for viewing and editing files

  • Also creates files if they don't exist

  • Basic Usage:

    • i = Insert mode (to type)

    • Esc = Exit insert mode

    • :w = Save (write)

    • :q = Quit

    • :wq = Save and quit


Absolute Path:

  • A complete path starting from the root directory

  • Always begins from the root directory (/ in Linux/Mac, C:\ in Windows)

  • Works regardless of your current location in the file system

  • Like giving a complete street address with city, state, and country

Examples of absolute paths:

Windows: C:\Users\John\Documents\file.txt

Linux/Mac: /home/user/documents/file.txt

Relative Path:

  • A path relative to your current working directory

  • Starts from where you currently are in the file system

  • Changes meaning depending on your current location

  • Like giving directions from your current position

Examples of relative paths:

./file.txt (file in current directory) ../file.txt

(file in parent directory)

folder/file.txt (file in subfolder of current directory)

Special Symbols in Relative Paths:

  • . refers to current directory

  • .. refers to parent directory

  • ~ refers to home directory (in Linux/Mac)

Real-world Analogy:

  • Absolute path is like: "123 Main Street, New York, NY, 10001, USA"

  • Relative path is like: "Two blocks down, turn right"

The relative path only makes sense if you know your starting point, while the absolute path works from anywhere.


Author

abdullah S.

Informationen

Zuletzt geändert