LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-01-2008, 10:28 AM   #1
siva19185
LQ Newbie
 
Registered: Jun 2008
Posts: 21

Rep: Reputation: 15
Move directory of files


I have series of files

one.txt two.txt three.txt four.txt and so on into the directory TXT,

I want to move these files to TXT.BACKUP directory like

one.txt.backup two.txt.backup three.txt.backup four.txt.backup....

can anyone guide me......
 
Old 07-01-2008, 11:28 AM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
If you have a backup directory then you probably don't need to rename every file in the backup directory. I would do this.
Code:
cp -R TXT TXT.BACKUP

Last edited by stress_junkie; 07-01-2008 at 11:37 AM.
 
Old 07-01-2008, 11:41 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
It will probably work best if you cd into your TXT directory.

Code:
cd TXT
   for file in *.txt; do
   mv "$file" ../TXT.BACKUP/"${file}.backup"
done
Since you want to move them instead of making a copy, adding .backup at the end seems odd to me because the originals are deleted.

After the "in" in the for loop you could have a space separated list of files if there are a handful of particular files that you want to backup:
for file in one.txt two.txt three.txt

Last edited by jschiwal; 07-01-2008 at 11:44 AM.
 
Old 07-02-2008, 02:59 AM   #4
siva19185
LQ Newbie
 
Registered: Jun 2008
Posts: 21

Original Poster
Rep: Reputation: 15
Thank u pals...

It's work very well..

Last edited by siva19185; 07-02-2008 at 03:03 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to create a script to move files from one directory to another mustang05 Solaris / OpenSolaris 4 06-16-2006 10:25 AM
loop move files up one directory level Melsync Programming 8 12-19-2005 10:51 PM
how to write a script to move files from one directory to another myeire Linux - Newbie 7 02-25-2005 10:01 AM
denied access to move files into /usr/src directory Larry O Linux - Newbie 4 01-17-2005 11:14 PM
Does anyone know how to move files to a particular directory using shell scripting RowanB Programming 3 11-11-2004 01:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration