Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

renaming and moving files with new name.

Status
Not open for further replies.

jestrada101

Technical User
Mar 28, 2003
332
I have a list of files.
file1.txt
file2.txt
file3.txt
file4.txt

I want to mvoe them to /tmpa/
but then have them named
file1
file2
file3
file4

Is there a quick command that will chop off the .txt for me and move the files?

Thanks!
JE
 
sed 's!\(.*\)\.txt!mv \1.txt /tmpa/\1!' /path/to/listoffiles | sh

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi

On my SuSE I have a [tt]rename[/tt] command :

Code:
rename ".txt" "" /tmpa/file*.txt

On some Debians I so a [tt]rename[/tt] with abit different syntax, but with the same capabilities. Take a look on your machine, is possible to have something similar.

Feherke.
 
this doesn't seem to be working for me and I do not have a rename command.

sed 's!\(.*\)\.txt!mv \1.txt /tmpa/\1!' /path/to/listoffiles | sh
 
/path/to/listoffiles is the name of the file containing the list of files.
If I misunderstood your original post (ie you DON'T have a list of files) you may try this:
ls *.txt | sed 's!\(.*\)\.txt!mv \1.txt /tmpa/\1!' | sh

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top