简体   繁体   中英

Copy file system hierarchy partially from one drive to another and make tar package in simple way (in C /Linux)

Basically I want to do upgrade the filesystem of the current filesystem present in the linux based microcontroller. But problem is I don't want to upgrade it fully but most of the files. File system has tree like structure with different bin,conf,config,lib,opt,firmware folders files (like filesystem ).Also.ko files,kernel files will be there. I want to copy selective things from the filesystem .Say I have hard disk connected to it with path as /mnt/sata and one created folder as upgrade .

So I want to copy the above filesystem package into this upgrade folder to use it for further use. So what will be easy solution for it? Is it possible to do it using C program with Linux system commands/shell scripting?

you can execute commands in C in two ways:

  • using system("your command")
  • using pipeopen("your command", "read or write or both")

what did system() do? it just executes the command given

what did pipeopen do? it redirects the output of your command

that mean if your goal is to just executing a command use system and if your need is to execute the command and handle it's output use pipeopen

The command to copy file in linux is:

cp filename /destinationfolder

in your program to execute this command do:

system("cp filename /destinationfolder")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM