floki
floki

Reputation: 11

I need to rename multiple files by removing the multiple dates prefixing the files

I accidently renamed all of my files by adding a prefix multiple times to each directory. I have tried the "rename" command and some peaenter image description herel scripting but I still can't resolve name changes. Any ideas on how to remove all the dates at once so that I just have directory?

Example

mv 2020-11-30-2020-11-30...2020-11-30-Documents Documents/

Upvotes: 0

Views: 179

Answers (3)

roneo.org
roneo.org

Reputation: 419

Here is a solution which does not require the use of regex. Based on vimv and the multi-cursor edition in Vscode:

Both packages are shipped in most Linux distributions:

apt install vimv codium

Open a terminal and setup codium as your editor: export EDITOR="codium -w"

Browse the terminal in the appropriate folder and type vimv. Hit enter

Vscodium opens, and shows the list of files and folders

Add cursors where you want. Quoting from the doc:

You can add secondary cursors (rendered thinner) with Alt+Click. Another common way to add more cursors is with Shift+Alt+Down or Shift+Alt+Up that insert cursors below or above.

Delete whatever you want, save the file, and exit

The files and folders should be renamed accordingly

Checkout the website of vimv for more informations and screencasts

Upvotes: 0

floki
floki

Reputation: 11

These commands both worked:

ls -1 | sed 's/.*-\(.*\)/mv "&" "\1"/'
rename 's/2020-11-30-//g' 2020-11-30-*

Upvotes: 0

Kent
Kent

Reputation: 195039

mv 2020-11-30-2020-11-30...2020-11-30-Documents Documents/

Assuming your filenames don't contain linebreak, quotes. or other special chars:

\ls -1|sed 's/.*-\(.*\)/mv "&" "\1"/'

You can check the output produced by the above command, if it looks good, pipe the output to |sh

NOTE: the backslash before ls is for ignoring your alias if you had ls alias.

Upvotes: 1

Related Questions