Working with Directories:

Afridi ShaikAfridi Shaik
3 min read

Manage Directories

  1. cdCommand:

    • Used to change the current working directory.

    • Example: cd /path/to/directory.

  2. pwdCommand:

    • Prints the current working directory.

    • Example: pwd.

  3. ~(Tilde):

    • Represents the home directory of the current user.

    • Example: cd ~ or cd.

  4. Tab Key Auto-Complete:

    • Pressing the Tab key can auto-complete directory and file names, saving time and reducing errors.
  5. -(Hyphen) for Previous Directory:

    • The - symbol is used to go to the previous working directory.

    • Example: cd -.

lsCommand:

  1. lsCommand:

    • Lists files and directories in the current directory.

    • Example: ls.

  2. -aOption:

    • Shows hidden files and directories (those starting with a dot).

    • Example: ls -a.

  3. -lOption:

    • 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:

  1. Absolute Path:

    • Specifies the full path from the root directory.

    • Example: /home/user/documents.

  2. Relative Path:

    • Specifies the path relative to the current working directory.

    • Example: ../parent_directory.

.(Dot) and.. (Double Dot):

  1. .(Dot):

    • Represents the current directory.

    • Example: ./current_directory.

  2. ..(Double Dot):

    • Represents the parent directory.

    • Example: ../parent_directory.

Linux Playground:-

https://www.redhat.com/en/interactive-labs/install-software-using-package-managers

0
Subscribe to my newsletter

Read articles from Afridi Shaik directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Afridi Shaik
Afridi Shaik