Bash-cat 中的一个隐藏。文件或写入
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30035358/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash - cat in a hidden . file or write to it
提问by Clutchy
Let's say I make a file .history.txt:
假设我创建了一个文件 .history.txt:
touch .history.txt
and I try to write to it:
我试着写信给它:
cat > .history.txt
after having done that all I get is:
完成后,我得到的是:
bash: .history.txt: is a directory
What I need is to be able to write some text to it like I would be able to any normal file. Any ideas what am I doing wrong?
我需要的是能够像写入任何普通文件一样向它写入一些文本。任何想法我做错了什么?
回答by Max
A file doesn't need to already exist in order to redirect output to it (the shell will create the file if necessary). But Bash is telling you that .history.txt
already exists and is a directory, so you can't write to it.
文件不需要已经存在才能将输出重定向到它(如有必要,shell 将创建该文件)。但是 Bash 告诉你.history.txt
已经存在并且是一个目录,所以你不能写入它。
You either need to remove the existing directory rm -rf .history.txt
or use a different file name. Then cat > .whatever.txt
should work on its own.
您需要删除现有目录rm -rf .history.txt
或使用不同的文件名。然后cat > .whatever.txt
应该自己工作。