create nested folders
Make a folder and every folder above it that is missing, and copy a file into a path that does not exist yet.
Steps
-
mkdir -p a/b/cmake a, a/b and a/b/c, as needed; no error if they exist
-
mkdir -p "$(dirname dest/sub/file.txt)" && cp file.txt dest/sub/file.txtmake the folders for a copy, then copy
-
install -D file.txt dest/sub/file.txtthe same in one step (GNU)
-
cp --parents src/sub/file.txt dest/copy keeping the path: dest/src/sub/file.txt (GNU)
Commands used
mkdircpinstall
Each has a page in lore: lore mkdir opens it.
Related recipes
- add to the end of a fileAdd lines to a file without replacing it, also to a file only root can write.
- argument list too long"Argument list too long" from rm, cp or mv: too many files for one command line. Hand them over in batches.
- change permissions of a folder and everything in itGive a folder, its subfolders and its files the permissions or the owner they need, without making them open to everyone.
- check a file's permissionsSee who may read, write and run a file or a folder, and why a path is refused.