Touch, A Silly Linux Command

In a break from common Linux command line tools, I’m going to show you a silly command that exists in Linux® called touch. It’s silly in that it looks ridiculous to begin with but someone created it for a reason.

touch means you’re going to touch a file or directory.   It is often used to create empty new files, like this:

Alpha:~ computerlamp$ touch Avengers

If you ls, you’ll see a file named Avengers in the current directory. Now try the command cat on Avengers.

Alpha:~ computerlamp$ cat Avengers

Hey, nothing there! You created a file with nothing in it. Not a single Avenger to be found in the Avengers file. Not even a Hawkeye or a Black Widow.  This means that if you need a new file, you cause this command to create it just like you can use echo.  Unlike touchecho actually puts words into the file.

There’s nothing stopping you from touching a file that already exists.

Alpha:~ computerlamp$ touch Avengers

Run ls again and nothing has changed. You can also try find and you won’t see anything different.  it doesn’t look like my command did anything.

So why did I touch it? I touched it for some reason, something must have changed, I just need to find out what.  It turns out there’s another flag to ls that will let me see the changes I made

Try this, run ls with the -l flag. It looks like:

Alpha:~ computerlamp$  ls -l
total 0
-rw-r--r--  1 computerlamp  staff  0 Nov 12 11:33 Avengers

See that date in there? That’s the date the of the last time the file was modified. Every time you touch a file, that gets updated. Try it a few times and see. touch was made so it’s easy to change that time. The 0 before the Nov in the date is the size of the file in bytes. The other things we’ll discuss in the next post.

Leave a Reply

Your email address will not be published. Required fields are marked *