我有很多 以375.20 结尾的库文件.需要修改后缀为375.66
[root@ps3cat5505k1 NVIDIA-Linux-x86-375.20]# ls
glext.h libGLX.so.0 libvdpau_nvidia.so.375.20 nvidia-modprobe
gl.h libglx.so.375.20 libvdpau.so.375.20 nvidia-modprobe.1.gz
glxext.h libnvcuvid.so.375.20 libvdpau_trace.so.375.20 nvidia-persistenced
glx.h libnvidia-cfg.so.375.20 LICENSE nvidia-persistenced.1.gz
html libnvidia-compiler.so.375.20 makeself-help-script.sh nvidia-persistenced-init.tar.bz2
kernel libnvidia-eglcore.so.375.20 makeself.sh nvidia-settings
libcuda.so.375.20 libnvidia-egl-wayland.so.375.20 mkprecompiled nvidia-settings.1.gz
libEGL_nvidia.so.375.20 libnvidia-encode.so.375.20 monitoring.conf nvidia-settings.desktop
libEGL.so.1 libnvidia-fatbinaryloader.so.375.20 nvidia-application-profiles-375.20-key-documentation nvidia-settings.png
libEGL.so.375.20 libnvidia-fbc.so.375.20 nvidia-application-profiles-375.20-rc nvidia-smi
libGLdispatch.so.0 libnvidia-glcore.so.375.20 nvidia-bug-report.sh nvidia-smi.1.gz
libGLESv1_CM_nvidia.so.375.20 libnvidia-glsi.so.375.20 NVIDIA_Changelog nvidia-xconfig
libGLESv1_CM.so.1 libnvidia-gtk2.so.375.20 nvidia-cuda-mps-control nvidia-xconfig.1.gz
libGLESv1_CM.so.375.20 libnvidia-gtk3.so.375.20 nvidia-cuda-mps-control.1.gz pci.ids
libGLESv2_nvidia.so.375.20 libnvidia-ifr.so.375.20 nvidia-cuda-mps-server pkg-history.txt
libGLESv2.so.2 libnvidia-ml.so.375.20 nvidia-debugdump README.txt
libGLESv2.so.375.20 libnvidia-opencl.so.375.20 nvidia-drm-outputclass.conf test-me
libGL.la libnvidia-ptxjitcompiler.so.375.20 nvidia_drv.so tls
libGL.so.1.0.0 libnvidia-tls.so.375.20 nvidia.icd tls_test
libGL.so.375.20 libnvidia-wfb.so.375.20 nvidia_icd.json tls_test_dso.so
libglvnd_install_checker libOpenCL.so.1.0.0 nvidia-installer
libGLX_nvidia.so.375.20 libOpenGL.so.0 nvidia-installer.1.gz
通过下面的脚本就可以简单修改.
之前想用rename 命令.发现在RHEL上面无法使用.
shell 里面的截取字符串通常用#和%进行匹配.
使用 # 号操作符。用途是从左边开始删除第一次出现子字符串即其左边字符,保留右边字符
newName=${tmpFile#*375}375.66
得到的就是
[root@ps3cat5505k1 NVIDIA-Linux-x86-375.20]# srt=libnvidia-encode.so.375.66
[root@ps3cat5505k1 NVIDIA-Linux-x86-375.20]# echo ${str#*375}
.20
[root@ps3cat5505k1 NVIDIA-Linux-x86-375.20]# echo ${str#*so.}
375.20
[root@ps3cat5505k1 NVIDIA-Linux-x86-375.20]#
使用 % 号操作符。用途是从右边开始删除第一次出现子字符串即其右边字符,保留左边字符。用法为%substr*
#!/bin/sh
for aFile in *.375.20; do
tmpFile=`basename $aFile`
newName=${tmpFile%375*}375.66#右面开始,
echo 原文件名:${tmpFile}
echo 新文件名:${newName}
mv $tmpFile $newName
done