Chinaunix

标题: 请教如何批量修改文件名 [打印本页]

作者: fire_vr    时间: 2015-06-10 11:15
标题: 请教如何批量修改文件名
我的目录下有很多文件,如下:
都是以数字打头的,我想把前面的数字和-都去掉,比如0001-,0002-这些都去掉,保留剩下的。
rename好像做得到,请教,谢谢!
  1. 0001-msm-ipc-Update-server-lookup-operation-to-return-com.patch  0100-Revert-usb-host-Fix-array-access-to-a-non-verified-i.patch
  2. 0002-msm-ipc-Fix-the-logic-while-dumping-IPC-Router-routi.patch  0101-Revert-usb-host-Verify-sg-before-accessing-it-in-qh_.patch
  3. 0003-msm-ipc-Update-HELLO-message-processing.patch               0102-usb-gadget-mbim-protect-packets-queue-corruption.patch
  4. 0004-msm-ipc-Reorganize-server-hash-table.patch                  0103-diag-Increase-the-maximum-number-of-SSIDs-per-msg-ma.patch
  5. 0005-msm-ipc-Fix-lockdep-warning-by-IPC-message-router.patch     0104-msm-qdsp6v2-Deleting-kernel-driver-from-arch-arm-mac.patch
  6. 0006-msm-ipc-IPC-Router-updates-to-support-QMI-in-the-ker.patch  0105-msm-kgsl-Protect-against-a-potential-overflow-in-kgs.patch
  7. 0007-msm-ipc-Security-updates-to-IPC-Router.patch                0106-USB-u_serial-Don-t-free-usb_requests-in-gs_close-and.patch
  8. 0008-msm-ipc-Send-REMOVE_CLIENT-message-when-a-server-por.patch  0107-usb-gps-Fix-multiple-gps-setup-issue.patch
  9. 0009-msm-ipc-Add-SMD-link-to-interface-with-WCNSS.patch          0108-csdio-Remove-the-driver.patch
  10. 0010-msm-ipc-Allow-QMI-clients-to-send-messages-after-IRS.patch  0109-Bluetooth-Replace-sprintf-with-snprintf.patch
  11. 0011-msm-ipc-Advertise-service-information-only-from-aliv.patch  0110-msm-qdsp6v2-memset-stack-buffer-allocation.patch
  12. 0012-msm-ipc-Cache-the-length-of-a-packet-being-looped-ba.patch  0111-msm-kgsl-Change-an-overflow-check-to-be-smart-compil.patch
  13. 0013-msm-ipc-Update-the-wakelock-naming-format-for-the-lo.patch  0112-ASoC-msm-Add-Buffer-overflow-check.patch
  14. 0014-msm-ipc-Add-check-to-avoid-integer-buffer-overflow.patch    0113-usb-Fix-compilation-error-when-usbnet-and-hsic-are-e.patch
  15. 0015-msm-ipc-Enable-IPC-logging-on-MDM9615.patch                 0114-USB-gadget-ether-Fix-memory-corruption-issues-with-m.patch
  16. 0016-lib-qmi-Introduce-QMI-Encode-Decode-library.patch           0115-msm-rpm-regulator-smd-correct-use-after-free-in-rpm_.patch
  17. 0017-msm-ipc-Add-support-for-IPC-Logging.patch                   0116-msm-acpuclock-cortex-Fix-off-by-one-error-for-large-.patch
  18. 0018-msm-ipc-Change-IPC-log-file-name-for-IPC-Router.patch       0117-msm-buspm-Correct-size-type-in-buspm_xfer_req.patch
  19. 0019-msm-ipc-Add-IPC-Logging-support-to-IPC-Router.patch         0118-Revert-msm-msm_bus-Add-NULL-pointer-checks.patch
  20. 0020-msm-ipc-Update-recvmsg-operation-to-be-non-blocking-.patch  0119-msm-msm_bus-Add-NULL-pointer-checks.patch
复制代码

作者: reyleon    时间: 2015-06-10 11:52
  1. for file in *.patch; do mv "$file" $(echo "$file"| sed 's/^[0-9]*-//');done
复制代码

作者: liuyu85    时间: 2015-06-10 12:05
本帖最后由 liuyu85 于 2015-06-10 12:06 编辑
  1. cd dir
  2. ls|while read fn; do mv $fn ${fn#*-}; done
复制代码

作者: WilliBhamlll    时间: 2015-06-10 12:06
  1. ls|sed -r 's/^[0-9]{4}-(.*)/mv & \1/e'
复制代码

作者: 聆雨淋夜    时间: 2015-06-10 12:10
cd到那个目录下,for i in `ls`;do mv $i ${i#*-}; done
作者: 我爱你我的菜    时间: 2015-09-07 11:23
回复 4# WilliBhamlll


    生效不了




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2