0

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.

rcaaron
  • 1
  • 1

1 Answers1

0

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
    Aside from the "permission denied" error (which is from the shell, not from cat, and reflects the user's lack of rights in the target directory), the command cat > filename will indeed create filename - however, it will hang waiting to read file contents from standard input. Simply hitting Ctrl-D will terminate the command, resulting in creation of an empty file, similar to touch filename or > filename – steeldriver Jun 11 '20 at 22:18
  • A good point, thank you; I've learnt something. As Ctrl-D means EOF it makes sense that this termination would result in an empty file. However having said that cat still probably won't be the first tool out of the box next time I want to create an empty file ;) – Concrete_Buddha Jun 12 '20 at 08:45