Linux command
tilde 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Home directory
cd ~
Another user's home directory
cd ~[username]
Previous directory
cd ~-
Current directory
echo ~+
Case modification (bash 4+)
echo ${var~~}
说明
~ (tilde) is expanded by the shell to directory paths. It's a shorthand that avoids hardcoding paths like /home/user. Tilde expansion only occurs at the start of a word or after :. In the middle of text, ~ is literal. ```bash cd ~ # Go home cd ~/Documents # Home subdirectory cd ~root # Root's home PATH=$PATH:~/bin # After : works ``` The ~+ and ~- forms mirror the pushd/popd directory stack, allowing quick navigation between recent directories.
FAQ
What is the tilde command used for?
~ (tilde) is expanded by the shell to directory paths. It's a shorthand that avoids hardcoding paths like /home/user. Tilde expansion only occurs at the start of a word or after :. In the middle of text, ~ is literal. ```bash cd ~ # Go home cd ~/Documents # Home subdirectory cd ~root # Root's home PATH=$PATH:~/bin # After : works ``` The ~+ and ~- forms mirror the pushd/popd directory stack, allowing quick navigation between recent directories.
How do I run a basic tilde example?
Run `cd ~` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
Where can I find more tilde examples?
This page includes 5 examples for tilde, plus related commands for nearby Linux tasks.