Linux command
dirs 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Display directory stack
dirs
Display with indices
dirs -v
Display one entry per line
dirs -p
Clear directory stack
dirs -c
Show nth entry from left
dirs +[n]
Show nth entry from right
dirs -[n]
Display full paths
dirs -l
说明
dirs displays the directory stack managed by pushd and popd. The stack provides a way to remember and return to previously visited directories without typing full paths. The directory stack is a list where the top (leftmost in default view) is the current directory. Each pushd adds to the stack and changes to that directory; popd removes from the stack and returns to the previous directory. Combined with +n and -n notation, you can reference directories by position, enabling quick navigation in complex directory structures.
参数
- -c
- Clear the directory stack.
- -l
- Display full paths (no ~ abbreviation).
- -p
- Print one directory per line.
- -v
- Print with index numbers, one per line.
- +n
- Display nth entry from left (0 = top).
- -n
- Display nth entry from right (0 = bottom).
FAQ
What is the dirs command used for?
dirs displays the directory stack managed by pushd and popd. The stack provides a way to remember and return to previously visited directories without typing full paths. The directory stack is a list where the top (leftmost in default view) is the current directory. Each pushd adds to the stack and changes to that directory; popd removes from the stack and returns to the previous directory. Combined with +n and -n notation, you can reference directories by position, enabling quick navigation in complex directory structures.
How do I run a basic dirs example?
Run `dirs` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -c do in dirs?
Clear the directory stack.