skip to Main Content

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/

3

Answers


  1. Chosen as BEST ANSWER

    These commands both worked:

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

  2. 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.

    Login or Signup to reply.
  3. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search