Win10 Powershell实现类似Linux指定tree命令展示深度
2020-02-10 18:33
921 查看
前言
今天又是远程上班的一天,愿NCP病毒早日过去……
用惯了Linux上的tree命令来展示目录结构,今天远程Win10上,需要通过目标结构写一些脚本,查看了下Powershell是默认有个tree命令的,但是不支持指定深度
所以,这篇文章主要是实现tree命令展示指定深度的目录结构功能
看了下Powershell官网的确有这个插件,描述是下边这shai er 的,大意是实现了命令行的通用功能 官网
PowerShell Community Extensions (PSCX) base module which implements a general purpose set of Cmdlets.
安装Powershell插件——Pscx
安装Pscx 3.2.2, 前边的命令是说安装这个插件的指定版本,后边的
-Scope CurrentUser表示此扩展仅作用于当前登录用户,
-AllowClobber是安装时提示这个模块会覆盖现有命令的错误,规避它使用此参数
Install-Module -Name Pscx -RequiredVersion 3.2.2 -Scope CurrentUser -AllowClobber
出现如下提示,直接输入A,回车
PS D:\com-workspace\enterprise> Install-Module -Name Pscx -RequiredVersion 3.2.2 -Scope CurrentUser -AllowClobber 不受信任的存储库 你正在从不受信任的存储库安装模块。如果你信任该存储库,请通过运行 Set-PSRepository cmdlet 更改其 InstallationPolicy 值。是否确实要从“PSGallery”安装模块? [Y] 是(Y) [A] 全是(A)
否(N) [L] 全否(L) [S] 暂停(S) [?] 帮助 (默认值为“N”): A
测试
Pscx扩展中有个命令叫做
Show-Tree,查看此命令的参数列表可以有哪些
PS D:\com-workspace\enterprise> get-help show-tree 名称 Show-Tree 摘要 Shows the specified path as a tree. 语法 Show-Tree [[-Path] <String[]>] [[-Depth] <Int32>] [-Force] [-IndentSize <Int32>] [-ShowLeaf] [-ShowProperty] [-Excl udeProperty <String[]>] [-Width <Int32>] [-UseAsciiLineArt] [<CommonParameters>] Show-Tree [[-LiteralPath] <String[]>] [[-Depth] <Int32>] [-Force] [-IndentSize <Int32>] [-ShowLeaf] [-ShowProperty] [-ExcludeProperty <String[]>] [-Width <Int32>] [-UseAsciiLineArt] [<CommonParameters>] 说明 Shows the specified path as a tree. This works for any type of PowerShell provider and can be used to explore prov iders used for configuration like the WSMan provider. 相关链接 备注 若要查看示例,请键入: "get-help Show-Tree -examples". 有关详细信息,请键入: "get-help Show-Tree -detailed". 若要获取技术信息,请键入: "get-help Show-Tree -full".
使用
Show-Tree 目录 -Depth 深度数,就可以了(目录如果是当前,可以省略)
相关文章推荐
- Linux实现查看组是否包括指定用户名的命令
- linux 命令展示该目录下的所有子目录及文件结构 tree
- linux下用find命令执行类似windows查找包含指定内容的文件
- Linux--tree命令实现
- Linux中tree命令的C语言实现
- linux系统调用之文件:递归实现tree命令
- Solaris下类似DOS下tree命令的实现
- Python实现 Linux tree命令:用树形结构显示目录结构
- linux 命令展示该目录下的所有子目录及文件结构 tree
- 【转】巧用DOS tree命令+批处理 实现 指定文件 批量复制!
- Linux tree命令 简单实现
- linux下利用pipe函数实现类似 “cat a.txt | grep a”的管道命令
- linux嵌入式: 实现自己的tree命令
- 在linux下代码实现ls -l 命令(利用移位 和 与 操作 对指定位的分离 )(指定位段的分离)
- linux下tree、命令的用法及实现代码
- 用Python实现Linux tree命令
- linux命令: tree的c实现
- python3 实现 linux 命令 tree
- linux netlink套接字实现类似ss命令 ,统计套接字以及TCP信息
- linux命令深度使用 –pstree(process status tree)