DEV Community

Discussion on: These are a few of my favorite: Terminal Shortcuts

Collapse
 
igormp profile image
Igor Moura

Just a heads up, touch isn't actually meant to create files (although it does it if the specified string doesn't exist), it is meant to update a file's timestamp (in case you point it to an already existing file).

You could also add the < operator - which does the same as cat, but is actually meant to redirect stuff into the stdout of your terminal.

Collapse
 
clickclickonsal profile image
Sal Hernandez

Oh wow, I didn't know that about touch. Thank you for clarifying this here.

I tried the < & that didn't seem to work on mac or linux.

Collapse
 
igormp profile image
Igor Moura • Edited

Weird, I've tried it in both systems and it works flawlessly.

Just to be sure, did you type in < filetoread? A lack of example might've been the problem in my post.

Collapse
 
dennisfen profile image
Denis Borisevich

Try this:

echo "some text" > new_file.txt

or this (which means basically "write data to the file until you meet EOF label"):

cat > new_file.txt << EOF
new line
another line
EOF

> will rewrite contents of the file
>> will append to the end of the file