在CentOS系統中,你可以使用tar
命令來批量提取文件。以下是一些常用的tar
命令選項和示例:
提取單個文件:
tar -xvf archive.tar -C /path/to/destination file1.txt
提取整個目錄:
tar -xvf archive.tar -C /path/to/destination directory_name/
提取所有文件:
tar -xvf archive.tar -C /path/to/destination
如果你有一個包含多個文件名的列表文件(例如files_to_extract.txt
),你可以使用以下命令來批量提取這些文件:
while IFS= read -r file; do
tar -xvf archive.tar -C /path/to/destination "$file"
done < files_to_extract.txt
find
命令結合tar
如果你想要提取某個目錄下所有特定類型的文件(例如所有.txt
文件),可以使用find
命令結合tar
:
find /path/to/source -type f -name "*.txt" | tar -xvf archive.tar -C /path/to/destination --files-from=-
tar
的--wildcards
選項如果你想要提取符合特定模式的文件,可以使用--wildcards
選項:
tar -xvf archive.tar --wildcards -C /path/to/destination 'pattern*'
假設你有一個名為backup.tar.gz
的壓縮文件,里面包含多個文件和目錄,你想提取其中的所有.txt
文件到一個指定的目錄/home/user/documents
:
mkdir -p /home/user/documents
tar -xvzf backup.tar.gz --wildcards -C /home/user/documents '*.txt'
-x
:提取文件。-v
:顯示詳細信息(verbose)。-f
:指定壓縮文件名。-C
:指定提取文件的目標目錄。--files-from
:從文件列表中提取文件。通過這些方法,你可以靈活地在CentOS系統中批量提取文件。