z 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

z 命令安装:


-bash/zsh: z command not found

#Arch Linux
pacman -S z

#OS X
brew install z

-------------------------
手动安装:

# /usr/local 安装
$ cd /usr/local
$ sudo git clone https://github.com/rupa/z.git
$ sudo chmod +x z.sh

# zsh 配置变量
$ echo '. /usr/local/z/z.sh' >> ~/.zshrc
$ source ~/.zshrc

# bash 配置变量
$ echo '. /usr/local/z/z.sh' >> ~/.bash_profile
$ source ~/.bash_profile

# 安装 manpage
$ cp z.1 /usr/local/share/man/man1

# 验证安装
$ z -h
$ man z

z 命令补充说明:


z 命令,跟踪最常用的目录并使用字符串或正则表达式模式快速导航到它们。

PSFrecency 是由 Mozilla 开发,将访问的频率和新近度(上一次访问到现在的时间差)合并为一个度量的启发式方法。

技巧:z 命令可以使用 tab 来进行补齐,以提高切换效率。

z 命令语法:


z [-chlrtx] [regex1 regex2 ... regexn]

z 命令选项:


-c     限制匹配到当前目录的子目录 / restrict matches to subdirectories of the current directory

-e     回显最佳匹配,不要 cd / echo the best match, don't cd

-h     显示简短的帮助信息 / show a brief help message

-l     只列出 / list only

-r     仅按排名匹配 / match by rank only

-t     仅按最近访问匹配 / match by recent access only

-x     从数据文件中删除当前目录 /remove the current directory from the datafile

z 命令实例:


z 命令,转到名称中包含 “foo” 的目录:

z foo

z 命令,转到包含“foo”和 “bar” 的目录:

z foo bar

z 命令,转到与 “foo” 匹配的排名最高的目录:

z -r foo

z 命令,转到最近访问的匹配 “foo” 的目录:

z -t foo

z 命令,列出 `z` 的数据库中与 “foo” 匹配的所有目录:

z -l foo

z 命令,从 `z` 的数据库中删除当前目录:

z -x .

z 命令其他技巧:


Data is stored in $HOME/.z. This can be overridden by setting the $_Z_DATA environment variable. When initialized, z will raise an error if this path is a directory, and not function correctly.
Installation:
       Put something like this in your $HOME/.bashrc or $HOME/.zshrc:

              . /path/to/z.sh

       cd around for a while to build up the db.

       PROFIT!!

       Optionally:
              Set $_Z_CMD to change the command name (default z).
              Set $_Z_DATA to change the datafile (default $HOME/.z).
              Set  $_Z_MAX_SCORE  lower  to  age  entries  out faster (default
              9000).
              Set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution.
              Set $_Z_NO_PROMPT_COMMAND to handle PROMPT_COMMAND/precmd  your-
              self.
              Set $_Z_EXCLUDE_DIRS to an array of directory trees to  exclude.
              Set $_Z_OWNER to allow usage when in 'sudo -s' mode.
              (These  settings  should  go  in  .bashrc/.zshrc before the line
              added above.)
              Install the provided man page z.1  somewhere  in  your  MANPATH,
              like /usr/local/man/man1.

z 命令扩展阅读:




z 命令评论