• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Saturday, May 24, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

How to Identify Working Directories Using Shell Characters and Variables

How VPS by How VPS
November 2, 2018
in Linux, Operating System
0
0
SHARES
16
VIEWS
Share on FacebookShare on Twitter

Contents

  1. 1. Using Specific Shell Characters
  2. 2. Using Environmental Variables
  3. 3. Using Simple cd Commands

Some of the special directories that a Linux user is bound to work with so many times on a shell command line include the user’s home directory, the current and previous working directories.

Therefore, understanding how to easily access or pinpoint these directories using certain unique methods can be a bonus skill for a new or any Linux user.

How to Identify Working Directories Using Shell Characters and Variables

Identify Working Directories Using Shell Characters and Environment Variables

In this tips for newbies, we shall look at ways of how a user can identify his/her home, current and previous working directories from the shell using special shell characters and environment variables.

1. Using Specific Shell Characters

There are certain specific characters that are understood by the shell when we are dealing with directories from the command line. The first character we shall look at is the tilde (~): it is used to access the current user’s home directory:

$ echo ~
How to Identify Working Directories Using Shell Characters and Variables

Display User Home Directory

Suggested Read: Learn ‘echo’ Command with This 15-Practical Examples

The second is the dot (.) character: it represents the current directory that a user is in, on the command line. In the screen shot below, you can see that the command ls and ls . produce the same out put, listing the contents of the current working directory.

$ ls
$ ls .
How to Identify Working Directories Using Shell Characters and Variables

List Contents of Current Working Directory

Suggested Read: Master ‘ls’ Command with This Basic 15-Practical Examples

The third special characters are the double dots (..) which represent the directory directly above the current working directory that a user is in.

In the image below, the directory above /var is the root directory (/), so when we use the ls command as follows, the contents of (/) are listed:

$ ls ..
How to Identify Working Directories Using Shell Characters and Variables

Print Contents of Parent Directory

Suggested Read: 7 Quirky ‘ls’ Command Tricks Every Linux User Should Know

2. Using Environmental Variables

Apart from the characters above, there are also certain environmental variables meant to work with the directories we are focusing on. In the next section, we shall walk through some of the important environmental variables for identifying directories from the command line.

$HOME: its value is the same as that of the tilde (~) character – the current user’s home directory, you can test that by using the echo command as follows:

$ echo $HOME
How to Identify Working Directories Using Shell Characters and Variables

Print User Home Directory

$PWD: in full, it stands for – Print Working Directory (PWD), as the name implies, it prints the absolute path of the current working directory in the shell command line as below:

$ echo $PWD 
How to Identify Working Directories Using Shell Characters and Variables

Print Present Working Directory

$OLDPWD: it points to the directory a user was in, just before moving to the current working directory. You can access its value as below:

$ echo $OLDPWD
How to Identify Working Directories Using Shell Characters and Variables

Print Parent Directory

Suggested Read: 15 ‘pwd’ (Print Working Directory) Command Examples in Linux

3. Using Simple cd Commands

Additionally, you can also run some simple commands to quickly accessing your home directory and previous working directory. For example, when you are in any part of your file system on the command line, typing cd and hitting Enter will move you to your home directory:

$ echo $PWD
$ cd
$ echo $PWD
How to Identify Working Directories Using Shell Characters and Variables

Switch to User Home Directory

You can also move to the previous working directory using the command cd - command as below:

$ echo $PWD
$ echo $OLDPWD
$ cd - 
$ echo $PWD
How to Identify Working Directories Using Shell Characters and Variables

Switch to Previous Working Directory

In this post, we moved through some simple yet useful command line tips for new Linux users to identify certain special directories from within the shell command line.

Do you have any thoughts in terms of Linux tips you want to share with us or questions concerning the subject matter, then use the comment form below to get back to us.

Source: tecmint.com

Tags: Linux Commandslinux guidelinux vps setup guide
Previous Post

How to Set Limits on User Running Processes in Linux

Next Post

How to Check MD5 Sums of Installed Packages in Debian/Ubuntu Linux

Next Post

How to Check MD5 Sums of Installed Packages in Debian/Ubuntu Linux

Leave a Reply Cancel reply

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

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet