LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 04-10-2020, 11:32 AM   #1
dave555
LQ Newbie
 
Registered: Dec 2019
Posts: 20

Rep: Reputation: Disabled
Does the cp command has a rename option?


Hello linux fans,

Does the cp command has a rename switch to prompt me to rename the file if a file exists?

The -i option will propmt to ovrrwrite the file.

Just curious to know if there is a rename option for cp or if there is a commnd that offers this option.

Thanks
 
Old 04-10-2020, 11:42 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
By typing the arguments for cp a certain way it will do the rename.

Perhaps you can expand your question because if one types:
Code:
$ cp orig-file.txt dest-file.txt
It makes a copy of orig-file.txt and names that copy to the name specified by dest-file.txt.

There is a rename command by the way.

If you're looking to make copies of multiple files, you can do that and then use rename, along with the find command to work in your favor, but we have little idea exactly what you're trying to do.
 
Old 04-10-2020, 11:49 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
You could look into the --backup option or maybe the --suffix option. See "man cp"

Code:
cp --archive --backup=numbered /source/* /destination/.

Last edited by Turbocapitalist; 04-10-2020 at 11:52 AM.
 
Old 04-10-2020, 12:47 PM   #4
dave555
LQ Newbie
 
Registered: Dec 2019
Posts: 20

Original Poster
Rep: Reputation: Disabled
This is what i wanted to do.

Code:
cp -v source/* dist/
if file(s) in source folder exist in dist folder with similar names, i would like cp to prompt me if i want to rename it.
 
Old 04-10-2020, 12:49 PM   #5
dave555
LQ Newbie
 
Registered: Dec 2019
Posts: 20

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
You could look into the --backup option or maybe the --suffix option. See "man cp"

Code:
cp --archive --backup=numbered /source/* /destination/.
I'm not at my computer right now, but i will try this and report the results. Thanks
 
Old 04-10-2020, 06:06 PM   #6
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by dave555 View Post
This is what i wanted to do.

Code:
cp -v source/* dist/
if file(s) in source folder exist in dist folder with similar names, i would like cp to prompt me if i want to rename it.
That command should do just that. Prompt you to OK the replacement of a target file. The verbose is not required, but won’t hurt.
 
Old 04-10-2020, 06:31 PM   #7
michaelsavage
Member
 
Registered: Apr 2019
Distribution: Linux Mint
Posts: 59

Rep: Reputation: 11
cp -i source/* dist/ will copy the files to the dist and ask if you want to overwrite the file
 
Old 04-10-2020, 06:59 PM   #8
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by michaelsavage View Post
cp -i source/* dist/ will copy the files to the dist and ask if you want to overwrite the file
cp -i will prompt for every file, whether or not there is a matching file in the destination. The message will be different if there is a matching file, but -i requires a response for each file in the source.

Probably the best way to see how things work is to just try them.
 
Old 04-10-2020, 08:22 PM   #9
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,980

Rep: Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624
Many of the members here are super at making scripts. To get more fine grain on your work maybe some script may do it??
 
  


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
LXer: How to Bulk Rename Files in Linux with Thunar’s Bulk Rename Tool LXer Syndicated Linux News 0 11-27-2019 07:03 PM
LXer: GUI To Batch Rename Files On Linux With Exif And Music Tags Support: Inviska Rename LXer Syndicated Linux News 0 05-25-2019 12:07 PM
LXer: How to rename user in Linux (also rename group & home directory) LXer Syndicated Linux News 0 06-26-2018 12:54 PM
LXer: How to rename user in Linux (also rename group & home directory) LXer Syndicated Linux News 0 11-28-2017 07:53 PM
Rename network interface (Rename ppp0 ...) Nicolas1390 Linux - Newbie 2 08-08-2011 02:14 AM

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

All times are GMT -5. The time now is 08:29 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