Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 02-08-2007, 12:50 AM   #1
Registered: Mar 2005
Location: Australia
Posts: 71

Rep: Reputation: 15
bash script to copy files

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.
Old 02-08-2007, 01:03 AM   #2
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
looking for this

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


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

All times are GMT -5. The time now is 03:33 AM.

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