Linux tips and tweaks
Print file and folder/directory listings
Most of the time, browsing folders and drives and viewing the contents on the screen using Nautilus, Dolphin, Knonqueror, or whatever file browser you use, is just what you need, but there may be occasions when you need a hard copy of the contents of a folder, disc or drive. For example, you might want a printed listing of the contents of a CD or DVD and you may want to include this in the box insert or cover. That's just one posisble use and there are many more. How can we print file and folder listings in Linux? There are several different solutions to this and they are quite straightforward. Let's take a look at some of the ways we can do this.
One simple way to print a file and directory listing is using copy and paste. For example, click Place, Home Folder in Ubuntu to open a Nautilus file browser window. Press Ctrl+A to select all the files, then open Gedit text editor on the Applications, Accessories menu and press Ctrl+V. The full paths of the files and folders selected in the browser window are pasted in. You can then print the listing in Gedit by clicking the printer icon in the toolbar.
The best method of printing directory listings is to go to the command prompt and use the
then the output that is normally sent to the screen is redirected to the file. There's no need to create it beforehand because it is created automatically. We can then open the text file in a text editor or word processor and print it from there. (Using a word processor or text editor gives you the option to add headings, formatting and so on.)
There are more command line switches and you can look them up if you need them, but these will do for printing directory listings. You can use one or several, so
ls -l >file.txt
will send a long listing to file.text, which can then be loaded into a text editor and printed. To include all files and directories and those in subdirectories and to print one file per line you would use
ls -aR1 >file.txt
We just combine the switches we want. Load the file into your favourite text editor afterwards and print it out.