Results 1 to 3 of 3

Thread: Using terminal to cp a directory from one volume to another with error log.

  1. #1
    Join Date
    Apr 2016
    Beans
    1

    Using terminal to cp a directory from one volume to another with error log.

    A friend of mine said that I could use this pice of code to copy files from one location to another and have it also output an error log
    Code:
    SOURCEDIR="/Volumes/FreeAgent GoFlex Drive/Anime"
    DESTDIR="/Volumes/5TB FreeAgent GoFlex Drive/Anime"
    for d in "${SOURCEDIR}/"*; do echo 'copying `basename "${d}"`';cp -r "${d}" "${DESTDIR}/`basename ${d}`" 2> err.log; done
    but when I use this code in a .sh file it does the following to the first copied dir, Screen Shot 2016-03-21 at 10.58.01.png it creates the first folder and gives it the label of the drive and the name of the first folder combined.
    The original line of code he gave me, that I was going to used before I asked if he could have it output the errors to a log, was
    Code:
    SOURCEDIR="/Volumes/FreeAgent GoFlex Drive/Anime"
    DESTDIR="/Volumes/5TB FreeAgent GoFlex Drive/Anime"
    for d in "${SOURCEDIR}/"*; do echo "copying `basename "${d}"`"; cp -r "${d}" "${DESTDIR}"; done
    and it worked fine, but now how do I get the error logging pice of code to work?

  2. #2
    Join Date
    Jun 2006
    Location
    UK
    Beans
    Hidden!
    Distro
    Ubuntu 22.04 Jammy Jellyfish

    Re: Using terminal to cp a directory from one volume to another with error log.

    Your screenshot shows what appears to be a MacOS Finder window. What operating system are you using?

    Edit: The references to AirDrop and iCloud Drive suggest that you are running MacOSX Yosemite, rather than a Linux desktop themed to look like MacOS, so I've moved this thread to the Other Operating Systems -> Mac OSX sub-forum.

    You posted this bash-related question in New to Ubuntu, the tagline for which clearly states:

    The perfect place to post for your Ubuntu support if you are new to Linux.
    Although members proficient in bash in Ubuntu may be able to help you, you may be better off in a MacOS forum which caters for those Mac users who wish to use the terminal.
    Last edited by coffeecat; April 5th, 2016 at 09:43 AM.
    Ubuntu 20.04 Desktop Guide - Ubuntu 22.04 Desktop Guide - Forum Guide to BBCode - Using BBCode code tags

    Member: Not Canonical Team

    If you need help with your forum account, such as SSO login issues, username changes, etc, the correct place to contact an admin is here. Please do not PM me about these matters unless you have been asked to - unsolicited PMs concerning forum accounts will be ignored.

  3. #3
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 22.04 Jammy Jellyfish

    Re: Using terminal to cp a directory from one volume to another with error log.

    In addition to what Coffeecat said, I have a couple questions:

    Why are you using cp rather than rsync? Is there a specific reason you want to get a list of errors that occurred during the copy?

    Try this:

    Code:
    #/bin/bash
    
    source="/Volumes/FreeAgent GoFlex Drive/Anime"
    destination="/Volumes/5TB FreeAgent GoFlex Drive/Anime"
    error="/home/$(whoami)/error.log"
    cp -rv $source $destination 2> $error
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •