cp

How to copy multiple files from a different directory using cp?

為{幸葍}努か 提交于 2019-11-28 17:22:25
问题 I want to copy multiple files from a specific directory once I am in another directory. To clarify I want to do the following, at once (one command): cp ../dir5/dir4/dir3/dir2/file1 . cp ../dir5/dir4/dir3/dir2/file2 . cp ../dir5/dir4/dir3/dir2/file3 . cp ../dir5/dir4/dir3/dir2/file4 . I can't use cp ../dir5/dir4/dir3/dir2/* . because in dir2 there are n files (n>4) By the way, I'm using bash . Thanks. 回答1: cp ../dir5/dir4/dir3/dir2/file[1234] . or (in Bash) cp ../dir5/dir4/dir3/dir2/file{1..4

Linux how to copy but not overwrite?

会有一股神秘感。 提交于 2019-11-28 15:00:31
I want to cp a directory but I do not want to overwrite any existing files even it they are older than the copied files. And I want to do it completely noniteractive as this will be a part of a Crontab Bash script. Any ideas? hovanessyan Taken from the man page : -n, --no-clobber do not overwrite an existing file (overrides a previous -i option) Example: cp -n myoldfile.txt mycopiedfile.txt Hans Ginzel Consider using rsync . rsync -a -v --ignore-existing src dst As per comments rsync -a -v src dst is not correct because it will update existing files. cp -n Is what you want. See the man page.

How can I make a progress bar while copying a directory with cp?

不想你离开。 提交于 2019-11-28 03:27:44
I suppose I could compare the number of files in the source directory to the number of files in the target directory as cp progresses, or perhaps do it with folder size instead? I tried to find examples, but all bash progress bars seem to be written for copying single files. I want to copy a bunch of files (or a directory, if the former is not possible). SteveLambert You can also use rsync instead of cp like this: rsync -Pa source destination Which will give you a progress bar and estimated time of completion. Very handy. To show a progress bar while doing a recursive copy of files & folders &

Recursive copy of specific files in Unix/Linux? [closed]

怎甘沉沦 提交于 2019-11-28 02:57:08
I need to copy all *.jar files from directory and all its subdirectories. How can I do it in UNIX/Linux terminal? Command cp -r *.jar /destination_dir doesn't work. rsync is useful for local file copying as well as between machines. This will do what you want: rsync -avm --include='*.jar' -f 'hide,! */' . /destination_dir The entire directory structure from . is copied to /destination_dir, but only the .jar files are copied. The -a ensures all permissions and times on files are unchanged. The -m will omit empty directories. -v is for verbose output. For a dry run add a -n, it will tell you

Copy files from one directory into an existing directory

允我心安 提交于 2019-11-28 02:42:25
In bash I need to do this: take all files in a directory copy them into an existing directory How do I do this? I tried cp -r t1 t2 (both t1 and t2 are existing directories, t1 has files in it) but it created a directory called t1 inside t2, I don't want that, I need the files in t1 to go directly inside t2. How do I do this? Nick What you want is: cp -R t1/. t2/ The dot at the end tells it to copy the contents of the current directory, not the directory itself. This method also includes hidden files and folders. If you want to copy something from one directory into the current directory, do

How to have the cp command create any necessary folders for copying a file to a destination [duplicate]

烈酒焚心 提交于 2019-11-28 02:35:59
This question already has an answer here: Linux: copy and create destination dir if it does not exist 19 answers When copying a file using cp to a folder that may or may not exist, how do I get cp to create the folder if necessary? Here is what I have tried: [root@file nutch-0.9]# cp -f urls-resume /nosuchdirectory/hi.txt cp: cannot create regular file `/nosuchdirectory/hi.txt': No such file or directory To expand upon Christian's answer, the only reliable way to do this would be to combine mkdir and cp : mkdir -p /foo/bar && cp myfile "$_" As an aside, when you only need to create a single

19年牛客多校第十场记录

╄→尐↘猪︶ㄣ 提交于 2019-11-27 18:28:21
H 题意: 给出一个图,只可能为他给出五个图的同构,让判断是哪个图 思路: 根据给出图的特点,求2度,3度,4度点的个数即可 #include<bits/stdc++.h> #define ll long long #define FOR(i,l,r) for(int i=l;i<=r;++i) using namespace std; typedef pair<int,int> pii; const int N =50; int G[10][10]; int d[10]; void solve(){ memset(G,0,sizeof G); memset(d,0,sizeof d); int u,v; for(int i=1;i<=5;++i){ scanf("%d%d",&u,&v); G[u][v] = 1; G[v][u] = 1; d[u]++; d[v]++; } int cnt3 = 0,pos3; for(int i=1;i<=6;++i){ if(d[i]==4) { printf("2,2-dimethylbutane\n"); return ; } if(d[i]==3){ cnt3++; if(cnt3>1){ printf("2,3-dimethylbutane\n"); return; } pos3 = i; } } if(cnt3==0){

How to move or copy files listed by 'find' command in unix?

跟風遠走 提交于 2019-11-27 11:13:17
I have a list of certain files that I see using the command below, but how can I copy those files listed into another folder, say ~/test? find . -mtime 1 -exec du -hc {} + Ankur Adding to Eric Jablow's answer, here is a possible solution (it worked for me - linux mint 14 /nadia) find /path/to/search/ -type f -name "glob-to-find-files" | xargs cp -t /target/path/ You can refer to " How can I use xargs to copy files that have spaces and quotes in their names? " as well. Thiyagu ATR Actually, you can process the find command output in a copy command in two ways: If the find command's output doesn

Copy all files with a certain extension from all subdirectories

纵然是瞬间 提交于 2019-11-27 06:03:35
Under unix, I want to copy all files with a certain extension (all excel files) from all subdirectories to another directory. I have the following command: cp --parents `find -name \*.xls*` /target_directory/ The problems with this command are: It copies the directory structure as well, and I only want the files (so all files should end up in /target_directory/) It does not copy files with spaces in the filenames (which are quite a few) Any solutions for these problems? --parents is copying the directory structure, so you should get rid of that. The way you've written this, the find executes,

How to use 'cp' command to exclude a specific directory?

北城余情 提交于 2019-11-27 02:28:24
I want to copy all files in a directory except some files in a specific sub-directory. I have noticed that 'cp' command didn't have a --exclude option. So, how can I achieve this? hank rsync is fast and easy: rsync -av --progress sourcefolder /destinationfolder --exclude thefoldertoexclude You can use --exclude multiples times. rsync -av --progress sourcefolder /destinationfolder --exclude thefoldertoexclude --exclude anotherfoldertoexclude Note that the dir thefoldertoexclude after --exclude option is relative to the sourcefolder , i.e., sourcefolder/thefoldertoexclude . Also you can add -n