cp command should ignore some files

前端 未结 4 568
北荒
北荒 2020-12-24 01:29

Sometimes I need to perform following command

cp -rv demo demo_bkp

However I want to ignore all the files in directory .git . How do I ach

4条回答
  •  不思量自难忘°
    2020-12-24 02:12

    To ignore a git directory specifically, I'd try git export first.

    But in general, to copy a directory tree excluding certain files or folders, I'd recommend using rsync instead of cp. The syntax is mostly the same, but rsync has way more options, including one to exclude selected files:

    rsync -rv --exclude=.git demo demo_bkp
    

    See e.g. the man page for more info.

提交回复
热议问题