Попробуйте команду rename
Ларри Уолла. Не устанавливается по умолчанию во всех системах, и в некоторых есть другая команда с таким именем. Он определенно доступен для систем на основе Debian.
rename
это sed
для имен файлов.
Нужно указать весь путь:
tar -xf playground.tar playground/test.txt
Вы можете использовать tar --list
или tar -t
, чтобы просмотреть содержимое архива, чтобы увидеть, что там:
$ tar -tf playground.tar
playground/
playground/text.txt
Вот полный журнал того, что я сделал, чтобы воспроизвести вашу проблему:
$ cd $(mktemp -d) # Go to a new empty directory
$ mkdir playground
$ touch playground/test.txt # Make the file we will tar
$ tar cf playground.tar playground # Make the tar
$ tar -tf playground.tar # List the contents of a tar
playground/
playground/test.txt # There's our file! It has a full path
$ rm -r playground # Let's delete the source so we can test extraction
$ tar -xf playground.tar playground/test.txt # Extract that file
$ find. # Check if the file is now there
.
./playground.tar
./playground
./playground/text.txt # Here it is!
Кроме того, вам не нужно было упаковывать весь каталог. Это тоже сработало бы. Я также добавил test2.txt
, чтобы показать, что весь каталог не распакован.
$ cd $(mktemp -d) # New directory
$ touch test.txt test2.txt # Let's make a few files
$ tar -cf playground.tar *.txt # Pack everything
$ tar -tf playground.tar # What's in the archive?
test2.txt
test.txt # Look: No directory!
$ rm *.txt # Clear the source files to test unpacking
$ tar -xf playground.tar test.txt # Unpack one file (no directory name)
$ find.
.
./test.txt
./playground.tar # There it is!
Имя архива должно быть включено в пути к файлам:
tar xf playground.tar playground/test.txt