hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    arrow
    arrow
    arrow
    What is the correct way to add a new directory to the $PATH variable in Linux?
    Question



    What is the correct way to add a new directory to the $PATH variable in Linux?

    A.

    set PATH=/new/directory

    B.

    export PATH=$PATH:/new/directory

    C.

    add PATH:/new/directory

    D.

    echo PATH:/new/directory

    E.

    modify PATH=/new/directory:$PATH

    Correct option is B

    In Linux, to add a new directory to the $PATH variable, the correct method is using the export command. This ensures that the new directory is appended to the existing $PATH and is available for the current shell session.
    Example: export PATH=$PATH:/new/directory
    This command appends /new/directory to the existing $PATH. To make this change permanent, it can be added to the .bashrc or .bash_profile file.
    Important Key Points:
    1. $PATH is an environment variable that defines the directories the shell searches for executable files.
    2. The export command ensures the modified $PATH is available to the current session and child processes.
    3. Changes made directly to $PATH are temporary unless added to shell configuration files like .bashrc.
    Knowledge Booster:
    · set PATH=/new/directory: Incorrect; set is not used for exporting environment variables.
    · add PATH:/new/directory: Incorrect; this syntax is invalid in Linux shells.
    · echo PATH:/new/directory: Incorrect; echo only displays the value but does not modify $PATH.
    · modify PATH=/new/directory:$PATH: Incorrect; modify is not a valid command in Linux.

    Free Tests

    Free
    Must Attempt
    Video Solutions

    RBI Assistant Pre 2026 Full Mock Test -01

    languageIcon English
    • pdpQsnIcon100 Questions
    • pdpsheetsIcon100 Marks
    • timerIcon60 Mins
    languageIcon English
    Free
    Must Attempt
    Video Solutions

    RBI Asst Prelims 2026 : Reasoning Section Test 01

    languageIcon English
    • pdpQsnIcon35 Questions
    • pdpsheetsIcon35 Marks
    • timerIcon20 Mins
    languageIcon English
    Free
    Must Attempt
    Video Solutions

    RBI Asst Prelims 2026 : Quant Section Test 01

    languageIcon English
    • pdpQsnIcon35 Questions
    • pdpsheetsIcon35 Marks
    • timerIcon20 Mins
    languageIcon English
    test-prime-package

    Access ‘SEBI Grade-A Assistant Manager’ Mock Tests with

    • 60000+ Mocks and Previous Year Papers
    • Unlimited Re-Attempts
    • Personalised Report Card
    • 500% Refund on Final Selection
    • Largest Community
    students-icon
    368k+ students have already unlocked exclusive benefits with Test Prime!
    Our Plans
    Monthsup-arrow