小编bee*_*bee的帖子

tar 和 if 语句

我有一个脚本来检查一个文件是否存在于 tar 文件中,但出了点问题,因为它总是转到else脚本的一部分。我很确定它不应该是那样的。

日期采用“Mon dd”格式(1 月 11 日)。

echo "enter date: \c"
read date
tarfile=`tar -tvf tarfile.tar | grep some_file | grep "$date"`

if [ -f "$tarfile" ]; then
    echo "yes"
    else
    echo "no"
fi
Run Code Online (Sandbox Code Playgroud)

scripting tar ksh files

3
推荐指数
1
解决办法
3003
查看次数

从 tar 文件中提取单个文件并将其放入另一个目录

我需要将 tar 文件中的单个文件提取到另一个目录。

到目前为止我有这个:

此操作将单个文件提取到同一目录:

tar -xvf filename.tar ./file.txt
Run Code Online (Sandbox Code Playgroud)

我试过了,但没用

tar -xvf filename.tar /home/dir ./file.txt
Run Code Online (Sandbox Code Playgroud)

或这个:

tar -xvf filename.tar -C /home/dir ./file.txt
Run Code Online (Sandbox Code Playgroud)

tar ksh directory

1
推荐指数
1
解决办法
7528
查看次数

标签 统计

ksh ×2

tar ×2

directory ×1

files ×1

scripting ×1