linux 操作系统下的dirs 命令介绍和使用案例

linux 操作系统下的dirs 命令介绍和使用案例

dirs 命令介绍

dirs 是一个 shell 内置命令,用于显示当前记住的目录列表。它通常与 pushdpopd 命令一起使用,允许用户在多个目录之间快速切换

基本语法

bash

dirs [OPTION] [+N] [-N]

  • OPTION:可选参数,用于控制输出格式。
  • +N:显示从左边数的第 N 个条目。
  • -N:显示从右边数的第 N 个条目。

常用选项

选项描述
-c清空记住的目录列表。
-l不显示家目录的路径。
-p每行显示一个条目。
-v每行显示一个条目,并在前面加上从 0 开始的索引。

命令介绍

root@meng:~# dirs
~
root@meng:~# which dirs
root@meng:~# dirs --help
dirs: dirs [-clpv] [+N] [-N]
    Display directory stack.
    
    Display the list of currently remembered directories.  Directories
    find their way onto the list with the `pushd' command; you can get
    back up through the list with the `popd' command.
    
    Options:
      -c    clear the directory stack by deleting all of the elements
      -l    do not print tilde-prefixed versions of directories relative
            to your home directory
      -p    print the directory stack with one entry per line
      -v    print the directory stack with one entry per line prefixed
            with its position in the stack
    
    Arguments:
      +N    Displays the Nth entry counting from the left of the list
            shown by dirs when invoked without options, starting with
            zero.
    
      -N    Displays the Nth entry counting from the right of the list
            shown by dirs when invoked without options, starting with
            zero.
    
    Exit Status:
    Returns success unless an invalid option is supplied or an error occurs.
root@meng:~# 

命令案例

root@meng:~# dirs
~
root@meng:~# dirs -p
~
root@meng:~# dirs -v
 0  ~
root@meng:~# dirs -l
/root
root@meng:~# pushd /data1
-bash: pushd: /data1: No such file or directory
root@meng:~# pushd /data
/data ~
root@meng:/data# pushd /tmp
/tmp /data ~
root@meng:/tmp# dirs
/tmp /data ~
root@meng:/tmp# dirs -p
/tmp
/data
~
root@meng:/tmp# dirs -v
 0  /tmp
 1  /data
 2  ~
root@meng:/tmp# dirs -l
/tmp /data /root
root@meng:/tmp# 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lisanmengmeng

蚊子腿也是肉

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值