Receiving Permission denied when trying to use cat command to create a file [duplicate]

I am working with Ubuntu version 18.04.4 LTS. I tried to create a file using the following command: sudo cat > filename.yaml and received a "Permission denied error" I can create the file using the VIM editor and sudo. Please advise.

0

2 Answers

I'm not an expert on cat but I suspect the command as you've entered it above will produce an error by design. Cat is used to print and concatenate files.

Example commands with cat are cat filename.yaml which will print the contents of filename.yaml to standard output (i.e. the terminal); while cat file1.yaml file2.yaml > filename.yaml will combine the contents of the existing files file1.yaml and file2.yaml into a new file called filename.yaml.

2

If you want to create a file, you can run:

touch filename.yaml (if the current directory is owned by your user)

or

sudo touch filename.yaml (if you are not the owner of the directory from where you are tunning the command)

For the reason why cat is not the proper command, you can refer to the other answer (ad related comments) by Concrete_Buddha user

You Might Also Like