You mean writing to a file using a shell script? Here are a few ways:
touch file
This method will simply create a file, but if the file already exists, it simply changes the modification date to the time you used that command.
echo "text" > file
That method overwrites the contents of file
to text
. If you wanted to clear a file, you can simply do this:
echo "" > file
Say you want to write more than one line to it, and you don't want to use thousands of echo
commands, you would use this command:
cat << EOF > file
test
test1
foo
bar
EOF
That enables you to write multiple lines in one command. The contents of file
would then be this:
test
test1
foo
bar
If you wanted to append to a file, replace >
to >>
.
Hope this helps!
EDIT: Oh, I see, so you would write the file in gedit, using the .sh
extension (optional, but it's a good idea), and then on a file manager, right click on the file, select Properties->Permissions, and check Allow executing file as program
. Then you can double-click on it and it will run :). Also, if you want to do so in the terminal, you can run this command to make it executable (you might want to prepend sudo
if it doesn't belong to you):
chmod +x file
And to run:
./file