使用tee命令将输出重定向到不存在的目录中的文件 [英] use tee command to redirect output to a file in a non-existent dir

查看:570
本文介绍了使用tee命令将输出重定向到不存在的目录中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用tee命令将输出重定向到文件,并且希望在尚未创建的目录中创建文件.

I am trying to use the tee command to redirect output to a file, and I want the file to be created in a dir which is yet to be created.

date | tee new_dir/new_file

当new_dir不存在时,tee命令失败说

when new_dir is not there, the tee command fails saying

tee:new_dir/new_file:没有这样的文件或目录

tee: new_dir/new_file: No such file or directory

如果我在运行tee命令之前创建了new_dir,那么它可以正常工作,但是由于某些原因,我不想手动创建new_dir,是否可以使用tee命令创建new_dir?

If I create the new_dir prior to running the tee command, then it works fine, but for some reason I don't want to create the new_dir manually, is it possible to create the new_dir with the tee command ?

推荐答案

否.您必须在运行tee之前创建目录.

No. You'll have to create the directory before running tee.

这篇关于使用tee命令将输出重定向到不存在的目录中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆