Basic Commands for navigating in Linux | Ubuntu File System

This is a beginner’s guide to navigating through the Linux File System. In this article, we will learn about the following commands:

Content:

  1. pwd
  2. cd
  3. ls

Command: pwd

This command is used to “Print Working Directory”. Shows the current location in the directory tree.

For Example:

So, once we type ‘pwd’, it prints the path of the current directory.

Command: cd

This command is used to “Change Directory”. When typed all by itself, it returns you to your home directory.

cd /directory is used to change into the specified directory name.

Example:

# cd /usr/src/linux

Also, cd ~ “~” is an alias for your home directory. It can be
used as a shortcut to your “home”, or other directories relative to your home.

cd .. Move up one directory. For example, if you are in /home/vic and you type “cd ..”, you will end up in /home.

cd – Return to the previous directory. An easy way to get back to your previous location!

Command: ls

ls dir lists all files in the current directory, in column format. ls /directory lists the files in the specified directory.

ls -l dir lists files in “long” format, one file per line. This also shows you additional info about the file, such as ownership, permissions, date, and size.

ls -a dir lists all files, including “hidden” files. Hidden files are those files that begin with a “.”, e.g. The .bash_history file in your home directory.

ls -ld directory lists “long” list of “directory”, but instead of showing
the directory contents, show the directory’s detailed information. For example, compare the output of the following two commands:

ls -l /usr/bin
ls -ld /usr/bin

ls /usr/bin/d* lists all files whose names begin with the letter “d” in the /usr/bin directory.

Example:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.