cp

Linux cp with a regexp

拈花ヽ惹草 提交于 2019-12-04 13:04:57
问题 I would like to copy some files in a directory, renaming the files but conserving extension. Is this possible with a simple cp , using regex ? For example : cp ^myfile\.(.*) mydir/newname.$1 So I could copy the file conserving the extension but renaming it. Is there a way to get matched elements in the cp regex to use it in the command ? If not, I'll do a perl script I think, or if you have another way... Thanks 回答1: Suppose you have myfile.a , myfile.b , myfile.c : for i in myfile.*; do echo

How to force 'cp' to overwrite directory instead of creating another one inside?

烂漫一生 提交于 2019-12-03 18:22:30
问题 I'm trying to write a Bash script that will overwrite an existing directory. I have a directory foo/ and I am trying to overwrite bar/ with it. But when I do this: cp -Rf foo/ bar/ a new bar/foo/ directory is created. I don't want that. There are two files in foo/ ; a and b . There are files with same names in bar/ as well. I want the foo/a and foo/b to replace bar/a and bar/b . 回答1: You can do this using -T option in cp . See Man page for cp . -T, --no-target-directory treat DEST as a normal

git copy file, as opposed to `git mv`

不想你离开。 提交于 2019-12-03 16:11:03
问题 I realize that git works by diff'ing the contents of files. I have some files that I want to copy. To absolutely prevent git from ever getting confused, is there some git command that can be used to copy the files to a different directory (not mv, but cp), and stage the files as well? 回答1: The short answer is just "no". But there is more to know; it just requires some background. (And as JDB suggests in a comment, I'll mention why git mv exists as a convenience.) Slightly longer: you're right

Why is my Bash script adding <feff> to the beginning of files?

强颜欢笑 提交于 2019-12-03 08:49:23
问题 I've written a script that cleans up .csv files, removing some bad commas and bad quotes (bad, means they break an in house program we use to transform these files) using sed: # remove all commas, and re-insert the good commas using clean.sed sed -f clean.sed $1 > $1.1st # remove all quotes sed 's/\"//g' $1.1st > $1.tmp # add the good quotes around good commas sed 's/\,/\"\,\"/g' $1.tmp > $1.tmp1 # add leading quotes sed 's/^/\"/' $1.tmp1 > $1.tmp2 # add trailing quotes sed 's/$/\"/' $1.tmp2

Copying the files based on modification date in linux

前提是你 提交于 2019-12-03 08:33:52
问题 It may be a duplicate question but i could not find the solution for this i want to copy a last 3 months files from one directory to another directory but i could find only to listing the files by using the following command. find . -mtime -90 -ls I really don't know how to copy the files by using -mtime . I'm new to linux please help me. 回答1: Use the -exec option for find : find . -mtime -90 -exec cp {} targetdir \; -exec would copy every result returned by find to the specified directory (

Linux cp with a regexp

风格不统一 提交于 2019-12-03 08:16:05
I would like to copy some files in a directory, renaming the files but conserving extension. Is this possible with a simple cp , using regex ? For example : cp ^myfile\.(.*) mydir/newname.$1 So I could copy the file conserving the extension but renaming it. Is there a way to get matched elements in the cp regex to use it in the command ? If not, I'll do a perl script I think, or if you have another way... Thanks Suppose you have myfile.a , myfile.b , myfile.c : for i in myfile.*; do echo mv "$i" "${i/myfile./newname.}"; done This creates (upon removal of echo ) newname.a , newname.b , newname

git copy file, as opposed to `git mv`

血红的双手。 提交于 2019-12-03 05:24:46
I realize that git works by diff'ing the contents of files. I have some files that I want to copy. To absolutely prevent git from ever getting confused, is there some git command that can be used to copy the files to a different directory (not mv, but cp), and stage the files as well? The short answer is just "no". But there is more to know; it just requires some background. (And as JDB suggests in a comment , I'll mention why git mv exists as a convenience.) Slightly longer: you're right that Git will diff files, but you may be wrong about when Git does these file-diffs. Git's internal

Linux commands to copy one file to many files

*爱你&永不变心* 提交于 2019-12-03 02:40:49
问题 Is there a one-line command/script to copy one file to many files on Linux? cp file1 file2 file3 copies the first two files into the third. Is there a way to copy the first file into the rest? 回答1: Does cp file1 file2 ; cp file1 file3 count as a "one-line command/script"? How about for file in file2 file3 ; do cp file1 "$file" ; done ? Or, for a slightly looser sense of "copy": tee <file1 file2 file3 >/dev/null 回答2: just for fun, if you need a big list of files: tee <sourcefile.jpg

cpio VS tar and cp

北战南征 提交于 2019-12-02 23:22:14
I just learned that cpio has three modes: copy-out, copy-in and pass-through. I was wondering what are the advantages and disadvantages of cpio under copy-out and copy-in modes over tar. When is it better to use cpio and when to use tar? Similar question for cpio under pass-through mode versus cp. Thanks and regards! I see no reason to use cpio for any reason other than ripping opened RPM files, via disrpm or rpm2cpio , but there may be corner cases in which cpio is preferable to tar. History and popularity Both tar and cpio are competing archive formats that were introduced in Version 7 Unix

Linux commands to copy one file to many files

﹥>﹥吖頭↗ 提交于 2019-12-02 16:12:52
Is there a one-line command/script to copy one file to many files on Linux? cp file1 file2 file3 copies the first two files into the third. Is there a way to copy the first file into the rest? Does cp file1 file2 ; cp file1 file3 count as a "one-line command/script"? How about for file in file2 file3 ; do cp file1 "$file" ; done ? Or, for a slightly looser sense of "copy": tee <file1 file2 file3 >/dev/null Yevgen just for fun, if you need a big list of files: tee <sourcefile.jpg targetfiles{01-50}.jpg >/dev/null - Kelvin Feb 12 at 19:52 But there's a little typo. Should be: tee <sourcefile.jpg