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.
Something like this:
Last edited by balajesuri; 05-06-2015 at 01:08 AM..
Store all file name in one temporary file
ls *filename*.doc > Temp.tmp
Now use the loop to remove value line by line
For Line in $(cat Temp.tmp);
do mv Line "yourSting".line;
done
This will give a good idea on how to do it
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
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)
hth & hf
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.
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
For Debian (this from Jessie):
For RedHat (this from Fedora 19, similar one available from CentOS 6.4 )
You may also be able to find an old shell script:
Note that the three are different from one another.
HI Guys,
I have some 8 files with different name and extensions. I need to check if they are present in a specific folder or not and also want that script to show me which all are not present. I can write if condition for each file but from a developer perspective , i feel that is not a good... (3 Replies)
What am I missing?
find: 0652-009 There is a missing conjunction
find: 0652-009 There is a missing conjunction
find: 0652-009 There is a missing conjunction
find: 0652-009 There is a missing conjunction
find: 0652-009 There is a missing conjunction
find: 0652-009 There is a missing... (3 Replies)
I've been googling for days but can't find a solution to this problem.
I have a number of sets of files on a server
file02.dat
.
.
file12.dat
/.../fred(1 to n)/bill(1 to m)/tony/joe/
in any "fred" branch there will be one or more "bill"s
some joe/'s may not have a fileset and... (4 Replies)
hi im new to linux and was just wondering if some 1 could help me
i have folders with T.V. series in them and i would like to delete part of the filename
e.g.
(series name).s01e01.(episode name)
(series name).s01e02.(episode name)
(series name).s01e03.(episode name)
(series... (4 Replies)
Hi is it possible to change multiple files (~10k) names with out disturbing the data in it. ?
input
Hynda|cgr10(+):100027702-1000312480|.txt
Hynda|cgr10(+):100027702-1000312483|.txt
Hynda|cgr10(+):100027702-1000312484|.txt
Hynda|cgr10(+):100027702-1000312482|.txt
output... (4 Replies)
I hope some one can help me
I have multiple files in a directory with out extension like as below mentioned. But i want to change all the file names along .DDMMYYYYHHMISS format. And all files should have same DDMMYYYYHHMISS.
Scenario:
direcory name = /vol/best/srcfiles
files in a... (4 Replies)
Hello,
I have some files in a directory like:
01_07_2010_aa.txt
01_07_2010_bb.txt
01_07_2010_cc.txt
01_07_2010_dd.txt
01_07_2010_ee.txt
01_07_2010_ff.txt
I want to change their names to :
3nm_aa.txt
3nm_bb.txt
3nm_cc.txt
3nm_dd.txt
3nm_ee.txt
3nm_ff.txt (8 Replies)
Hi Guys,
I need a help. I have 1130 zip files. Each one of them has files including 1 html file with long file name (includes special charactors, Alphabetic and numbers).
I have copied all 1130 zip files to my linux system and extracted using below command.
Find . -name "*.zip" -exec... (7 Replies)
Hi there,
I have a folder full of pdf's and I've run a compression on the to reduce the size, the output of the compress places a '-o' in the name of the file.
Before 12345.pdf
After 12345-o.pdf
Now I've got around 50000 files that I need to change back to the previous name, is... (3 Replies)
Hi there,
I hope someone can help me with this problem :
I have a directory (/var/www/file/imgprofil) which contains about 10000 JPG files. They have a naming convention thus :
prefix-date-key-suffix.jpg
they all have the prefix p-20050608-
then AAAA is a 4 letter code
the suffix is... (7 Replies)