How to strip path while archiving with TAR [closed] How to strip path while archiving with TAR [closed] linux linux

How to strip path while archiving with TAR [closed]


In your "Extraction phase" you can use the strip-components flag like

tar xvf tarname.tar --strip-components=n

which will remove the first n leading components of the file name. Although if you have different file-path-components this will not work for all cases.

If you want to do it while archiving, only one thing comes to mind, and I will share

INPUT: list of files + full paths

1) for each line, split the path out of the filename

2) execute cd to that path and tar on that filename

3) repeat for each line