I wan to create copy command to copy files from one directory to just back of it with removing suffix date. There are multiple files are there.   eg file LOAN.DAILY.20191204  want to create command   cp LOAN.DAILY.20191204 ../LOAN.DAILY   My attempt   ls -lrt | awk ' /DAILY/{ print "cp " , $9 , "../" , sub(/\.20191204$/,""); $9 }'   getting output   cp  LOAN.DAILY.20191204 ../ 1   why this 1 is coming
120897
Say I have three files (template_*.txt):   template_x.txt template_y.txt template_z.txt   I want to copy them to three new files (foo_*.txt).    foo_x.txt  foo_y.txt  foo_z.txt   Is there some simple way to do that with one command, e.g.   cp --enableAwesomeness template_*.txt foo_*.txt
73724
There is a standard command for file splitting - split.  For example, if I want to split a words file in several chunks of 10000 lines, I can use:  split -dl 10000 words wrd   and it would generate several files of the form wrd.01, wrd.02 and so on.  But I want to have a specific extension for those files - for example, I want to get wtd.01.txt, wrd.02.txt files.  Is there a way to do it?
97732
I have a directory with several subdirectories with files. How can I copy all files in the subdirectories to a new location?  Edit: I do not want to copy the directories, just the files...  As this is still on XP, I chose the below solution:   for /D %S IN ("src\*.*") DO  @COPY "%S\" "dest\"   Thanks!
50479
I am having issues making this syntax work correctly. What I would like to do is remove all tmp and bak files from the specified directory and all subdirectories if the modified date is older than 7 days.  for %G in (.tmp, .bak) do forfiles -p "C:\test\cad projects" -s -m *%G -d -7 -c "cmd /c del @path"   My syntax was gathered from .  If I change my search mask to only include one desired extension then I get correct results.  forfiles -p "c:\test\cad projects" -s -m *.bak -d -7 -c "cmd /c del @path"   I don't do much with batch files so I was hoping someone could assist. Thanks for reading.
16606
On my Windows 7 machine, when I make a copy (Ctrl+C, Ctrl+V) of a file in the same folder I get the new file created with " - Copy" added to the file name:  1st copy: "foo.txt" -> "foo - Copy.txt". 2nd copy and so on: "foo.txt" -> "foo - Copy (2).txt".  Is there a way to change this naming pattern?  Particularly I'm interested in changing the naming from " - Copy (index)" to "_index", so that the files would be named foo_1.txt, foo_2.txt and so on.  I know there are 3rd party file managers that can do this, but I would like to know if there is a way to change this naming pattern in explorer.
96588
I came up with the following snippet for counting files in each subdirectory:  for x (**/*(/)); do print $x; find $x -maxdepth 1 -type f | wc -l; done   The command outputs consecutive pairs (one below the other) as follows:  directory_name # of files   I would like to change the code above to:   Print each match on the same line (i.e. directory_name ':' # of files) Only count files if the folders are leaves in the directory tree (i.e. they don't have any subfolders).    How can I do that?
53311
Assuming file2 already exists, the command   &gt; file1 &lt; file2 cat   appears to be copying the content of file2 to file1.  But I cannot understand this structure.  I understand that "Nothing" is being directed to file1 (creating or erasing its content). Then the content of file2 is being directed to file1.  Why is cat after file2? How does it know to cat file2 if the operands are not in the correct order?
45426
If you have a series of subfolders (like from a to z) and want to run a command on each one of them (like rm *.pdf or ls *.pdf), how do you do that? The "manual" approach would be cd a, rm *.pdf, or ls *.pdf, cd .., cd b, ... That seems too complicated, so I believe there must be an easier approach.
16118
list=`ls -a R*` echo $list   Inside a shell script, this echo command will list all the files from current directory starting with R, but in one line. How can I print each item on one line?  I need a generic command for all the scenarios happening with ls, du, find -type -d, etc.
89541
I would like to rename all files in a folder so to have consecutive numbers. For instance:  1.png 2.png 3.png etc   I know there is the rename command and I know there are DOZENS of similar questions in here but I can't find the way.  NOTE: Suggested duplicate doesn't contain a solution specific for my case. Please stop flagging this as duplicate, because suggested duplicate does not answer my question
28159
I just asked a  related to how I can count the files of particular extension. Now I want to cp these files to a new dir.  I am trying,  cp *.prj ../prjshp/   and   cp * | grep '\.prj$' ../prjshp/   but they are giving the same error,     bash: /bin/cp: Argument list too long   How do I copy them?
114395
I want to cp aaa/deep/sea/blob.psd to bbb/deep/sea/blob.psd  How do I do the copy if the deep and sea directories don't exist under bbb so that the copy both creates the directories that are needed and copies the file?  Right now I get No such file or directory as deep and sea don't exist.  I looked thru the man help pages and other questions but nothing jumps out at me.  The closest I've got is using rcp for the directory:  rcp -r aaa/deep/sea/ bbb/deep/sea/   though this copies the whole directory and contents and I just want the one file.  Trying to do that however gave cp: cannot create regular file bbb/deep/sea/blob.psd' such file or directory
110706
How can I find just the *.mp3 files with a recursive command like ls -R *.mp3 in a directory that contains several sub-directories and at the end copy these files in a directory that I choose.  Thanks for your support.
15297
How can I write the same content to many text files by using cat or echo in only one command?  For example I want to write "hello" to file1 and file2. I tried:   echo "hello" &gt;&gt; file1 file2   but it didn't work. How can I do it?
7695
I need to copy /root/nbu/file1.sh to every user's home directory if user's id is even number.  Trying to execute following script:  #!/bin/bash cat /etc/passwd | while read LINE do     username=$(awk -v var="$LINE" -F: '{         if ($3 % 2 == 0)            print $1         }')     cp /root/nbu/file1.sh ~"$username" done   And it does nothing. If I echo cp /root/nbu/file1.sh ~"$username" command and execute it directly in the script, it works.  I guess the problem is that ~ gets expanded in the bash script, but can't figure out how to solve this problem.  Thank you in advance.
19905
I have a bunch of folders which are labelled in this way:   conf1  conf2  ...   But the order in the home directory is like   conf1  conf10  conf100  conf101  ...  conf2  conf20  conf200  conf201  ...   Because each folder contains a file named "distance.txt", I would like to be able to print the content of the distance.txt file, from each single folder, but in order, going from folder 1-->2-->3... to the final folder 272.   I tried several attempts, but every time the final file contains the all set of values in the wrong order; this is the piece of code I set:     ls -v | for d in ./*/;       do (cd "$d" &amp;&amp; cat distance.txt &gt;&gt; /path/to/folder/d.txt          );      done   As you can see I tried to "order" the folders with the command  ls -v   and then to couple the cycle to iteratively save each file.  Can you kindly help me?
93860
On Windows 7, I have a directory containing the following four files:   xxx.txt xxx.txt2 xxx2.txt xxx2.txt2   With the file have more than 3 character as a file extension, the behavior of the wildcard * seems odd:  dir *.txt  10/13/2014  04:14 PM                 6 xxx.txt 10/13/2014  04:17 PM                 6 xxx2.txt 10/13/2014  04:17 PM                 6 xxx2.txt2 10/13/2014  04:14 PM                 6 xxx.txt2            4 File(s)             24 bytes            0 Dir(s)   6,660,980,736 bytes free   I would expect to see only the two files with txt extension and not the ones with txt2 (like it would on a Linux machine). Does MS-DOS ignore the truncate the file extension to 3 characters or does it add automatically another wildcard at the end? If I want to delete only the files with txt extension and not the one with txt2, which command should I use? Thanks