First of all: Insert USB drive (usally 8GB+ is needed). format w disk utility to GUID Partition Map and Mac OS Extended (Journaled).
can be downloaded from App Store or with:
softwareupdate --fetch-full-installer
full syntax for specfic version is needed:
softwareupdate --fetch-full-installer --full-installer-version 10.13.6
When it's downloaded run:
Example with Mojave
sudo /Applications/Install\ macOS\ Mojave.app/Contents/Resources/createinstallmedia --volume /Volumes/<USBDRIVE_NAME> --nointeraction --downloadassets
For a beta version:
sudo /Applications/Install\ macOS\ Mojave\ Beta.app/Contents/Resources/createinstallmedia --volume /Volumes/<USBDRIVE_NAME> --nointeraction --downloadassets
The “–downloadassets” flag is new in macOS Mojave It downloads assets which may be required during installation.