Linux Command Line Basics
Key Concepts
- Navigating the File System
- Managing Files and Directories
- Basic Text Manipulation
Navigating the File System
Navigating the file system in Linux involves using commands to move between directories and view their contents. The most essential commands for this are cd
(change directory) and ls
(list directory contents).
Imagine the file system as a tree with branches representing directories and leaves representing files. The cd
command allows you to move from one branch to another, while ls
helps you see the leaves (files) and smaller branches (subdirectories) within the current branch.
For example, to move to the home directory, you would use cd ~
. To list the contents of the current directory, you would use ls
.
Managing Files and Directories
Managing files and directories involves creating, copying, moving, and deleting them. Key commands for this include mkdir
(make directory), cp
(copy), mv
(move), and rm
(remove).
Think of managing files and directories as organizing a bookshelf. The mkdir
command is like adding a new shelf, cp
is like copying a book to another shelf, mv
is like moving a book to a different shelf, and rm
is like removing a book from the shelf.
For example, to create a new directory named "projects", you would use mkdir projects
. To copy a file named "report.txt" to the "projects" directory, you would use cp report.txt projects/
.
Basic Text Manipulation
Basic text manipulation involves viewing and editing text files. Essential commands for this include cat
(concatenate and print files), nano
(a simple text editor), and grep
(search text).
Consider text manipulation as reading and annotating a book. The cat
command is like reading the entire book, nano
is like writing notes in the book, and grep
is like finding specific words or phrases in the book.
For example, to view the contents of a file named "notes.txt", you would use cat notes.txt
. To search for the word "important" in "notes.txt", you would use grep "important" notes.txt
.