Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Move multiple files to different directory using a single command

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by Soham
Soham's Unix or Linux Image
Soham Soham is offline
Registered User
 
Join Date: Sep 2007
Last Activity: 18 June 2018, 3:48 PM EDT
Location: UNIX
Posts: 76
Thanks: 20
Thanked 1 Time in 1 Post
Move multiple files to different directory using a single command

I have multiple files test1, test2, test3 etc. I want to move to a different directory with ABC_ prefixed to every file and and current dat time as postfix using a single command. (I will be using this is sftp with ! (command for local server).

I have tried the following but it gives error



Code:
cp * /other_dir/ABC_{*}_`date +%m%d%y`

Sponsored Links
    #2  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by Soham
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is online now Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 22 June 2018, 10:40 AM EDT
Location: Simplicity
Posts: 4,124
Thanks: 359
Thanked 1,402 Times in 1,259 Posts
With a classic for loop:


Code:
for f in *; do cp "$f" /other_dir/ABC_"$f"_`date +%m%d%y`; done

The Following User Says Thank You to MadeInGermany For This Useful Post:
Soham (4 Weeks Ago)
Sponsored Links
    #3  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by Soham
Soham's Unix or Linux Image
Soham Soham is offline
Registered User
 
Join Date: Sep 2007
Last Activity: 18 June 2018, 3:48 PM EDT
Location: UNIX
Posts: 76
Thanks: 20
Thanked 1 Time in 1 Post
Thanks. In fact I wanted a single command, but this will work for me
    #4  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by Soham
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is online now Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 22 June 2018, 10:40 AM EDT
Location: Simplicity
Posts: 4,124
Thanks: 359
Thanked 1,402 Times in 1,259 Posts
I think only mmv can do it with one command.


Code:
mmv -c "*" /other_dir/ABC_"#1"_`date +%m%d%y`

Sponsored Links
    #5  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by Soham
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 22 June 2018, 8:24 AM EDT
Location: Aachen, Germany
Posts: 12,917
Thanks: 429
Thanked 3,967 Times in 3,648 Posts
Is the rename (perl?) utility available at your target host?
Sponsored Links
    #6  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by Soham
Soham's Unix or Linux Image
Soham Soham is offline
Registered User
 
Join Date: Sep 2007
Last Activity: 18 June 2018, 3:48 PM EDT
Location: UNIX
Posts: 76
Thanks: 20
Thanked 1 Time in 1 Post
RudiC,

perl is available. Not rename UNIX command.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sftp multiple files in single command sid2013 UNIX for Dummies Questions & Answers 3 12-18-2013 08:04 AM
Single command to create multiple empty files(no trailing lines as well). Onkar Banerjee Shell Programming and Scripting 4 09-05-2013 05:28 AM
Empty out multiple files with a single command? Validatorian Shell Programming and Scripting 4 01-16-2012 04:08 PM
Grep multiple strings in multiple files using single command gagan4599 UNIX for Dummies Questions & Answers 2 01-19-2011 06:22 AM
how to rename multiple files with a single command tayyabq8 Shell Programming and Scripting 5 03-18-2008 04:04 PM



All times are GMT -4. The time now is 10:58 AM.