$ sort continents.txt

sort takes the standard input and orders it alphabetically for the standard output (it doesn’t change the file itself). Here, the continents in continents.txt will be listed in alphabetical order:

Africa Antarctica Asia Australia Europe North America South America
$ cat glaciers.txt | sort > sorted-glaciers.txt

Here, the command takes the standard output from cat glaciers.txt and “pipes” it to sort. The standard output of sort is redirected to a new file named sorted-glaciers.txt.



A few commands are particularly powerful when combined with redirection. Let’s try them out.

First, use cat to view the contents of lakes.txt.


Sort the contents of lakes.txt.


Then type:

cat lakes.txt | sort > sorted-lakes.txt

Use cat to output the contents of sorted-lakes.txt.

Sign up to start coding

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?