{"id":303,"date":"2021-01-11T12:00:00","date_gmt":"2021-01-11T17:00:00","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=303"},"modified":"2021-01-11T17:50:27","modified_gmt":"2021-01-11T22:50:27","slug":"linux-copy-all-files-with-exception","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/linux-copy-all-files-with-exception\/","title":{"rendered":"Linux: Copy all files with exception"},"content":{"rendered":"\n<p>Sometime we need to copy entire directory with the except of a few files or a specific directory. This could easily be accomplished with a regular expression as follows:<\/p>\n\n\n\n<p>Note: $ is the command prompt, not the code you type.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ mkdir test\n$ cd test\n$ touch a.txt\n$ touch b.txt\n$ mkdir mod\n$ cd mod\n$ touch c.txt \n$ touch d.txt\n$ mkdir ..\/views\n$ cd ..\/views\n$ touch e.txt \n$ touch f.txt\n$ mkdir ..\/..\/test2\n$ cd ..<\/code><\/pre>\n\n\n\n<p>Following is the directory structure created by this code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ls -R\n$ .:\na.txt &nbsp;b.txt &nbsp;mod &nbsp;views\n\n.\/mod:\nc.txt  d.txt  touch\n\n.\/views:\ne.txt  f.txt  touch<\/code><\/pre>\n\n\n\n<p>Now we copy all files except for the mod directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ cp -a &#91;^mod]* ..\/test2<\/code><\/pre>\n\n\n\n<p>This is what it looks like after copying. All files are copied with the exception of the mod directory and its contents.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ls -R ..\/test2\n..\/test2:\na.txt &nbsp;b.txt &nbsp;views\n\n..\/test2\/views:\ne.txt  f.txt  touch<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometime we need to copy entire directory with the except of a few files or a specific directory. This could easily be accomplished with a regular expression as follows: Note: $ is the command prompt, not the code you type. Following is the directory structure created by this code: Now we copy all files except [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":533,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[35],"class_list":["post-303","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-linux"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=303"}],"version-history":[{"count":2,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/303\/revisions"}],"predecessor-version":[{"id":534,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/303\/revisions\/534"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media\/533"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}