Bash - Cat in a Hidden. File or Write to It

Let's say I make a file .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?

10

1 Answer

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.

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.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest