A file can be manipulated in a variety of ways. In fact, Unix built upon this to create an operating system where everything is treated as a file. Therefore learning some simple command line file operations is crucial:

  • New empty files are commonly created using the touch command.
  • The contents of a directory can be listed using the ls command. (Be sure to type a lowercase “L” as in “list” and not the number 1.)
  • A string of text can be output to the terminal using the echo command. This is useful in coordination with the > operator that redirects the text output to a file.
  • A file can be output and read using the cat command.
  • A file can be deleted using the rm command.



Using the command line, create a new file called lunch using the command touch lunch.

Optionally, you can verify that this file has been created by using the command ls to list all the files in the current directory.


Write a list of foods such as burger, salad, and sandwich to the lunch file using the following command:

echo "burger, salad, and sandwich" > lunch

Optionally, you can verify this by reading the file using the command cat lunch.


Delete the lunch file using the command rm lunch.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?