touch, rm, ls, and cp Files in the Linux/Unix Bash Shell Petting Zoo

touch, rm, ls, and cp Files in the Linux/Unix Bash Shell Petting Zoo

For this Linux/Unix bash shell tutorial, we have an extra special field trip planned in the “Petting Zoo” directory. Seatbelts everyone!

Lets take a look around. Use the “ls” command to list the directory contents.

zoo 01

Llamas, turkeys, and bison, oh my! I’d like to know a bit more about these files. The “-l” option shows us the file’s permissions, group owner, file size, and date last modified. Radical!

zoo 02

Oh no! That poor llama hasn’t been modified in years! How sad, it must be lonely. Lets “touch” it.

Touching a file updates the access and modification time of the file, so if we list the petting zoo directory contents again…

zoo 03

We see the llama has been “touched” recently. Doesn’t that just make you feel all warm inside?

Lets touch everything!

Ouch! That hedgehog was unpleasant, but you know what would be amazing? A unicorn.

It may not look like anything happened, but you have to believe!

zoo 04

Check it out! The touch command created a new file when we requested a file that didn’t exist. Magical!

This unicorn seems lonely and empty, I think she needs a friend. Lets make one with the cp command.

They should get along nicely, seeing as they are identical twins.

zoo 05

Not all files live out in the open, we can use the “-a” option with “ls” to show any hidden files.

zoo 06

Oh em gee! It’s a “.chupacabra”. Wait, what is a chupacabra? The “file” command will shed some light on this.

zoo 07

It’s worse than I could possibly have imagined. The .chupacabra is a Windows executable, and it’s upsetting the free and open-range files! It’s time for some good old-fashioned human intervention.

The .chupacabra is gone.

zoo 08

But what’s this hidden “.den”?

zoo 09

It’s a directory! Lets see what’s inside.

zoo 10

Holy blood-sucking cryptids! More “.chupacabras”. We need to recursively remove that “.den” directory, stat!

zoo 11

Peace has been restored to the “Petting Zoo” directory. Lets head home.

zoo 12

Lets review what we learned on our field trip:

  • ls lists the contents of a directory.
  • touch updates the date accessed and date modified times of a file.
  • If touch is given a non-existent file, it will create one for you.
  • the file command describes the file type.
  • cp copies a file.
  • rm removes a file.
  • rm -r removes a directory and all of the files and directories inside of it.

Class dismissed!

Featured image credit: Sam Howzit

touch, rm, ls, and cp Files in the Linux/Unix Bash Shell Petting Zoo was posted by on . JR is one of the three humans that run the behind-the-scene affairs of The Hello World Program. He is interested in spreading the good robot word over the vast Inter-webs. His contributions to the show include editing, web programming, design, and music composition.

Discuss this article in the Comments below, or and it with your friends. Learn more about Linux by subscribing to The Hello World Newsletter .

Join the Discussion

Subscribe to our Mailing List

Stay up to date on the latest videos and tutorials with our monthly newsletter

The email entered is invalid