Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Assuming you're in the root folder where are all directories for compression (in your case /), you can use find along with xargs command, e.g.

find dir1/ -name "*.fit" -print0 | xargs -i% -r0 sh -c 'mkdir -vp "$(dirname "/another_dir/%")" && gzip -vc "%" | tee "/another_dir/%".gz > /dev/null && rm -v "%"'

Note: You can also replace | tee "/another_dir/%".gz > /dev/null with > "/another_dir/%".gz.

This will find all .fit files in dir1/ and pass them to xargs command for parsing where % is replaced with each of your file.

The xargs command will:

  • create the empty folder (mkdir) with its parents (-p) as a placeholder,
  • compress given file (%) into standard output (-c) and redirect compressed output to tee,
  • tee will save the compressed input into .gz file (since tee by default prints the input to the terminal screen, sending it to /dev/null will suppress it, but it'll still save the content into the given file).

After successful compression, remove the original (rm). You can always remove that part, in order to remove them manually after verifying your compressed files.

It is important that you're in relative folder to your dir1/, so all paths returned by find are relative to the current folder, so you don't have to convert absolute paths into relativeconvert absolute paths into relative (this still can be done by realpath, e.g. realpath --relative-to=$absolute $current, but it will just overcomplicate the above command).

On macOS, to use -r argument for xargs, you need to install GNU xargs (brew install xargs) and use gxargs command instead. Similar on other BSD systems.

Related question: gzip several files in different directories and copy to new directory.

Assuming you're in the root folder where are all directories for compression (in your case /), you can use find along with xargs command, e.g.

find dir1/ -name "*.fit" -print0 | xargs -i% -r0 sh -c 'mkdir -vp "$(dirname "/another_dir/%")" && gzip -vc "%" | tee "/another_dir/%".gz > /dev/null && rm -v "%"'

Note: You can also replace | tee "/another_dir/%".gz > /dev/null with > "/another_dir/%".gz.

This will find all .fit files in dir1/ and pass them to xargs command for parsing where % is replaced with each of your file.

The xargs command will:

  • create the empty folder (mkdir) with its parents (-p) as a placeholder,
  • compress given file (%) into standard output (-c) and redirect compressed output to tee,
  • tee will save the compressed input into .gz file (since tee by default prints the input to the terminal screen, sending it to /dev/null will suppress it, but it'll still save the content into the given file).

After successful compression, remove the original (rm). You can always remove that part, in order to remove them manually after verifying your compressed files.

It is important that you're in relative folder to your dir1/, so all paths returned by find are relative to the current folder, so you don't have to convert absolute paths into relative (this still can be done by realpath, e.g. realpath --relative-to=$absolute $current, but it will just overcomplicate the above command).

On macOS, to use -r argument for xargs, you need to install GNU xargs (brew install xargs) and use gxargs command instead. Similar on other BSD systems.

Related question: gzip several files in different directories and copy to new directory.

Assuming you're in the root folder where are all directories for compression (in your case /), you can use find along with xargs command, e.g.

find dir1/ -name "*.fit" -print0 | xargs -i% -r0 sh -c 'mkdir -vp "$(dirname "/another_dir/%")" && gzip -vc "%" | tee "/another_dir/%".gz > /dev/null && rm -v "%"'

Note: You can also replace | tee "/another_dir/%".gz > /dev/null with > "/another_dir/%".gz.

This will find all .fit files in dir1/ and pass them to xargs command for parsing where % is replaced with each of your file.

The xargs command will:

  • create the empty folder (mkdir) with its parents (-p) as a placeholder,
  • compress given file (%) into standard output (-c) and redirect compressed output to tee,
  • tee will save the compressed input into .gz file (since tee by default prints the input to the terminal screen, sending it to /dev/null will suppress it, but it'll still save the content into the given file).

After successful compression, remove the original (rm). You can always remove that part, in order to remove them manually after verifying your compressed files.

It is important that you're in relative folder to your dir1/, so all paths returned by find are relative to the current folder, so you don't have to convert absolute paths into relative (this still can be done by realpath, e.g. realpath --relative-to=$absolute $current, but it will just overcomplicate the above command).

On macOS, to use -r argument for xargs, you need to install GNU xargs (brew install xargs) and use gxargs command instead. Similar on other BSD systems.

Related question: gzip several files in different directories and copy to new directory.

replaced http://superuser.com/ with https://superuser.com/
Source Link

Assuming you're in the root folder where are all directories for compression (in your case /), you can use find along with xargs command, e.g.

find dir1/ -name "*.fit" -print0 | xargs -i% -r0 sh -c 'mkdir -vp "$(dirname "/another_dir/%")" && gzip -vc "%" | tee "/another_dir/%".gz > /dev/null && rm -v "%"'

Note: You can also replace | tee "/another_dir/%".gz > /dev/null with > "/another_dir/%".gz.

This will find all .fit files in dir1/ and pass them to xargs command for parsing where % is replaced with each of your file.

The xargs command will:

  • create the empty folder (mkdir) with its parents (-p) as a placeholder,
  • compress given file (%) into standard output (-c) and redirect compressed output to tee,
  • tee will save the compressed input into .gz file (since tee by default prints the input to the terminal screen, sending it to /dev/null will suppress it, but it'll still save the content into the given file).

After successful compression, remove the original (rm). You can always remove that part, in order to remove them manually after verifying your compressed files.

It is important that you're in relative folder to your dir1/, so all paths returned by find are relative to the current folder, so you don't have to convert absolute paths into relative (this still can be done by realpath, e.g. realpath --relative-to=$absolute $current, but it will just overcomplicate the above command).

On macOS, to use -r argument for xargs, you need to install GNU xargs (brew install xargs) and use gxargs command instead. Similar on other BSD systems.

Related question: gzip several files in different directories and copy to new directorygzip several files in different directories and copy to new directory.

Assuming you're in the root folder where are all directories for compression (in your case /), you can use find along with xargs command, e.g.

find dir1/ -name "*.fit" -print0 | xargs -i% -r0 sh -c 'mkdir -vp "$(dirname "/another_dir/%")" && gzip -vc "%" | tee "/another_dir/%".gz > /dev/null && rm -v "%"'

Note: You can also replace | tee "/another_dir/%".gz > /dev/null with > "/another_dir/%".gz.

This will find all .fit files in dir1/ and pass them to xargs command for parsing where % is replaced with each of your file.

The xargs command will:

  • create the empty folder (mkdir) with its parents (-p) as a placeholder,
  • compress given file (%) into standard output (-c) and redirect compressed output to tee,
  • tee will save the compressed input into .gz file (since tee by default prints the input to the terminal screen, sending it to /dev/null will suppress it, but it'll still save the content into the given file).

After successful compression, remove the original (rm). You can always remove that part, in order to remove them manually after verifying your compressed files.

It is important that you're in relative folder to your dir1/, so all paths returned by find are relative to the current folder, so you don't have to convert absolute paths into relative (this still can be done by realpath, e.g. realpath --relative-to=$absolute $current, but it will just overcomplicate the above command).

On macOS, to use -r argument for xargs, you need to install GNU xargs (brew install xargs) and use gxargs command instead. Similar on other BSD systems.

Related question: gzip several files in different directories and copy to new directory.

Assuming you're in the root folder where are all directories for compression (in your case /), you can use find along with xargs command, e.g.

find dir1/ -name "*.fit" -print0 | xargs -i% -r0 sh -c 'mkdir -vp "$(dirname "/another_dir/%")" && gzip -vc "%" | tee "/another_dir/%".gz > /dev/null && rm -v "%"'

Note: You can also replace | tee "/another_dir/%".gz > /dev/null with > "/another_dir/%".gz.

This will find all .fit files in dir1/ and pass them to xargs command for parsing where % is replaced with each of your file.

The xargs command will:

  • create the empty folder (mkdir) with its parents (-p) as a placeholder,
  • compress given file (%) into standard output (-c) and redirect compressed output to tee,
  • tee will save the compressed input into .gz file (since tee by default prints the input to the terminal screen, sending it to /dev/null will suppress it, but it'll still save the content into the given file).

After successful compression, remove the original (rm). You can always remove that part, in order to remove them manually after verifying your compressed files.

It is important that you're in relative folder to your dir1/, so all paths returned by find are relative to the current folder, so you don't have to convert absolute paths into relative (this still can be done by realpath, e.g. realpath --relative-to=$absolute $current, but it will just overcomplicate the above command).

On macOS, to use -r argument for xargs, you need to install GNU xargs (brew install xargs) and use gxargs command instead. Similar on other BSD systems.

Related question: gzip several files in different directories and copy to new directory.

Expanding a bit.
Source Link
kenorb
  • 22.1k
  • 18
  • 149
  • 172

Assuming you're in the root folder where are all directories for compression (in your case /), you can use find along with xargs command, e.g.

find dir1/ -name "*.fit" -print0 | xargs -i% -r0 sh -c 'mkdir -vp "$(dirname "/another_dir/%")" && gzip -vc "%" | tee "/another_dir/%".gz > /dev/null && rm -v "%"'

Note: You can also replace | tee "/another_dir/%".gz > /dev/null with > "/another_dir/%".gz.

This will find all .fit files in dir1/ and pass them to xargs command for parsing where % is replaced with each of your file.

The xargs command will:

  • create the empty folder (mkdir) with its parents as a placeholder parents (mkdir-p) as a placeholder,
  • compress given file (%) into standard output (-c) and redirect compressed output to tee,
  • tee will save the compressed input into .gz file (since tee by default prints the input to the terminal screen, sending it to /dev/null will suppress it, but it'll still save the content into the given file).

After successful compression, remove the original (rm). You can always remove that part, in order to remove them manually after verifying your compressed files.

It is important that you're in relative folder to your dir1/, so all paths returned by find are relative to the current folder, so you don't have to convert absolute paths into relative (this still can be done by realpath, e.g. realpath --relative-to=$absolute $current, but it will just overcomplicate the above command).

On macOS, to use -r argument for xargs, you need to install GNU xargs (brew install xargs) and use gxargs command instead. Similar on other BSD systems.

Related question: gzip several files in different directories and copy to new directory.

Assuming you're in the root folder where are all directories for compression (in your case /), you can use find along with xargs command, e.g.

find dir1/ -name "*.fit" -print0 | xargs -i% -r0 sh -c 'mkdir -vp "$(dirname "/another_dir/%")" && gzip -vc "%" | tee "/another_dir/%".gz > /dev/null && rm -v "%"'

Note: You can also replace | tee "/another_dir/%".gz > /dev/null with > "/another_dir/%".gz.

This will find all .fit files in dir1/ and pass them to xargs command for parsing where % is replaced with each of your file.

The xargs command will:

  • create empty folder with its parents as a placeholder (mkdir),
  • compress file (%) into standard output and redirect compressed output to tee,
  • tee will save the compressed input into .gz file.

After successful compression, remove the original (rm). You can always remove that part, in order to remove them manually after verifying your compressed files.

It is important that you're in relative folder to your dir1/, so all paths returned by find are relative to the current folder, so you don't have to convert absolute paths into relative (this still can be done by realpath, e.g. realpath --relative-to=$absolute $current, but it will just overcomplicate the above command).

On macOS, to use -r argument for xargs, you need to install GNU xargs (brew install xargs) and use gxargs command instead. Similar on other BSD systems.

Related question: gzip several files in different directories and copy to new directory.

Assuming you're in the root folder where are all directories for compression (in your case /), you can use find along with xargs command, e.g.

find dir1/ -name "*.fit" -print0 | xargs -i% -r0 sh -c 'mkdir -vp "$(dirname "/another_dir/%")" && gzip -vc "%" | tee "/another_dir/%".gz > /dev/null && rm -v "%"'

Note: You can also replace | tee "/another_dir/%".gz > /dev/null with > "/another_dir/%".gz.

This will find all .fit files in dir1/ and pass them to xargs command for parsing where % is replaced with each of your file.

The xargs command will:

  • create the empty folder (mkdir) with its parents (-p) as a placeholder,
  • compress given file (%) into standard output (-c) and redirect compressed output to tee,
  • tee will save the compressed input into .gz file (since tee by default prints the input to the terminal screen, sending it to /dev/null will suppress it, but it'll still save the content into the given file).

After successful compression, remove the original (rm). You can always remove that part, in order to remove them manually after verifying your compressed files.

It is important that you're in relative folder to your dir1/, so all paths returned by find are relative to the current folder, so you don't have to convert absolute paths into relative (this still can be done by realpath, e.g. realpath --relative-to=$absolute $current, but it will just overcomplicate the above command).

On macOS, to use -r argument for xargs, you need to install GNU xargs (brew install xargs) and use gxargs command instead. Similar on other BSD systems.

Related question: gzip several files in different directories and copy to new directory.

Fixed typo.
Source Link
kenorb
  • 22.1k
  • 18
  • 149
  • 172
Loading
Fixed typo.
Source Link
kenorb
  • 22.1k
  • 18
  • 149
  • 172
Loading
Source Link
kenorb
  • 22.1k
  • 18
  • 149
  • 172
Loading