Redirection paths

The path that comes after the redirection operator can include directory parts, and tildes to expand; both of the following redirections will work, if the mydir directory exists in your home directory:

$ cd
$ printf 'Hello, file!\n' > mydir/myfile
$ printf 'Hello, file!\n' > ~/mydir/myfile

Variables such as HOME can also be expanded for the file destination:

$ printf 'Hello, file!\n' > "$HOME"/myfile

For output redirection to a new file path to work, you will need permission to create files in the destination directory. If the file already exists, you will need permission to write to it in order to replace its contents. For example, if we try to write a file to the root user's home directory while we are not root, we will probably find this is not allowed:

$ printf 'Hello, root!\n' > ~root/myfile
bash: /root/myfile: Permission denied