linux_powershell/bash_获取相对路径对应的绝对路径(resolve-path/realpath)alias别名创建失败_找不到路径/

powershell_获取相对路径对应的绝对路径

reference

PS D:\repos\blogs> help path|sort category
Name Category Module Synopsis
---- -------- ------ --------
Convert-Path Cmdlet Microsoft.PowerShell.Man… Converts a path from a PowerShell path to a PowerShell provider path.
Join-Path Cmdlet Microsoft.PowerShell.Man… Combines a path and a child path into a single path.
Resolve-Path Cmdlet Microsoft.PowerShell.Man… Resolves the wildcard characters in a path, and displays the path contents.
Split-Path Cmdlet Microsoft.PowerShell.Man… Returns the specified part of a path.
Test-Path Cmdlet Microsoft.PowerShell.Man… Determines whether all elements of a path exist.
backupEnvs_regeditPrintPath Function functionsByCxxu …
Get-PromptPath Function posh-git …
Get-CMsmqMessageQueuePath Function Carbon …

从上述信息来看,resolve-path 似乎会是我们需要的cmdlet

  • 通过该命令查看用例 help Resolve-Path -Examples
    • 确实是我们想要的
    • NAME
      Resolve-Path
      SYNOPSIS
      Resolves the wildcard characters in a path, and displays the path contents.
      ----------- Example 1: Resolve the home folder path -----------
      PS C:\> Resolve-Path ~
      Path
      ----
      C:\Users\User01
      ------ Example 2: Resolve the path of the Windows folder ------
      PS C:\> Resolve-Path -Path "windows"
      Path
      ----
      C:\Windows
      When run from the root of the C: drive, this command returns the path of the Windows folder in the C: drive.
      -------- Example 3: Get all paths in the Windows folder --------
      PS C:\> "C:\windows\*" | Resolve-Path
      This command returns all of the folders in the C:\Windows folder. The command uses a pipeline operator (|) to send a path string to `Resolve-Path`.
      ---------------- Example 4: Resolve a UNC path ----------------
      PS C:\> Resolve-Path -Path "\\Server01\public"
      This command resolves a Universal Naming Convention (UNC) path and returns the shares in the path.
      ---------------- Example 5: Get relative paths ----------------
      PS C:\> Resolve-Path -Path "c:\prog*" -Relative
      .\Program Files
      .\Program Files (x86)
      .\programs.txt
      This command returns relative paths for the directories at the root of the C: drive.
      -------- Example 6: Resolve a path containing brackets --------
      PS C:\> Resolve-Path -LiteralPath 'test[xml]'

linux bash 获取文件绝对路径

例如

xaga:/sdcard/Download $ realpath swap-controller-3307-1031.zip
/storage/emulated/0/Download/swap-controller-3307-1031.zip

其他用法示例

realpath
Display the resolved absolute path for a file or directory.
More information: https://www.gnu.org/software/coreutils/realpath.
- Display the absolute path for a file or directory:
realpath path/to/file_or_directory
- Require all path components to exist:
realpath --canonicalize-existing path/to/file_or_directory
- Resolve ".." components before symlinks:
realpath --logical path/to/file_or_directory
- Disable symlink expansion:
realpath --no-symlinks path/to/file_or_directory
- Suppress error messages:
realpath --quiet path/to/file_or_directory

man realpath

REALPATH(1) User Commands REALPATH(1)
NAME
realpath - print the resolved path
SYNOPSIS
realpath [OPTION]... FILE...
DESCRIPTION
Print the resolved absolute file name; all but the last component must exist
-e, --canonicalize-existing
all components of the path must exist
-m, --canonicalize-missing
no path components need exist or be a directory
-L, --logical
resolve '..' components before symlinks
-P, --physical
resolve symlinks as encountered (default)
-q, --quiet
suppress most error messages
--relative-to=DIR
print the resolved path relative to DIR
--relative-base=DIR
print absolute paths unless paths below DIR
-s, --strip, --no-symlinks
don't expand symlinks
-z, --zero
end each output line with NUL, not newline
--help display this help and exit
--version
output version information and exit
AUTHOR
Written by Padraig Brady.

linux别名创建基本格式

alias <aliaseName>=<value>
最重要的是,等号两边和值必须紧密相联,没有空格,

正确示例

alias test1=~/dir/testFile

值带有空格的时候

需要为值用""包裹起来
例如
alias importConfig="source /home/cxxu/linuxShellScripts/importer.sh"

错误示例

下例子中,错误在于,别名importConfig和等号之间有一个空格!

alias importConfig ="source /home/cxxu/linuxShellScripts/importer.sh"
posted @   xuchaoxin1375  阅读(16)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示