Working with Directories:
Table of contents
Manage Directories
cd
Command:Used to change the current working directory.
Example:
cd /path/to/directory
.
pwd
Command:Prints the current working directory.
Example:
pwd
.
~
(Tilde):Represents the home directory of the current user.
Example:
cd ~
orcd
.
Tab Key Auto-Complete:
- Pressing the Tab key can auto-complete directory and file names, saving time and reducing errors.
-
(Hyphen) for Previous Directory:The
-
symbol is used to go to the previous working directory.Example:
cd -
.
ls
Command:
ls
Command:Lists files and directories in the current directory.
Example:
ls
.
-a
Option:Shows hidden files and directories (those starting with a dot).
Example:
ls -a
.
-l
Option:- Provides detailed information about files and directories in a long format.
Example: ls -l
. or ll
Tree Command:
The tree
command in Linux is a useful tool for visually representing the directory structure in a tree-like format. It recursively displays the contents of directories and subdirectories, making it easier to understand the hierarchy of files and directories within a specified path.
Here's the basic syntax of the tree
command:
tree [options] [directory]
Install Tree Package:
Example Usage:
Example 1: Display Tree for Current Directory
This command will display the tree structure of the current working directory.
Example 2: Display Tree for a Specific Directory
tree /path/to/directory
Replace /path/to/directory
with the actual path of the directory you want to visualize.
Example 3: Display Tree with File Details
The -l
option shows additional details for each file, including permissions and file sizes.
tree -l
Example 4: Display Tree with Hidden Files
The -a
option includes hidden files and directories (those starting with a dot).
tree -a
Example 5: Limit Depth of Tree
The -L
option limits the depth of the tree to the specified level. In this example, the depth is limited to 2 levels.
tree -L 2
Example 6: Save Tree to a File
Redirect the output to a file for documentation or reference.
tree > tree_structure.txt
Types of Paths:
Absolute Path:
Specifies the full path from the root directory.
Example:
/home/user/documents
.
Relative Path:
Specifies the path relative to the current working directory.
Example:
../parent_directory
.
.
(Dot) and..
(Double Dot):
.
(Dot):Represents the current directory.
Example:
./current_directory
.
..
(Double Dot):Represents the parent directory.
Example:
../parent_directory
.
Linux Playground:-
https://www.redhat.com/en/interactive-labs/install-software-using-package-managers
Subscribe to my newsletter
Read articles from Afridi Shaik directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by