Renaming can be done using mv command. But you cannot rename multiple files at once. You need to script it. I can think of one solution:
Have two arrays with the values of X and Y. Loop over them and for each value of X and Y, rename the file to desired format.
Try it out and let us know.
This is bad advice. That is a useless use of cat and a useless use of ls * and a useless use of backticks, not to mention a dangerous use of backticks! Also, a pointless use of temporary file. I often see two or three of these habits, but to see all five of them simultaneously is interesting. Remember that ls doesn't expand *, the shell does, so you can feed it straight into for.
A simpler and safer version is
for FILE in *filename*.doc
do
echo mv "$FILE" some-destination-string
done
Remove the echo once you've gotten some-destination-string as exactly what you want it to be.
Rudic, yours is better, but there's no point using a pipe there -- too many arguments for for would also be too many arguments for ls, it doesn't help you.
What i do, looks like:
(might be a little overkill for such a simple substitution, but for certain sed commands, this preview is just 'required' (feels alot more saver)!
(as in, i would had deleted (renamed to empty) quite a few files already)
EDIT:
What i'm saying is:
The more files you have (to rename), the more important it is to PRE-view the changes that will be done.
And having the strings aligned left and right of the screen/window just helps to compare, rather than having a list that is just space delimited. imho
All you need to do is to define a 'prefix' string, and add it in front of RudiC's example.
For RedHat (this from Fedora 19, similar one available from CentOS 6.4 )
NAME
rename - rename files
SYNOPSIS
rename [options] expression replacement file...
DESCRIPTION
rename will rename the specified files by replacing the first occur
rence of expression in their name by replacement.
You may also be able to find an old shell script:
# @(#) mved Rename, change filename by mv-ing with special pattern, =.
# $Id: mved 291 2007-10-23 11:26:32Z dennisl $
# See: http://raf.org/mved/
# From comp.sources.wizards & Martin Marietta at ornl, off Usenet.
# 90.09.27.
# mved.sh
# Move-and-edit filenames.
#
# Usage: mved [-n] from-pattern to-pattern
...
Note that the three are different from one another.
F22: dnf info rename shows nothing. man rename , shows the same though
Where the heck did that come from?
I'm 120% sure that rename was one of the first commands i've tried in the shell, and (in 2011) it showed "command not found"...
renameutils.x86_64 : A set of programs to make renaming and copying of files
: easier
Claims approved for F22 and earlier ... cheers, drl
---------- Post updated May 7th, 2015 at 06:38 ---------- Previous update was May 6th, 2015 at 13:38 ----------
Hi, sea.
Perhaps more usefully (all on Fedora 19):
yum whatprovides rename
produces (in part):
Loaded plugins: langpacks, refresh-packagekit
util-linux-2.23.1-3.fc19.x86_64 : A collection of basic system utilities
Repo : fedora
Matched from:
Filename : /usr/bin/rename
...
And also:
yum info ren
produces:
Loaded plugins: langpacks, refresh-packagekit
Available Packages
Name : ren
Arch : x86_64
Version : 1.0
Release : 18.fc19.2.1
Size : 14 k
Repo : fedora/19/x86_64
Summary : Rename multiple files
URL : http://linux.maruhn.com/sec/ren.html
License : Public Domain
Description : Whereas mv can rename (as opposed to move) only one file at a
: time, ren can rename many files according to search and
: replacement patterns, ala VMS and MS-DOS (but better). ren checks
: for replacement name collisions and handles rename chains (1 goes
: to 2 goes to 3 etc.) gracefully.