O'Reilly logo

Raspberry Pi For Dummies by Mike Cook, Sean McManus

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Redirection to Create Files in Linux

Before we look at how you delete files and copy them, we should prepare some files to play with.

It’s possible to send the results from a command to a file instead of the screen; in other words, to redirect them. You could keep some listing results in a file, for example, so you have a permanent record of them or so you can analyze them using a text editor. You turn screen output into a file by using a greater-than sign and the filename you’d like to send the output to, like this:

ls > listing.txt

remember.eps You don’t need to have the file extension of .txt for it to work in Linux, but it’s a useful reminder for yourself, and it helps if you ever copy the file back to a Windows machine.

warning_bomb.eps Try using this command twice to list two different directories and then looking at the contents of listing.txt with the less command. You’ll see just how unforgiving Linux is. The first time you run the command, the file listing.txt is created. The second time you do it, it’s replaced without warning. Linux trusts you to know what you’re doing, so you need to be careful not to overwrite files.

If you want a bit of variety, you can use some other commands to display content on screen:

echo: This displays whatever you write after it on screen. You can use it to solve ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required