I know you can do mkdir
to create a directory and touch
to create a file, but is there no way to do both operations in one go?
i.e. if I wa
This is what I would do:
mkdir -p /my/other/path/here && touch $_/cpredthing.txt
Here, the $_
is a variable that represents the last argument to the previous command that we executed in line.
As always if you want to see what the output might be, you can test it by using the echo
command, like so:
echo mkdir -p /code/temp/other/path/here && echo touch $_/cpredthing.txt
Which outputs as:
mkdir -p /code/temp/other/path/here
touch /code/temp/other/path/here/cpredthing.txt
As a bonus, you could write multiple files at once using brace expansion, for example:
mkdir -p /code/temp/other/path/here &&
touch $_/{cpredthing.txt,anotherfile,somescript.sh}
Again, totally testable with echo
:
mkdir -p /code/temp/other/path/here
touch /code/temp/other/path/here/cpredthing.txt /code/temp/other/path/here/anotherfile /code/temp/other/path/here/somescript.sh