zoukankan      html  css  js  c++  java
  • Win10 Powershell实现类似Linux指定tree命令展示深度

    前言

    今天又是远程上班的一天,愿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-workspaceenterprise> Install-Module -Name Pscx -RequiredVersion 3.2.2 -Scope CurrentUser -AllowClobber
    
    不受信任的存储库
    你正在从不受信任的存储库安装模块。如果你信任该存储库,请通过运行 Set-PSRepository cmdlet 更改其 InstallationPolicy
    值。是否确实要从“PSGallery”安装模块?
    [Y] 是(Y)  [A] 全是(A)  [N] 否(N)  [L] 全否(L)  [S] 暂停(S)  [?] 帮助 (默认值为“N”): A
    

    测试

    Pscx扩展中有个命令叫做Show-Tree,查看此命令的参数列表可以有哪些

    PS D:com-workspaceenterprise> 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 深度数,就可以了(目录如果是当前,可以省略)

  • 相关阅读:
    关于dllimport的使用
    公众平台返回原始数据为: 错误代码-40164
    CentOS7.4 系统下 Tomcat 启动慢解决方法
    PyCharm实现高效远程调试代码
    代码比较工具推荐
    CentOS7 下源码安装 python3
    linux定时任务调度定系统——opencron
    使用 ISO镜像配置 本地yum 源(RHEL, CentOS, Fedora等适用)
    Error: rpmdb open failed
    部署Redis(脚本安装)
  • 原文地址:https://www.cnblogs.com/hellxz/p/12292047.html
Copyright © 2011-2022 走看看