2011-04-20 10:24:10 +0000 2011-04-20 10:24:10 +0000
79
79

Linux上でファイルやフォルダを再帰的に移動する

考察:

ls -al ../public-back
drwxrwxr-x 4 apache apache 4096 Apr 19 03:32 templates

ls -al ../public-back/templates

drwxrwxr-x 2 apache apache 4096 Apr 19 03:33 content
drwxrwxr-x 2 apache apache 20480 Apr 20 06:14 images
drwxrwxr-x 2 apache apache 4096 Apr 19 03:35 video

ls -al /public

drwxrwxr-x 4 apache apache 4096 Apr 20 09:49 templates

ls -al /public/templates

drwxrwxr-x 2 apache apache 4096 Apr 20 09:50 content
drwxrwxr-x 2 apache apache 4096 Apr 20 09:50 images
drwxrwxr-x 2 apache apache 4096 Apr 20 09:50 video

パーミッションで再帰的に/public-back/templatesの内容を/public/templatesに移動するにはどうすればいいですか?

回答 (5)

97
97
97
2011-04-20 14:10:36 +0000

私が質問を誤解していない限り、これは動作します:

mv /public-back/templates/* /public/templates

また、あなたが巨大なファイルのリストを持っていない限り、-iを追加すると、それが何かを上書きする前に尋ねるでしょう。

10
10
10
2011-04-20 14:24:07 +0000

cp の man ページには、以下のように書かれています:

-p same as --preserve=mode,ownership,timestamps
-r same as --recursive=copy directories recursively

Try;

cp -rp /public-back/templates/* /public/templates/
5
5
5
2016-02-17 07:43:21 +0000

私の親指ドライブから私のOSMCシステムにアイテムを移動するとき、私は次の非常に便利なことがわかりました:

find /media/Pi\ Hard\ 16GB/ -name '*' -exec mv -v {} /media/External\ HDD/Videos/ \;

それがどのように動作するかについての説明は以下のとおりです。

ところで、ソースまたは宛先のディレクトリ名(上記参照)の任意のスペースの前にバックスラッシュを追加することを忘れないでください。

find finds all files and folders in the destination path.

/media/Pi Hard 16GB/ is the path searched. Escape special char such as spaces.

-name '*' filters on names. If you do not escape or quote this then 
          the shell will expand it before find sees it.

-exec Executes a command, in our case mv

-v Verbose, so you can see what's happening (optional)

{} is replaced by the name of the found object.

実質的に、あなたはすべてのファイルとすべてのフォルダを見つけて、それらを一つずつ移動しています(またはディレクトリが最初に見つかった場合、あなたはそのディレクトリとその中のコンテンツを移動しています)。これは移動のたびに新しいプロセスが開始され、非常に非効率的です。通常のコマンドが失敗した場合のみ使用してください。

2
2
2
2017-09-06 07:05:14 +0000
cp -a --link ../public-back/* /public/. && rm -rf ../public-back

だから宛先ディレクトリにハードリンクを作成して、ソースディレクトリを削除します。

2
2
2
2015-10-20 15:24:37 +0000

mvはこれをしないようです。しかし、あなたはこの小さなトリックを使用することができ、魅力のように動作します:&002&002&001&002&002&002とパーミッションとすべてを保持します。

関連する質問

6
10
7
5
13