Learn

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.
  • 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.

Instructions

1.

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.

2.

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.

3.

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?