This page covers fundamental commands for navigating your file system and managing directories.
1. ls
- List Directory Contents
Purpose: The ls
command is used to list the contents of a directory. It's one of the most fundamental commands for navigating and understanding your file system.
Syntax: ls [OPTIONS] [FILE...]
Key Options:
-l
: (long format) Displays detailed information about files and directories, including permissions, owner, group, size, and modification date.-a
: (all) Shows all files, including hidden files (those starting with a dot.
).-h
: (human readable) Displays file sizes in a human-readable format (e.g., KB, MB, GB).-R
: (recursive) Lists the contents of directories and their subdirectories.
Examples:
ls ls -l ls -a ls -lh /home/user/documents
2. cd
- Change Directory
Purpose: The cd
command allows you to change your current working directory. This is crucial for navigating the file system.
Syntax: cd [DIRECTORY]
Key Uses:
cd /path/to/directory
: Change to an absolute path.cd directory_name
: Change to a subdirectory within the current directory.cd ..
: Move up one level to the parent directory.cd
: Go to your home directory (shorthand forcd ~
).cd -
: Go back to the previous directory you were in.
Examples:
cd /etc cd my_project cd ..
3. pwd
- Print Working Directory
Purpose: The pwd
command stands for "print working directory." It displays the full path of your current location within the file system.
Syntax: pwd
Example:
pwd
4. mkdir
- Make Directories
Purpose: The mkdir
command is used to create new directories (folders).
Syntax: mkdir [OPTIONS] DIRECTORY_NAME...
Key Options:
-p
: (parents) Creates parent directories as needed. This is useful for creating a directory tree in one command.
Examples:
mkdir new_folder mkdir -p project/src/main
5. rmdir
- Remove Empty Directories
Purpose: The rmdir
command is used to remove empty directories. If a directory contains files or other subdirectories, rmdir
will fail.
Syntax: rmdir DIRECTORY_NAME...
Example:
rmdir empty_folder