What does ~ mean ?

dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
3,511
Reaction score
3,256
Credits
31,430

Understanding the ~ Symbol in Linux​

In Linux, the ~ (tilde) symbol is a shorthand notation for the home directory of the current user. The home directory is where a user's personal files, configurations, and directories are stored. This symbol simplifies navigation and file management within the terminal.

Why Use the ~ Symbol?​

Using the ~ symbol can save time and keystrokes when working in the terminal. Instead of typing out the full path to your home directory, you can use ~ to quickly reference it.

Examples of Using the ~ Symbol​

Here are a few examples to illustrate how you can use the ~ symbol in various commands:

  1. Navigating to the Home Directory
    To quickly navigate to your home directory, you can use the cd (change directory) command with ~:
    Code:
     cd ~
  2. Listing Files in the Home Directory
    To list all files and directories in your home directory, use the ls (list) command with ~:
    Code:
     ls ~
  3. Creating a New Directory in the Home Directory
    To create a new directory named new_folder in your home directory, use the mkdir (make directory) command with ~:
    Code:
     mkdir ~/new_folder
  4. Copying a File to the Home Directory
    To copy a file named example.txt from the current directory to your home directory, use the cp (copy) command with ~:
    Code:
     cp example.txt ~/
  5. Moving a File to a Subdirectory in the Home Directory
    To move a file named example.txt to a subdirectory named documents within your home directory, use the mv (move) command with ~:
    Code:
     mv example.txt ~/documents/

Conclusion​

The ~ symbol is a powerful and convenient tool in Linux for referencing the home directory.
 


Typically, in documentation, it would be written like

~/.profile

Which means, file " .profile " in your Home directory,
so that they don't need to use the $HOME which may be more Linux distro specific (?).
And if not, ~ is shorter than $HOME
Reason enough to use it, in my book. Plus, you know advanced users are reading your documentation.


Also note that

cd

redirects to the same directory as

cd ~

So you don't even need to use ~
Maybe this is also distro dependent, I don't know, but I know that " cd " on itself guides me to my home directory.
 


Members online


Latest posts

Top