Use 'Rename' command in terminal? (Solved)

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
Clarity
Posts: 3367
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1387 times
Been thanked: 446 times

Use 'Rename' command in terminal? (Solved)

Post by Clarity »

I am trying to use the 'rename' terminal command and need help.

I have 3 files in a folder: Class.txt Agenda.txt Notes.txt

I want to RENAME the 3 files, automatically, to filenames without the ".txt".

In a terminal (on FossaPUP64/Slacko64), I do the following:

Code: Select all

# cd folder
# ls
Agenda.txt  Class.txt  Notes.txt
# rename 's/.txt//' *
# ls
Agenda.txt  Class.txt  Notes.txt

The filenames remain the same no matter the rename operator I use.

Can anyone guide me to correct use of the rename command, please?

Last edited by Clarity on Thu May 13, 2021 6:04 pm, edited 2 times in total.
tosim
Posts: 439
Joined: Thu Jul 23, 2020 1:13 pm
Has thanked: 736 times
Been thanked: 50 times

Re: RENAME command use

Post by tosim »

I suggest: Open terminal, type "man rename" without quotes, and it will give you the info.

Clarity
Posts: 3367
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1387 times
Been thanked: 446 times

Re: RENAME command use

Post by Clarity »

Have you tried that?

User avatar
Flash
Moderator
Posts: 909
Joined: Tue Dec 03, 2019 3:13 pm
Location: Arizona, U.S.
Has thanked: 47 times
Been thanked: 109 times

Re: How to use 'Rename' command in terminal?

Post by Flash »

I just entered 'rename --help' into a Sakura console and got this:

Code: Select all

# rename --help

Usage:
 rename [options] <expression> <replacement> <file>...

Rename files.

Options:
 -v, --verbose       explain what is being done
 -s, --symlink       act on the target of symlinks
 -n, --no-act        do not make any changes
 -o, --no-overwrite  don't overwrite existing files
 -i, --interactive   prompt before overwrite

 -h, --help          display this help
 -V, --version       display version

For more details see rename(1).
# 

I typed 'man rename' into a Sakura console and it sent me here: https://linux.die.net/man/3/rename

Chaos coordinator :?
User avatar
misko_2083
Posts: 196
Joined: Wed Dec 09, 2020 11:59 pm
Has thanked: 10 times
Been thanked: 20 times

Re: How to use 'Rename' command in terminal?

Post by misko_2083 »

It takes a few seconds to find an anwser with my Nokia 2.1 with this Googleware on top of linux kernel. https://unix.stackexchange.com/question ... sion#34550

I would usually use mv instead, but since your choice is rename here's the online manual
https://www.man7.org/linux/man-pages/man1/rename.1.html

Do you want to exit the Circus? The Harsh Truth
https://www.youtube.com/watch?v=ZJwQicZHp_c

Clarity
Posts: 3367
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1387 times
Been thanked: 446 times

Re: How to use 'Rename' command in terminal?

Post by Clarity »

The problem I am having is that the command implementation is not working.

I AM wondering if it is a bug or a command misuse. There are no error messages, so I am clueless and appealing for help/insights.

Anyone else tried to do such? Did it work on your system?

Curious. Thanks in advance.

Clarity
Posts: 3367
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1387 times
Been thanked: 446 times

<Solution> Use of 'Rename' command in terminal?

Post by Clarity »

Looks like there is 2 LInux RENAME commands
For FossaPUP64 & Slacko64, the following syntax works:

Code: Select all

rename -- .txt  '' *

Where

  1. "-- .txt" is what you want to scan for

  2. and " '' " is what you those found to change to

  3. '*' is for all filenames found in the folder.

Thanks for all attempts to help me.

P.S. The command is "lightening" fast for small use or large number of filenames.

User avatar
Flash
Moderator
Posts: 909
Joined: Tue Dec 03, 2019 3:13 pm
Location: Arizona, U.S.
Has thanked: 47 times
Been thanked: 109 times

Re: Use 'Rename' command in terminal? (Solved)

Post by Flash »

Rox Filer has an excellent batch rename function. Check it out. In Rox, highlight the group of files you want to rename, right-click and choose Rename.

Chaos coordinator :?
Post Reply

Return to “Programming”