LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-07-2007, 11:50 PM   #1
thtr2k
Member
 
Registered: Mar 2005
Location: Australia
Posts: 71

Rep: Reputation: 15
bash script to copy files


Hi,
i want to write a bash script to copy files, but i encounter a minor problem. My command "mycp source destination" and check for the existence of the file being copied to the new location. eg mycp ~/dir1/file1.txt ~/abc/dir2 If in dir2 has file1.txt it should automatically be file2.txt (i want to increment the number because I tried with style file1.txt.bak but don't like the look of the extension) otherwise just do the normal copy. One more thing how do i break down the $2 (ie: ~/abc/dir2/file.txt or ./def/dir2/file.txt) as directory and file. coz i want too have a prompt if the directory doesn't exist either create or terminate.
Thanks.
 
Old 02-08-2007, 12:03 AM   #2
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
looking for this

Code:
basename ~/abc/dir2/file.txt
Code:
dirname ~/abc/dir2/file.txt
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 script to copy all files containing a certain string to a directory dc6463 Programming 21 04-18-2013 01:56 PM
BASH script to copy specific files ScottReed Linux - Software 5 07-20-2006 11:08 AM
script or utility to copy files and folders m2azer Linux - General 1 12-22-2005 10:09 AM
will this script copy only certain files? verbatim Programming 5 04-28-2005 09:28 AM
Using bash to copy files from the CD-ROM polyspaston Linux - General 6 01-13-2004 09:06 PM


All times are GMT -5. The time now is 10:13 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration