PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, May 17, 2022

[FIXED] How to copy files and preserve partial paths in Linux?

 May 17, 2022     copy, filepath, linux, partial, shell     No comments   

Issue

It's easy to copy files and preserve the full path as the source using --parent. Didn't find questions and solutions on how to preserve partial paths, keep the partial path and filename in lowercase as below,

Source: /A/B/c/d/e.txt

Target: /X/Y/c/d/e.txt

The only/dumb way I can think of is to parse out "c/d" from the source, and then "mkdir -p /X/Y/c/d"and "cp /A/B/c/d/e.txt /X/Y/c/d". Is there a better single-liner way without all the pre/postfix string operations?


Solution

A simple way would be to first cd (or pushd/popd) into /A/B, then let the -t (--target-directory) option replicate the relative path hierarchy.

cd /A/B && cp -t /X/Y --parents c/d/e.txt


Answered By - luciole75w
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing