Getting Started: 15 practice examples on Linux's 'cd' command

Source: Internet
Author: User

Getting Started: 15 practice examples on Linux's 'cd' command

In Linux, The 'cd' (Change directory) command is the most important and commonly used command for beginners and system administrators. For administrators who manage servers without graphic interfaces, 'cd' is the only way to go to the directory, check logs, execute programs, applications, scripts, and other tasks. For new users, it is the initial command they must learn by themselves.

Example of 15 cd commands in Linux

Therefore, please study hard. Here we will bring you 15 basic 'cd' commands, which are skillful and shortcuts and learn to use these learned skills, it will greatly reduce your effort and time spent on the terminal.

Course details
  • Command name: cd
  • Representative: Switch the Directory
  • Platform: All Linux releases
  • Execution method: Command Line
  • Permission: access your own directory or other specified directories
  • Level: Basic/beginner
  1. Switch from the current directory to/usr/local

    1. Avi @ tecmint :~ $ Cd/usr/local
    2. Avi @ tecmint:/usr/local $
  2. Use the absolute path to switch from the current directory to/usr/local/lib

    1. Avi @ tecmint:/usr/local $ cd/usr/local/lib
    2. Avi @ tecmint:/usr/local/lib $
  3. Use the relative path to switch from the current path to/usr/local/lib

    1. Avi @ tecmint:/usr/local $ cd lib
    2. Avi @ tecmint:/usr/local/lib $
  4. (A) switch the current directory to the parent directory

    1. Avi @ tecmint:/usr/local/lib $ cd-
    2. /Usr/local
    3. Avi @ tecmint:/usr/local $

    (B) switch the current directory to the parent directory

    1. Avi @ tecmint:/usr/local/lib $ cd ..
    2. Avi @ tecmint:/usr/local $
  5. Display the last left working directory (use the '-' option)

    1. Avi @ tecmint:/usr/local $ cd --
    2. /Home/avi
  6. Returns two layers from the current directory to the upper-level

    1. Avi @ tecmint:/usr/local $ cd ../../
    2. Avi @ tecmint:/$
  7. Return from any directory to the user's home directory

    1. Avi @ tecmint:/usr/local $ cd ~
    2. Avi @ tecmint :~ $

    Or

    1. Avi @ tecmint:/usr/local $ cd
    2. Avi @ tecmint :~ $
  8. Switch the working directory to the current working directory (LCTT: What is the significance of this ?!)

    1. Avi @ tecmint :~ /Downloads $ cd.
    2. Avi @ tecmint :~ /Downloads $

    Or

    1. Avi @ tecmint :~ /Downloads $ cd ./
    2. Avi @ tecmint :~ /Downloads $
  9. Your current directory is "/usr/local/lib/python3.4/dist-packages". Switch to "/home/avi/Desktop/". A command line is required, switch up until '/', and then use the absolute path

    1. Avi @ tecmint:/usr/local/lib/python3.4/dist-packages $ cd.../home/avi/Desktop/
    2. Avi @ tecmint :~ /Desktop $
  10. Switch from the current working directory to/var/www/html. Requirement: do not complete the command. Use the TAB

    1. Avi @ tecmint:/var/www $ cd/v <TAB>/w <TAB>/h <TAB>
    2. Avi @ tecmint:/var/www/html $
  11. Switch from the current directory to/etc/v _. Ah, you forgot the directory name, but you don't want to use the TAB

    1. Avi @ tecmint :~ $ Cd/etc/v *
    2. Avi @ tecmint:/etc/vbox $

    Note: If only one directory starts with 'V', it will be moved to 'vbox '. If many directories start with 'V' and the command line does not provide more standards, this will be moved to the first directory starting with 'V' (in the order in which letters exist in the Standard Dictionary)

  12. You want to switch to the user's 'av' directory (not sure if it is avi or avt) without using a TAB

    1. Avi @ tecmint:/etc $ cd/home/av?
    2. Avi @ tecmint :~ $
  13. Pushed and poped in Linux

    Pushed and poped are Linux bash commands. They are also the scripts that can save the current working directory location to the memory and read the directory from the memory as the current directory. These scripts can also switch directories.

    1. Avi @ tecmint :~ $ Pushd/var/www/html
    2. /Var/www/html ~
    3. Avi @ tecmint:/var/www/html $

    The preceding command saves the current directory to the memory and switches to the required directory. Once poped is executed, it extracts the saved directory location from the memory as the current directory

    1. Avi @ tecmint:/var/www/html $ popd
    2. ~
    3. Avi @ tecmint :~ $
  14. Switch to the directory with spaces

    1. Avi @ tecmint :~ $ Cd test \ tecmint/
    2. Avi @ tecmint :~ /Test tecmint $

    Or

    1. Avi @ tecmint :~ $ Cd 'test cmint'
    2. Avi @ tecmint :~ /Test tecmint $

    Or

    1. Avi @ tecmint :~ $ Cd "test tecmint "/
    2. Avi @ tecmint :~ /Test tecmint $
  15. Switch from the current directory to the download directory, and then list the content it contains (using a line of command)

    1. Avi @ tecmint:/usr $ cd ~ /Downloads & ls
    2. ...
    3. .
    4. Service_locator_in.xls
    5. Sources. list
    6. Teamviewer_linux_x64.deb
    7. Tor-browser-linux64-3.6.3_en-US.tar.xz
    8. .
    9. ...

We try to use the least words and are as friendly as ever to help you understand how Linux works and runs.

This is all content. I will come back soon with another interesting topic.

10 useful Linux Command Interview Questions and answers

Linux Command cd

Cat for Linux commands

Linux Command alias/unalias

Linux Command Parsing: su root and su-root

Interactive input of Linux commands read

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.