11

I've search the net for Linux's answer to something like Teracopy (Windows)... but could not find anything suitable.

The closest things i got are:

Can someone recommend me a simple file copy tool that can queue files for copy/move/delete? Preferably if I can drag and drop from Nautilus.

If something like this does not exist, can someone please tell me why? ...am I the only person that needs something like this?

9
  • 2
    If you could explain exactly what you want, it would be useful. I guess most linux users will not be familiar with "Teracopy".
    – Peltier
    Sep 8, 2009 at 15:06
  • 1
    Is this because big copies and deletes take time and the GUI interface is unavailable/less useful while they are running? Sep 8, 2009 at 15:25
  • A partial explanation of this request can be found here: superuser.com/questions/9284/… Sep 8, 2009 at 17:40
  • Wait a minute, isn't MiniCopier available for Linux? It's a Java app. Sep 13, 2009 at 18:56
  • 1
    @Tobu Terracopy can queue and pause multiple copy job
    – Kokizzu
    Jul 16, 2015 at 10:09

7 Answers 7

3

I just wrote this simple script, which I called 'cpw', to solve this problem.

You use it just like you would use cp... the only difference is that it builds an array of any cpw processes that are already running when it is started, and waits for them to finish before passing the commands on to cp. In this way, it behaves like a self-organizing queue.

You can keep adding background cpw jobs, but they won't step on each other. They'll execute one at a time.

I'm sure others can suggest improvements.

#!/bin/bash

cpwpids=(`ps -ef | grep $USER | grep 'cpw' | grep -v grep | grep -v $$ | awk '{ print $2 }'`) #build an array of all cpw procs for this user that aren't this one.

cpwcnt=${#cpwpids[@]} # number of elemenets in the above array
cnt=$cpwcnt # counter to be decremented each pass
while [ $cnt -gt 0 ]
do
    cnt=$cpwcnt
    for i in "${cpwpids[@]}" # check if each pid has died yet
    do
        ps --pid $i >/dev/null
        if [ $? -gt 0 ]
        then
            let "cnt -= 1"
        fi
    done
    sleep 2
done
cp -v "$@" >> /tmp/cpw.log #log

Usage example:

$ cpw -R /src/tree /dest/tree &
1
  • Just a warning, I've tried this script and for a reason I haven't investigated further, it can hang indefinitely waiting for other scripts to finish. The more reliable way to achieve exclusivity in bash is to use flock -e . See for example here: stackoverflow.com/questions/17996577/…
    – px1mp
    Dec 11, 2013 at 20:47
2

Since the script given by Josh Arenberg might have some deadlocking issues (which I did not experience so far, but also have not investigated), I have written up something on my own. It should not have deadlocking problems. It also works for any shell command, not just cp.

Contents of ~/bin/q

#!/bin/bash

#this waits for any PIDs to finish
anywait(){

    for pid in "$@"; do
        while kill -0 "$pid" 2&>1 >/dev/null; do
            sleep 0.5
        done
    done
}


PIDFILE=~/.q.pid

#open PIDFILE and aquire lock
exec 9>>$PIDFILE
flock -w2 9 || { echo "ERROR: flock() failed." >&2; exit 1; }

#read previous instances PID from PIDFILE and write own PID to PIDFILE
OLDPID=$(<$PIDFILE)
echo $$>$PIDFILE

#release lock
flock -u 9

#wait for OLDPID
anywait $OLDPID

#do stuff
"$@"


#afterwards: cleanup (if pidfile still contains own PID, truncate it)
flock -w2 9 || { echo "ERROR: flock() failed." >&2; exit 1; }
if [ $(<$PIDFILE) == $$ ]; then
truncate -s0 $PIDFILE
fi
flock -u 9

It creates a chain of processes, each waiting for the previous one. If a process in the middle of the chain crashes while waiting (unlikely but not impossible), the chain is broken and both parts run in parallel. The same happens if one of the processes is killed.

Usage like this:

q $COMMAND $ARGS

or even

q $COMMAND $ARGS; $ANOTHER_COMMAND $MORE_ARGS

Test e.g. by typing

q sleep 10 &
q echo blubb &

and finding that after 10 seconds blubb is printed.

2
  • I sometimes get permission denied error for while kill -0 "$pid" 2&>1 >/dev/null; do line. Any ideas?
    – Mrchief
    Jun 27, 2018 at 2:41
  • Ok, so after using this for a long time, I can say that it doesn't work. Maybe the access error is the cause of it but I can see multiple cp stepping on each other.
    – Mrchief
    Jun 28, 2018 at 1:14
1

Ultracopier is one you want, with Nemo plugin or Nautilus plugin.

0

I don't know of anything like this for Linux (though that's not to say that there isn't one somewhere). Linux software tends to get written by Linux users. Experienced Linux users may not think to create a tool like this, because if they notice any slowdown of copies during a GUI session they're likely to switch to a terminal and copy via commandline.

Here are some basic commandline copying utilities that are very fast and shouldn't affect your desktop environment:

  • cp ("cp foo /path/to/bar" will copy foo to bar)
  • mv ("mv foo /path/to/bar" will move (rename) foo to bar)
  • tar ("tar cf - foo | ( cd /path/to/archive/ ; tar xf - )" will recursively copy a directory)
  • rsync ("rsync -r foo /path/to/archive/" will recursively copy a directory)
0

Create a list of files and use SCP to perform the copy. The nice thing in linux is you can add to your text file using echo.

0

I found this Unix Batch System project called Task Spooler which let's you queue up tasks.

Or you can do sudo apt-get install task-spooler

Once installed, you can simply put ts (or tsp for Ubuntu/Debian systems) in front of any regular shell command to queue it up.

This page has lot of examples about it's usages: https://www.ostechnix.com/add-linux-commands-queue-execute-one-one/ or you watch a video here: https://www.youtube.com/watch?v=wv8D8wT20ZY

I verified it and it seems to be working as expected for all my cp commands.

-1

In my experience, doing a few copies simultaneously in Linux doesn't really reduce overall throughput. My measurement of throughput is based on rsync's -P argument. My particular case is separately copying a number of folders full of large files off of a USB hard drive at the same time.

So unless you're copying a lot of things at once, you should be fine.

1
  • 2
    Sorry to say, but this is more like a comment. Lot of opinions, not really an answer.
    – Mrchief
    Jun 28, 2018 at 1:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .