面白そうな記事を見つけました。
Advanced Copy Command – Shows Progress Bar While Copying Large Files/Folders in Linux
オリジナルのcp,mvコマンドにpatchを適用して実行中にプログレスバーを表示して進捗が分かりやすくするコマンドです。早々にインストールしてみました。
環境
・CentOS Linux release 7.4.1708 (Core)
・Kernel 3.10.0-693.11.1.el7.x86_64
- ソース・プログラムのダウンロード
- 解凍
- Patchダウンロード
- Patch適用
- ./configure
- make
- command
- cp,mvのコピー
- 実行
下記サイトからオリジナルのcp,mvコマンドのソース・プログラムをダウンロードします。
http://ftp.gnu.org/gnu/coreutils/
最新版はcoreutils-8.28.tar.xzでした。
http://ftp.gnu.org/gnu/coreutils/coreutils-8.28.tar.xz
1 2 3 4 5 6 7 8 9 10 11 |
# wget http://ftp.gnu.org/gnu/coreutils/coreutils-8.28.tar.xz --2017-12-11 18:01:02-- http://ftp.gnu.org/gnu/coreutils/coreutils-8.28.tar.xz Resolving ftp.gnu.org (ftp.gnu.org)... 208.118.235.20 Connecting to ftp.gnu.org (ftp.gnu.org)|208.118.235.20|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 5252336 (5.0M) [application/x-tar] Saving to: 'coreutils-8.28.tar.xz' 100%[====================================================================>] 5,25 2017-12-11 18:01:06 (1.57 MB/s) - 'coreutils-8.28.tar.xz' saved [5252336/5252336 |
1 2 3 4 5 |
# tar Jxvf coreutils-8.28.tar.xz coreutils-8.28/ coreutils-8.28/.version coreutils-8.28/.vg-suppressions (snip) |
coreutils-8.28のpatchが下記サイトにありました。
Package Details: advcp 8.25-1
https://aur.archlinux.org/packages/advcp/
これをコピー&ペーストでファイルに保存します。
今回はadvcpmv-8.25.patchという名前で作成しました。
https://aur.archlinux.org/cgit/aur.git/plain/advcpmv-8.25.patch?h=advcp
advcpmv-8.25.patchを適用します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# cd coreutils-8.28 # patch -p1 -i advcpmv-8.25.patch patching file src/copy.c Hunk #1 succeeded at 128 (offset 11 lines). Hunk #2 succeeded at 289 (offset 12 lines). Hunk #3 succeeded at 299 (offset 12 lines). Hunk #4 succeeded at 462 (offset 12 lines). Hunk #5 succeeded at 538 (offset 8 lines). Hunk #6 succeeded at 671 (offset 7 lines). Hunk #7 succeeded at 1429 (offset 7 lines). Hunk #8 succeeded at 1504 (offset 7 lines). Hunk #9 succeeded at 1518 (offset 7 lines). Hunk #10 succeeded at 1534 (offset 7 lines). patching file src/copy.h Hunk #1 succeeded at 234 (offset 3 lines). Hunk #2 succeeded at 303 (offset 11 lines). patching file src/cp.c Hunk #1 succeeded at 141 (offset 1 line). Hunk #2 succeeded at 181 (offset 1 line). Hunk #3 succeeded at 637 with fuzz 1 (offset 10 lines). Hunk #4 succeeded at 843 (offset 9 lines). Hunk #5 succeeded at 918 (offset 10 lines). Hunk #6 succeeded at 1057 with fuzz 2 (offset 6 lines). Hunk #7 succeeded at 1114 (offset 6 lines). patching file src/mv.c Hunk #1 succeeded at 65 (offset 1 line). Hunk #2 succeeded at 166 (offset 2 lines). Hunk #3 succeeded at 390 (offset 2 lines). Hunk #4 succeeded at 446 with fuzz 2 (offset -14 lines). Hunk #5 succeeded at 492 with fuzz 1 (offset -14 lines). |
./configureを実行します。
1 2 3 4 5 6 |
# ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /usr/bin/mkdir -p checking for gawk... gawk (snip) |
エラーになりました。rootでconfigureを実行しないでと…
1 2 3 4 |
checking whether mkfifo rejects trailing slashes... yes checking whether mknod can create fifo without root privileges... configure: err configure: error: you should not run configure as root (set FORCE_UNSAFE_CONFIGUthis check) See `config.log' for more details |
検証なのでそのままチェックを無視するようにして再度実行です。
1 2 3 4 5 6 7 8 |
# export FORCE_UNSAFE_CONFIGURE=1 # ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes (snip) config.status: executing po-directories commands config.status: creating po/POTFILES config.status: creating po/Makefile |
./configureが正常終了したらmakeの実行です。
1 2 3 4 5 6 7 |
# make GEN lib/alloca.h GEN lib/arpa/inet.h GEN lib/configmake.h (snip) make[2]: Leaving directory `/root/coreutils-8.28/gnulib-tests' make[1]: Leaving directory `/root/coreutils-8.28' |
コマンドはcoreutils-8.28/srcに作成されています。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# find src -executable -type f src/dcgen src/nice src/chroot src/hostid src/who src/timeout src/users src/pinky src/uptime src/stty src/df src/stdbuf src/[ src/b2sum src/base64 src/base32 src/basename src/cat src/chcon src/chgrp src/chmod src/chown src/cksum src/comm src/cp src/csplit src/cut src/date src/dd src/dir src/dircolors src/dirname src/du src/echo src/env src/expand src/expr src/factor src/false src/fmt src/fold src/ginstall src/groups src/head src/id src/join src/kill src/link src/ln src/logname src/ls src/md5sum src/mkdir src/mkfifo src/mknod src/mktemp src/mv src/nl src/nproc src/nohup src/numfmt src/od src/paste src/pathchk src/pr src/printenv src/printf src/ptx src/pwd src/readlink src/realpath src/rm src/rmdir src/runcon src/seq src/sha1sum src/sha224sum src/sha256sum src/sha384sum src/sha512sum src/shred src/shuf src/sleep src/sort src/split src/stat src/sum src/sync src/tac src/tail src/tee src/test src/touch src/tr src/true src/truncate src/tsort src/tty src/uname src/unexpand src/uniq src/unlink src/vdir src/wc src/whoami src/yes src/getlimits src/make-prime-list src/libstdbuf.so |
今回は/usr/local/binにacp,amvとしてコピーしました。
1 2 |
# cp src/cp /usr/local/bin/acp # cp src/mv /usr/local/bin/amv |
acpを実行してみます。プログレスバーを表示するオプションは-g
です。
1 2 |
# acp -g dummy.iso /tmp 1 files ( 1.0 GiB) copied in 2.3 seconds (450.3 MiB/s). |
大きなファイルやディレクトリをコピーする時など進捗が分かっていいですね。
Help
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# acp --help Usage: acp [OPTION]... [-T] SOURCE DEST or: acp [OPTION]... SOURCE... DIRECTORY or: acp [OPTION]... -t DIRECTORY SOURCE... Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY. Mandatory arguments to long options are mandatory for short options too. -a, --archive same as -dR --preserve=all --attributes-only don't copy the file data, just the attributes --backup[=CONTROL] make a backup of each existing destination file -b like --backup but does not accept an argument --copy-contents copy contents of special files when recursive -d same as --no-dereference --preserve=links -f, --force if an existing destination file cannot be opened, remove it and try again (this option is ignored when the -n option is also used) -g, --progress-bar add a progress bar -i, --interactive prompt before overwrite (overrides a previous -n option) -H follow command-line symbolic links in SOURCE -l, --link hard link files instead of copying -L, --dereference always follow symbolic links in SOURCE -n, --no-clobber do not overwrite an existing file (overrides a previous -i option) -P, --no-dereference never follow symbolic links in SOURCE -p same as --preserve=mode,ownership,timestamps --preserve[=ATTR_LIST] preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all --no-preserve=ATTR_LIST don't preserve the specified attributes --parents use full source file name under DIRECTORY -R, -r, --recursive copy directories recursively --reflink[=WHEN] control clone/CoW copies. See below --remove-destination remove each existing destination file before attempting to open it (contrast with --force) --sparse=WHEN control creation of sparse files. See below --strip-trailing-slashes remove any trailing slashes from each SOURCE argument -s, --symbolic-link make symbolic links instead of copying -S, --suffix=SUFFIX override the usual backup suffix -t, --target-directory=DIRECTORY copy all SOURCE arguments into DIRECTORY -T, --no-target-directory treat DEST as a normal file -u, --update copy only when the SOURCE file is newer than the destination file or when the destination file is missing -v, --verbose explain what is being done -x, --one-file-system stay on this file system -Z set SELinux security context of destination file to default type --context[=CTX] like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX --help display this help and exit --version output version information and exit By default, sparse SOURCE files are detected by a crude heuristic and the corresponding DEST file is made sparse as well. That is the behavior selected by --sparse=auto. Specify --sparse=always to create a sparse DEST file whenever the SOURCE file contains a long enough sequence of zero bytes. Use --sparse=never to inhibit creation of sparse files. When --reflink[=always] is specified, perform a lightweight copy, where the data blocks are copied only when modified. If this is not possible the copy fails, or if --reflink=auto is specified, fall back to a standard copy. The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX. The version control method may be selected via the --backup option or through the VERSION_CONTROL environment variable. Here are the values: none, off never make backups (even if --backup is given) numbered, t make numbered backups existing, nil numbered if numbered backups exist, simple otherwise simple, never always make simple backups As a special case, cp makes a backup of SOURCE when the force and backup options are given and SOURCE and DEST are the same name for an existing, regular file. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report cp translation bugs to <http://translationproject.org/team/> Full documentation at: <http://www.gnu.org/software/coreutils/cp> or available locally via: info '(coreutils) cp invocation' |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# amv --help Usage: amv [OPTION]... [-T] SOURCE DEST or: amv [OPTION]... SOURCE... DIRECTORY or: amv [OPTION]... -t DIRECTORY SOURCE... Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY. Mandatory arguments to long options are mandatory for short options too. --backup[=CONTROL] make a backup of each existing destination file -b like --backup but does not accept an argument -f, --force do not prompt before overwriting -g, --progress-bar add progress-bar -i, --interactive prompt before overwrite -n, --no-clobber do not overwrite an existing file If you specify more than one of -i, -f, -n, only the final one takes effect. --strip-trailing-slashes remove any trailing slashes from each SOURCE argument -S, --suffix=SUFFIX override the usual backup suffix -t, --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY -T, --no-target-directory treat DEST as a normal file -u, --update move only when the SOURCE file is newer than the destination file or when the destination file is missing -v, --verbose explain what is being done -Z, --context set SELinux security context of destination file to default type --help display this help and exit --version output version information and exit The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX. The version control method may be selected via the --backup option or through the VERSION_CONTROL environment variable. Here are the values: none, off never make backups (even if --backup is given) numbered, t make numbered backups existing, nil numbered if numbered backups exist, simple otherwise simple, never always make simple backups GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report mv translation bugs to <http://translationproject.org/team/> Full documentation at: <http://www.gnu.org/software/coreutils/mv> or available locally via: info '(coreutils) mv invocation' |