Android Century
  • Home
  • Android Zone
    • Android Apps
    • Android Games
    • Apps APk Files
    • Games Apk Files
    • Apps Hack Tricks
  • Reviews
  • Fantasy Zone
    • Entertainment
    • Quotes and Status
    • Life Style
    • Home Made Tips
    • Hair Care
    • Skin Care
    • Fantasy Tips
  • Tricks
    • Free Recharge
    • Free Internet
    • shopping Cashback
    • Recharge Cashback
  • Tech
  • Mobiles
  • Gadgets
  • News
  • How To's
  • Software
Breaking
Loading...

Featured post

How to Take Great Photos With Apple's iPhone X

Recent Posts

Labels

  • Android Apk Files
  • Android Apps
  • Android Games
  • Apps Apk Files
  • Entertainment
  • Fantasy Tips
  • Gadgets
  • Hair Care
  • HomeMade Tips
  • How To's
  • News
  • Quotes
  • Quotes & Status
  • Recharge Cashback
  • Recharge Promo Codes
  • Shopping Cashback
  • Technology
  • skin care
Home / How To's / How to Copy File to Multiple Directories With One Command in Linux

How to Copy File to Multiple Directories With One Command in Linux

Latest Govt. Jobs 23:58:00 How To's Edit
00_lead_image_copying_to_three_locations_with_one_command
Copying a file with the Linux command line is easy. However, what if you want to copy the same file to several different locations? That’s easy, too, and we’ll show you how to do that with one command.
Normally, to copy one file, you would use the cp command, linking to the source file and the destination directory:
cp ~/Documents/FileToBeCopied.txt ~/TextFiles/
To copy it to two more directories, many people would just run the command two more times, with different destinations:
cp ~/Documents/FileToBeCopied.txt ~/Dropbox/
cp ~/Documents/FileToBeCopied.txt /media/lori/MYUSBDRIVE/
01_entering_cp_command_three_times
However, we can do the same task with one command:
echo dir1 dir2 dir3 | xargs -n 1 cp file1
Here’s how this command works. The echo command normally writes to the screen. However, in this case, we want to feed the output of the echo command as input to the xargs command. To do this, we use the pipe symbol ( | ) which feeds output from one command as input to another. The xargs command will run the cp command three times, each time appending the next directory path piped to it from the echo command on to the end of the cp command. There are three arguments being passed to xargs , but the -n 1 option on the xargs command tells it to only append one of those arguments at a time to the cp command each time it’s run.
So, to stick with our example from earlier, the three separate cp commands above can be combined into one command like this:
echo ~/TextFiles/ ~/Dropbox /media/lori/MYUSBDRIVE | xargs -n 1 cp ~/Documents/FileToBeCopied.txt
02_using_single_command
Note that if the file being copied exists in any of the destination directories specified, the file in that destination will be replaced automatically. You will not be asked if you want to replace the file. (Normally, when you use the cp command to copy a file to a single location, you can add the -i option to ask if you want to replace an existing file. However, the -i option is an interactive option (it causes the cp command to ask for input from the user) and you cannot use an interactive option with the cp command when using it in conjunction with xargs .)
One other thing to consider, is that if you are copying a very large file, you might want to add the no-clobber ( -n ) option to the cp command in the single command above. This option automatically prevents a file from being overwritten in a destination if it already exists there. If you’re copying a very large file over a network, it may be slow and you might want to avoid using the resources required to copy and replace the file. The following command adds the -n option, and will not copy the file to any destination listed in the arguments to the echo statement, if the file already exists in that destination.
echo ~/TextFiles/ ~/Dropbox /media/lori/MYUSBDRIVE | xargs -n 1 cp -n ~/Documents/FileToBeCopied.txt
03_single_command_with_no_clobber
Type man echo, man xargs, or man cp on the command line in Linux for more information about any of these commands.
Share on Facebook Share on Twitter Share on Google Plus

RELATED POSTS


How to Get Free Internet on Idea An...

How to Use DroidVPN App For Free In...

How to HACK Google Play Music App
How to Copy File to Multiple Directories With One Command in Linux How to Copy File to Multiple Directories With One Command in Linux Reviewed by Latest Govt. Jobs on 23:58:00 Rating: 5

0 comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments ( Atom )

Search This Blog

TEST BOOK FOR GOVT ENTRANCE TEST

TEST BOOK FOR GOVT ENTRANCE TEST
Find All Latest book for preparation of SSC,RAILWAYBANK PO,RBI,BANK CLERK,GATE ME,GATE CE are available here in less prices, to check out the books click here

Translate

  • Popular Post
  • Random posts
  • Category

Popular Posts

  • Teen Patti Offer 2018: Refer and Earn Flipkart Vouchers Free
    Teen Patti Offer 2018: Refer and Earn Flipkart Vouchers Free
    Teen Patti Refer & Earn Offer:  Hey Guys! Today I make an article about Teen Patti Referral ...
  • KingRoot 4.8.1 (136) APK Latest Version Download
    Download KingRoot Latest Version 4.8.1 In Tools by Developer KingRoot Studio ( 4.x / 5  average ...
  • 11 things you should understand approximately iOS 11
    Apple introduced the following version of its running system for the iPhone and iPad, iOS eleven ...
  • How to Upload Your Music Library to Google Play Music
    Google Play Music offers an unlimited music streaming subscription paired with YouTube Red ...
  • How to Disable Your Mac’s Touchpad When Another Mouse Is Connected
    Laptop trackpads can be annoying. Your palm hits them while you’re typing, moving your cursor ...
  • How to Gain Root Access of An Android Device via KingoRoot Software
    What Does Root Access Mean? Gaining root access of Android is the process of modifying the ...

Random Posts

  • Here MediaTek will sit out the ARM race for Windows 10 PCs
    Here MediaTek will sit out the ARM race for Windows 10 PCs
    01.03.2017 - 0 Comments
    Despite a turbulent past, Windows PCs with ARM are making a grand return later this year, but only with…
  • Amazon Echo Review
    Amazon Echo Review
    04.02.2018 - 0 Comments
    Key Features Review Price: £89.99 Voice activation Large skills library Smart home Routines Built-in…
  • Review: V-Moda Crossfade Wireless
    Review: V-Moda Crossfade Wireless
    15.02.2017 - 0 Comments
    V-Moda VERDICT The Crossfade Wireless are competent wireless headphones that excel in the fundamentals,…
  • Now Xiaomi launches Mi 5c with in-house octa-core Surge S1 processor
    Now Xiaomi launches Mi 5c with in-house octa-core Surge S1 processor
    02.03.2017 - 0 Comments
    Xiaomi Mi 5c is the first smartphone to be powered by the company’s Surge S1 chipset. Following on the…
  • Fitbit to end support for Pebble smartwatches by June this year
    Fitbit to end support for Pebble smartwatches by June this year
    27.01.2018 - 0 Comments
    NEW DELHI: Fitbit, the maker of popular fitness wearables, has announced that it will end…

Labels

Android Apk Files Android Apps Android Games Apps Apk Files Apps Hack Tricks Entertainment Free Internet Freecharge Gadgets Games Apk Files How To's Laptops Guide Mobiles Reviews Technology Viral's android zone free recharge

Entertainment

Tricks

Popular Posts

  • Teen Patti Offer 2018: Refer and Earn Flipkart Vouchers Free
    Teen Patti Offer 2018: Refer and Earn Flipkart Vouchers Free
    Teen Patti Refer & ...
  • Researchers trick 'CEO' email scammer into giving up identity
    Businesses ...
  • How to Gain Root Access of An Android Device via KingoRoot Software
    What Does Root ...
  • Tinyowl Freecharge Offer – Get 15% Cashback + extra 25% cashback using Freecharge [Ultimatez Tricks]
    Tinyowl Freecharge ...
  • How to Disable Your Mac’s Touchpad When Another Mouse Is Connected
    Laptop ...
  • Infocus Vision 3 review
    What happens when ...
  • EVGA redesigns its graphics cards following overheating concerns
    Following a ...

Random Posts

  • Samsung Gear Fit 2 review
    Samsung Gear Fit 2 review
    05.04.2017 - 0 Comments
    Samsung VERDICT With the Gear Fit 2 Samsung has made hefty changes to its wearable line both inside and…
  • This rare iPod prototype could be yours for $100,000
    This rare iPod prototype could be yours for $100,000
    01.03.2017 - 0 Comments
    If you've just found $100,000 down the back of the sofa - and you love nothing more than owning a…
  • Astell&Kern AK70 high-res digital audio player review: Sweet sound and strong features make it a winner
    Astell&Kern AK70 high-res digital audio player review: Sweet sound and strong features make it a winner
    04.02.2017 - 0 Comments
    The AK70 is one of the first hi-res audio players on the market to support aptX HD for high-res music…
  • Apple iPhone performance issue
    Apple iPhone performance issue
    08.02.2018 - 0 Comments
    Apple iPhone battery performance feature: Here’s how it will look on iOS 11.3 and users will be able to see…
  • How to protect smartphones from theft or loss [Go Android Authority]
    How to protect smartphones from theft or loss [Go Android Authority]
    21.03.2016 - 0 Comments
    How to protect smartphones from theft or loss: Theft or loss of smart phones is definitely one’s worst…

Most Popular

  • Teen Patti Offer 2018: Refer and Earn Flipkart Vouchers Free
    Teen Patti Offer 2018: Refer and Earn Flipkart Vouchers Free
    Teen Patti Refer & ...
  • SAMSUNG GALAXY J7 (2016) REVIEWS
    SAMSUNG GALAXY J7 (2016) REVIEWS
    SAMSUNG GALAXY J ...
  • Top 5 Best SmartPhones under 7000 Rs (March 2017)
    Looking for the ...
  • Apple, IBM, Cisco are huge because of Indians, do not deny them H-1B visa: RBI Governor Urjit Patel
    ...
  • SAMSUNG GALAXY J7 (2016) Specifications
    SAMSUNG GALAXY J ...
  • BlackBerry Teases Marshmallow Beta Testing for Priv by Next Week
    Blackberry ...
  • LG Q6 Review
    LG Q6 Review
    2017 is ...

Contact Form

Name

Email *

Message *

Offers Zone

Created By Android Century Distributed by Android Century
  • Home
  • About us
  • Contact us
  • Privacy policy
  • Terms of use
  • Advertise here
Subscribe Via Email Subscribe To Android Century By Email And Get Free Updates. ;-)


Your email address is safe with us!