-2

can anyone help me?? I want rename file from

Chat WhatsApp dengan A3 - 21.mp4
Mine.mp4
MoviMax_MV1_V016_2.106.001_20150227_2030_fbf.mp4
bedrock_server.mp4

to

test1.mp4
test2.mp4
test3.mp4
test4.mp4

how do i do it??

  • Did you try something and have some specific problem? Have you tried `mv "Chat WhatsApp dengan A3 - 21.mp4" test1.mp4`? – kaylum Dec 29 '20 at 05:32
  • I've tried "mv Chat WhatsApp dengan A3 - 21.mp4 test1.mp4" but actually there are 143 files, and I think it seems like use "mv" command for 143 files is a waste of time, is there a simpler and faster way?? like using the "for" or "while" command – Sokedgy Mwmwng Dec 29 '20 at 05:44
  • Yes there is (you should update your question to make it clearer that that is what you are asking about). But SO is not a place to ask for complete code. Do research (e.g. learn bash scripting), make an attempt at the code and then ask a specific question about the code. – kaylum Dec 29 '20 at 05:45
  • In a directory of 143 files, there will not be a portable way, without using the original names to do so. LOCALE will impact sort order. You can loop and move using `test` and a suffix of increasing numbers, but if you have a requirement to map specific names to `testXXX` you will have to use a `mv` of individual files as shown by @RiccoD – David C. Rankin Dec 29 '20 at 05:53
  • Possible duplicate of https://stackoverflow.com/questions/65474842/how-to-rename-all-directories-on-a-terminal – tripleee Dec 29 '20 at 05:54
  • You could write some program in C, using [nftw(3)](https://man7.org/linux/man-pages/man3/nftw.3.html), [opendir(3)](https://man7.org/linux/man-pages/man3/opendir.3.html), [rename(2)](https://man7.org/linux/man-pages/man2/rename.2.html) and other [syscalls(2)](https://man7.org/linux/man-pages/man2/syscalls.2.html). See also [path_resolution(7)](https://man7.org/linux/man-pages/man7/path_resolution(7)) and [credentials(7)](https://man7.org/linux/man-pages/man7/credentials.7.html). Or in C++ with [Qt](http://qt.io/) or [POCO](https://pocoproject.org/) – Basile Starynkevitch Dec 29 '20 at 05:59
  • Why stop there? You could write it in 8086 assembly! – tripleee Dec 29 '20 at 06:03

1 Answers1

1

Just use the "mv" command to rename the files.

Usage: mv original_file renamed_file

Just take note of files with space, you will need to add back slash (\) before the space so it will be considered as "space".

mv Chat\ WhatsApp\ dengan\ A3\ -\ 21.mp4 test1.mp4
mv Mine.mp4 test2.mp4
mv MoviMax_MV1_V016_2.106.001_20150227_2030_fbf.mp4 test3.mp4
mv bedrock_server.mp4 test4.mp4
Ricco D
  • 6,873
  • 1
  • 8
  • 18