What is the tilde's shortcut function?

QuestionsQuestions8 SkillsProDec, 19 2025
0122

In Linux, the tilde (~) functions as a Shell Expansion shortcut that represents the absolute path to the current user's home directory.

Here is a breakdown of its primary shortcut functions:

1. Representing Your Home Base

Instead of typing /home/labex, you simply type ~.

  • Example: ls ~ lists files in your home folder.

You can use it with the cd (change directory) command to jump home instantly from anywhere in the file system:

  • cd ~ : Takes you to /home/labex.
  • cd ~/project : Takes you to the project folder inside your home directory.

3. Referring to Other Users

The tilde can also be a shortcut to someone else's home directory if you append their username:

  • ~username : Represents the home directory of that specific user.

4. The "Previous" Directory Shortcut

In some shells (like the one you are using), you might see variations:

  • ~+ : Represents the current working directory (same as pwd).
  • ~- : Represents the previous working directory.

Summary:
The tilde's main function is convenience and portability. It ensures that your commands and scripts work correctly regardless of what your specific username is or where your home folder is located on the disk.

0 Comments

no data
Be the first to share your comment!