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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like