You might consider using mkdir --parents
(or mkdir -p
for short) to avoid an error if the directory already exists (you can also create nested directories this way, e.g mkdir -p dir1/dir2/dir3
will create the requested directories and not throw an error if they already exist).
You may also want to consider omitting the touch
command entirely as >
will create the file for you if it doesn't already exist (FYI: >>
will append to the end of an existing file, wheras >
will overwrite an existing file.
So,
mkdir -p ~/Desktop/new_file && echo "Hello World" > ~/Desktop/new_file/adas.txt
Should do what you want, then you could later do things like:
echo "More text to add" >> ~/Desktop/new_file
More info can be found in the bash manpage (man bash
under SHELL GRAMMAR (particularly the Lists section.
Good Luck
echo
bit... – George Udosen Mar 12 '17 at 05:24