Terminal output into text file

Is there any way in AppleScript to output the result of a terminal command (shell command) into a text file?

so e.g. if I did

do shell script "ls -l /"

To get the list of folders in root, could I output the result into a text file?


This will put it in a text file on your desktop.

do shell script "ls -l / > ~/Desktop/test.txt"