I have folder with subfolders and files inside. I want to copy all html files from all subfolders in main folder (parent) and have it in new folder (dist) with the same folder structure. (I am using Mac)
parent
subfolder1 - file1.html, file4.html
subfolder2 - file2.html
subfolder3 - file3.html
Expected result is dist folder with structure the same as in parent folder:
dist
subfolder1 - file1.html, file4.html
subfolder2 - file2.html
subfolder3 - file3.html
I am using this command:
cp -R ./parent/templates/**/*.html ./dist/templates
But the result is templates folder filled up with .html files but no subfolders copied.
dist
file1.html
file2.html
file3.html
file4.html
So I am not sure how to do it.
how to do it.
With GNU cp you could try:
cd ./parent/templates/ &&
cp -R --parents **/*.html ../../dist/templates
But I would recommend to use rsync.
Related
I have two folders
frontend/static/
static/
I want to rsync first folder but want to ignore second folder
rsync -av --delete --exclude-from 'rsync_exclude.txt'
I write in rsyng_exclude.txt
static
igonore both
or
./static/
ignore neither.
Is there any method to ignore only static/ and rsync frontend/static/
In an sftp session, is there a way for me to put the contents of a folder, but only files (not subfolders)? Here's an example.
Folder
main.py
config.py
requirements.txt
__pycache__ (a folder)
Above is a sample of the local directory. From the folder that encloses Folder, I'd SFTP to the target server. How do I put only main.py, config.py, and requirements.txt (they're files not folders)? . I don't want to put __pycache__ as it's a folder.
If I put -r Folder it will copy Folder and all its contents, including __pycache__. If I put -r Folder/*, it will put all the contents of Folder, without Folder itself, including __pycache__. This is close to what I want. A variant of put -r Folder/* that only copies file contents, not subfolders. So it would skip the __pycache__ folder when copying contents.
Thanks!
Just remove the -r if you do not want to recurse into the subdirectories:
put Folder/*
I have a folder which i want to copy and overwrite an existing folder in a directory.
Logic : i unzip the file , it will consist of 3 files [ test1.txt, test2.txt, test3.txt ]
Source Folder
- home/source/folder1
- test.zip
Targer Folder
- home/target
when i use the unzip command , file structure will be as follow
- home/target/folder1
- test1.txt
- test2.txt
- test3.txt
- test.zip
Initially i was using this command to copy the source folder to the target folder
cp -R home/source/folder1 home/target
However, when i trigger this the second time , it will create a sub folder of folder1
- home/target/folder
-test1.txt
-test2.txt
-test3.txt
-test.zip
-folder1
I found a few thread suggesting to use -T command
cp -R -T home/source/folder1 home/target
However this will also result the same folder structure as
- home/target/folder
-test1.txt
-test2.txt
-test3.txt
-test.zip
-folder1
The last resort which i will go to is to write a script to remove first and copy the folder
-rm -r home/target/folder
-cp -R home/source/folder1
Point 1 :
i was wondering if it is possible to replace or overwrite the whole folder itself
e.g after we have unzip the files , folder structure will be as this in target folder
- home/target/folder1
-test1.txt
-test2.txt
-test3.txt
-folder1
using the cp copy, it will automatically replace the existing folder1 and its content to how it is reflected in source folder
Source Folder
- home/target/folder1
- test.zip
Using this approach is working as expected, however i was wondering if in point a approach is possible
[ -d home/target/folder1 ] && echo "Workbook Directory Exist , removing twbx files content" && rm -r home/target/folder1
cp home/source/folder1 home/target
Fore example, I have some files in my project, structure could be like this
Project/
-- file1.txt
-- file2.txt
-- build/
-- sub-folder/
I want to zip some files from my project and I can do that using ZIP command (build folder and some other files are excluded from zip)
zip -r build/project-04.05.2016 ./ -x *\build\*
After this new file is created:
build/project-04.05.2016.zip
In Mac Finder when I double click on this file it becomes unzipped like this:
build/project-04.05.2016/
----------- file1.txt
----------- file2.txt
----------- subfolder/
I would like to somehow zip this archive, so when it's unzipped, instead of "project-04.05.2016" I get a folder "project" with the same content. I was trying to rename the file to "project-04.05.2016" after it's zipped as "project", but when it's unzipped the results are the same. Maybe there's a way to first move the files to some temporary "project" folder and than to zip them to "project-04.05.2016.zip"? Thanks in advance.
Here is my current solution, it's a small script and I'm not too satisfied with it, but it works. I will accept if someone answers with more elegant solution. So, here it is:
#clear the contents of the previous build first
rm -r build/*
#copy required files to a temporary folder
rsync -av --exclude=build ./ build/project
#change current directory to build
cd build/
#zip files from build/project folder
zip -r "project-04.05.2016" project
#remove temporary folder
rm -r project/
#final zip file is at location:
#build/project-04.05.2016.zip
I have a folder structure like this
Folder1 Folder2 Folder3 ...FolderXYZ
Each of these Folders contains around 500 files named like
event-yyyy-mm-dd-0001.jpg_backup event-yyyy-mm-dd-0002.jpg_backup ... and
event-yyyy-mm-dd-0001.jpg event-yyyy-mm-dd-0002.jpg ....
I need to copy all *.jpg_backup files from Folder1 Folder2 ... to a new created subdirectory within a diffrent folder Folderexisting, strip the _backup from the filenames, and make a zip with all the renamed files, named after parent directory (e.g. Folder1.zip).
The script should be able to do this recursively for all folders. OS is a Debian Wheezy with no GUI.
THX in advance