1行のシェルからダウンロードして解凍します。

1行のシェルからダウンロードして解凍します。

私はインターネットからGNU tarのソースコードを取得する必要があります(http://ftp.gnu.org/gnu/tar/tar-latest.tar.gz)そして、シェルの1行にあるソースコードのすべてのファイルに含まれるすべてのCヘッダーファイルのリストを抽出します。パイプ、特にwgetコマンドを使用する必要があることを知っていますが、どのように機能させるかはわかりません。手動で行うと、リストは次のようになります。

Wordsplit.h ws2tcpip.h xalloc.h xalloc-oversize.h xattr-at.h xattrs.h xgetcwd.h xsize.h

ベストアンサー1

これはうまくいきますが、カールとタールが必要です(ほとんどのシステムではデフォルトで利用可能です)。

$ curl -sL -o- "http://ftp.gnu.org/gnu/tar/tar-latest.tar.gz" |tar -tz --wildcards --no-anchored '*.h'
tar-1.29/build-aux/snippet/_Noreturn.h
tar-1.29/build-aux/snippet/arg-nonnull.h
tar-1.29/build-aux/snippet/c++defs.h
tar-1.29/build-aux/snippet/unused-parameter.h
tar-1.29/build-aux/snippet/warn-on-use.h
tar-1.29/gnu/uniwidth/cjk.h
tar-1.29/gnu/argp.h
tar-1.29/gnu/argp-fmtstream.h
tar-1.29/gnu/argp-namefrob.h
tar-1.29/gnu/argp-version-etc.h
tar-1.29/gnu/bitrotate.h
tar-1.29/gnu/c-ctype.h
tar-1.29/gnu/c-strcase.h
tar-1.29/gnu/full-write.h
tar-1.29/gnu/gettext.h
tar-1.29/gnu/localcharset.h
tar-1.29/gnu/mbuiter.h
tar-1.29/gnu/progname.h
tar-1.29/gnu/se-context.in.h
tar-1.29/gnu/se-selinux.in.h
---------many more files follow-------------

あるいは、grepと組み合わせることもできます。

$ curl -sL -o- "http://ftp.gnu.org/gnu/tar/tar-latest.tar.gz" |tar -zt |grep '/src/.*\.h$'
tar-1.29/src/arith.h
tar-1.29/src/common.h
tar-1.29/src/tar.h
tar-1.29/src/xattrs.h

あなたの質問を考えると「すべてのCヘッダーファイルのリストを抽出する」上記のリストが必要だとします。

これらのファイルの内容を取得するには、.h次の方法を使用して内容を画面に「ダンプ」できます。

$ curl -sL -o- "http://ftp.gnu.org/gnu/tar/tar-latest.tar.gz" |tar -xzO --wildcards --no-anchored '*.h'

ヒント:読みやすくするためにANDを|less最後に置きます。

最後に、@don_crisstiが画面ダンプの代わりにローカルドライブに "* .h"ファイルを抽出するように提案したようにこれを完了するには、次のようにします。

$ curl -sL -o- "http://ftp.gnu.org/gnu/tar/tar-latest.tar.gz" |tar -xzf - --wildcards --no-anchored '*.h'

tar-1.29.hすべてのファイルを含む現在の作業ディレクトリに新しいフォルダが作成されます。

$ ls -ld tar-1.29
drwxr-xr-x 7 root root 4096 Mar 24 01:48 tar-1.29
$ ls -l tar-1.29
total 20
drwxr-xr-x 3 root root 4096 Mar 24 01:48 build-aux
drwxr-xr-x 3 root root 4096 Mar 24 01:48 gnu
drwxr-xr-x 2 root root 4096 Mar 24 01:48 lib
drwxr-xr-x 2 root root 4096 Mar 24 01:48 src
drwxr-xr-x 2 root root 4096 Mar 24 01:48 tests

おすすめ記事