- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在同一个子目录中有两个版本的 tcpdump。
tcpdump-4.1.1 和 tcpdump-4.3.0
如何编写一个返回最高版本的 bash 函数?
编辑:
我现在已经开始工作了。这是代码。
#!/bin/bash
# Function to get the latest version of the directory
function getLatestDirVer {
latestDIR=$(ls -v $1* | tail -n 1)
stringLen=`expr length "$latestDIR"`
stringLen=$(($stringLen-1))
latestDIR2=`expr substr $latestDIR 1 $stringLen`
echo $latestDIR2
}
# Main function
echo $(getLatestDirVer tcpdump)
这是输出
[luke@machine Desktop]$ ./latestDIRversion.sh
tcpdump-4.3.0
tcpdump-4.1.1 和 tcpdump-4.3.0 目录位于桌面目录中。
最佳答案
这是使用 ls
的一种方法。您可以使用 -v
标志按文件名中的版本号从低到高排序:
ls -v tcpdump* | tail -n 1
编辑:
事实证明,我完全误读了你的问题。我以为您对文件名感兴趣,但实际上您对目录感兴趣。您可以将以下内容添加到您的 ~/.bashrc
,我认为它对您有用:
getLatestDirVer () {
for i in $(find ./* -type d | sort --version-sort); do :;done
cd "$i"
}
关于bash - 如何比较目录名称并输入最高版本的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12857637/
我是pyOpenSSL的新用户,我想用下面的代码制作一个证书 from OpenSSL import crypto as c cert = c.X509() cert.add_extensions([
我有很多包含文件的目录。我想创建一个逗号分隔的 txt 文件,显示目录名称以及该特定目录中的文件,请参见下面的示例: 我在找什么: DirName,Filename 999,123.tif 999,1
如何通过linux命令行将以下文件名(Windows支持的格式)替换为自定义名称。以下仅是一个示例案例。我的测试目录中有 100 多个文件,因此我需要一种自动化方式,而不是为每个文件手动输入“mv”命
我正在制作一个用 PHP 上传文件的表单。这些是我的输入: $file_name = filter_input(INPUT_POST, 'file_name'); $file = filter_i
所以有一个 ftp 服务器(在 Windows 上运行),其中包含一些我需要在我的 vps 上同步的数据。我一直在使用 curlftpfs +rsync 成功地完成这项任务,但最近我不得不添加新目录来
我正在使用 C++ 和 GDAL,进行一些基本练习。我想要构建的其中一件事是创建一个程序,该程序从目录名称中读取其中的文件,然后在 foor 循环中读取数据集并将波段写入新的虚拟栅格。我设法使用 bo
这个问题在这里已经有了答案: What's better of require(dirname(__FILE__).'/'.'myParent.php') than just require('my
我是 ns3 的新手。我有一些用 C++ 编写的简单程序。 我通过以下命令运行我的 ns3 程序 exec "`dirname "$0"`"/../../waf "$@" 谁能解释一下上述线路的功能?
我之前使用的是 statik将文件嵌入到 Go 应用程序中。 在 Go 1.16 中我可以移除那些依赖 例如: //go:embed static var static embed.FS fs :=
我正在尝试使用 Android Studio 构建我的第一个 android 应用程序。不幸的是,每次我打开我的项目时,尝试运行它或 gradle assemble 它我都会收到以下错误: Gradl
谁能解决这个问题?我认为问题可能出在传递给创建文件函数时的 readstring() 参数中。我尝试通过剥离 '\n' 来解决它,但错误仍然存在。除了 readstring() 之外还有其他解决方
如何编写一个名为“abc”的 bash shell 脚本,它接受一个参数,一个目录的名称,并将扩展名“.xyz”添加到目录中所有还没有它的可见文件 我主要编写了更改当前目录中文件名的代码,但我无法让脚
我想知道一种方法是否比另一种更好。我一直在使用 $_SERVER 方法指向当前目录,但是这种方法比 realpath(dirname(_FILE_)) 方法更好还是有什么区别? 最佳答案 $_SERV
我正在尝试重新启动 Jenkins,但它没有说以下错误。有没有人对此有任何线索? $ service jenkins restart Shutting down Jenkins killproc: E
我必须远程传输位于不同目录中的文件。目录与 Google Drive 同步,每天都有新内容添加。我想运行一个每天运行一次的脚本,并将传输新的目录。我可以处理选择新目录的部分。我正在使用 MATLAB
我正在eclipse中构建一个android应用程序。我需要调用用C/C++编写的函数。 我设置了包括NDK,cygwin等在内的所有内容(询问是否需要更多详细信息),但是当我尝试运行该项目时,出现此
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 6 年前。 Improve
我有这个代码: BufferedReader in = new BufferedReader (new InputStreamReader(System.in)); System.out.print(
关闭。这个问题需要details or clarity .它目前不接受答案。 想改善这个问题吗?通过 editing this post 添加详细信息并澄清问题. 去年关闭。 Improve this
我是一名优秀的程序员,十分优秀!