Search code examples
bashhttp-redirect

Bash redirect and append to non-existent file/directory


When I use >> nonexistent/file.log. Bash gives me back "No such file or directory".

How can I make a one liner that redirects the STDOUT/STDERR to a log file, even if it doesn't exist? If it doesn't exist, it must create the necessary folders and files.


Solution

  • Using install :

    command | install -D /dev/stdin nonexistent/file.log
    

    or use

    mkdir nonexistent
    

    first.