How to rename files to exclude the datetime stamp?

user513724

I would like to have a regex that will rename my files. Microsoft Windows has changed my files' names and I want to remove the parenthetical datetime substring from the filenames.

Here are some sample filenames:

icon-culture (2015_09_04 06_58_44 UTC).png
icon-disk (2015_09_04 06_58_44 UTC).png
icon-download (2015_09_04 06_58_44 UTC).png
icon-drop (2015_09_04 06_58_44 UTC).png
icon-file (2015_09_04 06_58_44 UTC).png
icon-film (2015_09_04 06_58_44 UTC).png
icon-flag (2015_09_04 06_58_44 UTC).png
icon-folder (2015_09_04 06_58_44 UTC).png
icon-garbage (2015_09_04 06_58_44 UTC).png
icon-graph (2015_09_04 06_58_44 UTC).png
icon-heart (2015_09_04 06_58_44 UTC).png
icon-help (2015_09_04 06_58_44 UTC).png
icon-lock (2015_09_04 06_58_44 UTC).png
icon-map (2015_09_04 06_58_44 UTC).png
icon-media (2015_09_04 06_58_44 UTC).png
icon-money (2015_09_04 06_58_44 UTC).png
icon-monitor (2015_09_04 06_58_44 UTC).png
icon-notes (2015_09_04 06_58_44 UTC).png
icon-openmail (2015_09_04 06_58_44 UTC).png
icon-phone (2015_09_04 06_58_44 UTC).png
icon-photo (2015_09_04 06_58_44 UTC).png

My desired filenames after renaming are:

icon-culture.png
icon-disk.png
icon-download.png
icon-drop.png
icon-file.png
icon-film.png
icon-flag.png
icon-folder.png
icon-garbage.png
icon-graph.png
icon-heart.png
icon-help.png
icon-lock.png
icon-map.png
icon-media.png
icon-money.png
icon-monitor.png
icon-notes.png
icon-openmail.png
icon-phone.png
icon-photo.png

The tutorials that I found didn't do well for me because there are some special characters and numbers.

muru

You can use the rename command:

$ rename -n 's/ \(.*?\)//' *.png
icon-culture (2015_09_04 06_58_44 UTC).png renamed as icon-culture.png
icon-disk (2015_09_04 06_58_44 UTC).png renamed as icon-disk.png
icon-download (2015_09_04 06_58_44 UTC).png renamed as icon-download.png
icon-drop (2015_09_04 06_58_44 UTC).png renamed as icon-drop.png
icon-file (2015_09_04 06_58_44 UTC).png renamed as icon-file.png
icon-film (2015_09_04 06_58_44 UTC).png renamed as icon-film.png
icon-flag (2015_09_04 06_58_44 UTC).png renamed as icon-flag.png
icon-folder (2015_09_04 06_58_44 UTC).png renamed as icon-folder.png
icon-garbage (2015_09_04 06_58_44 UTC).png renamed as icon-garbage.png
icon-graph (2015_09_04 06_58_44 UTC).png renamed as icon-graph.png
icon-heart (2015_09_04 06_58_44 UTC).png renamed as icon-heart.png
icon-help (2015_09_04 06_58_44 UTC).png renamed as icon-help.png
icon-lock (2015_09_04 06_58_44 UTC).png renamed as icon-lock.png
icon-map (2015_09_04 06_58_44 UTC).png renamed as icon-map.png
icon-media (2015_09_04 06_58_44 UTC).png renamed as icon-media.png
icon-money (2015_09_04 06_58_44 UTC).png renamed as icon-money.png
icon-monitor (2015_09_04 06_58_44 UTC).png renamed as icon-monitor.png
icon-notes (2015_09_04 06_58_44 UTC).png renamed as icon-notes.png
icon-openmail (2015_09_04 06_58_44 UTC).png renamed as icon-openmail.png
icon-phone (2015_09_04 06_58_44 UTC).png renamed as icon-phone.png
icon-photo (2015_09_04 06_58_44 UTC).png renamed as icon-photo.png

s/ \(.*?\)// is a simple, if broad, expression, matching a space followed by parentheses-enclosed stuff. You can pick more precise expressions like:

  • s/ \(.*?\)\.png$/.png/ - like the previous, but matching only if followed by .png and the end of the filename, or
  • s/ \(\d{4}(_\d\d){2} \d\d(_\d\d){2} UTC\)\.png/.png/ - matching the date pattern shown in these files, and followed .png.

The -n option is for testing the command. Run without it if you're satisfied with the results.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to rename files with count?

分類Dev

How to rename files with count?

分類Dev

How to rename the set of files with pattern

分類Dev

How to rename files with different extensions

分類Dev

How do I rename the extension for a bunch of files?

分類Dev

How do I rename the extension for a bunch of files?

分類Dev

How do I rename all files to lowercase?

分類Dev

How to rename multiple files with different names at once?

分類Dev

How to rename all the files in a folder in numeric order?

分類Dev

how to tell rsync to preserve time stamp on files when source tree has a mounted point

分類Dev

Using rename to rename files and directories

分類Dev

How to rename multiple files in vscode (visual studio code)?

分類Dev

How to rename files in hdfs from spark more efficiently?

分類Dev

How do I rename several files in folders following the order of a list

分類Dev

Regex - Magento Magmi Import: How to rename image files correctly?

分類Dev

how to rename multiple files by replacing string in file name? this string contains a "#"

分類Dev

How to rename by removing last part name for multiple files

分類Dev

How can I bulk rename files taking into account some weights?

分類Dev

How does one rename multiple files using python?

分類Dev

How do I exclude files from karma code coverage report?

分類Dev

How to exclude all but certain files in the sidebar in Visual Studio Code?

分類Dev

how to exclude files while using gsutil rsync -x

分類Dev

How to exclude all hidden files and folders from duplicity backup

分類Dev

How can I exclude all subdirectories but include files of a directory in rsync?

分類Dev

Rename multiple files randomly

分類Dev

Efficient way to rename files

分類Dev

Exclude hidden files in Python

分類Dev

Delete and rename files using unlink() and rename()

分類Dev

How to log Serial data with time stamp?

Related 関連記事

  1. 1

    How to rename files with count?

  2. 2

    How to rename files with count?

  3. 3

    How to rename the set of files with pattern

  4. 4

    How to rename files with different extensions

  5. 5

    How do I rename the extension for a bunch of files?

  6. 6

    How do I rename the extension for a bunch of files?

  7. 7

    How do I rename all files to lowercase?

  8. 8

    How to rename multiple files with different names at once?

  9. 9

    How to rename all the files in a folder in numeric order?

  10. 10

    how to tell rsync to preserve time stamp on files when source tree has a mounted point

  11. 11

    Using rename to rename files and directories

  12. 12

    How to rename multiple files in vscode (visual studio code)?

  13. 13

    How to rename files in hdfs from spark more efficiently?

  14. 14

    How do I rename several files in folders following the order of a list

  15. 15

    Regex - Magento Magmi Import: How to rename image files correctly?

  16. 16

    how to rename multiple files by replacing string in file name? this string contains a "#"

  17. 17

    How to rename by removing last part name for multiple files

  18. 18

    How can I bulk rename files taking into account some weights?

  19. 19

    How does one rename multiple files using python?

  20. 20

    How do I exclude files from karma code coverage report?

  21. 21

    How to exclude all but certain files in the sidebar in Visual Studio Code?

  22. 22

    how to exclude files while using gsutil rsync -x

  23. 23

    How to exclude all hidden files and folders from duplicity backup

  24. 24

    How can I exclude all subdirectories but include files of a directory in rsync?

  25. 25

    Rename multiple files randomly

  26. 26

    Efficient way to rename files

  27. 27

    Exclude hidden files in Python

  28. 28

    Delete and rename files using unlink() and rename()

  29. 29

    How to log Serial data with time stamp?

ホットタグ

アーカイブ