 Hello, today we are going to be looking at printing all your documents from the shell. Super easy to do. Your most common formats are supported. You can print PDFs, images, and text files, but we're also going to be looking at other things like writer documents, you know, Word documents, and spreadsheets. You're going to have to convert those first, but it's super easy to do, and you don't even need to create a separate file. You just pipe the output of a conversion command into your printing command, which is LPR in this case. There are different options. I'm going to go over that in the video. Also note, in the description of this video, as always, there's going to be a link to my notes where you can see, you know, just follow along and see what files to install and see example commands. So check out the links in the description of this video, and let's get started. Okay, we're going to be printing different types of files. We've got a PDF here with some text and image in it. I've got a plain text file, and I've got a JPEG file. And LPR is going to be able to print to all of those by default. Things like Word documents, writer documents, spreadsheets, we're going to be able to print those, but we're going to have to, there's a intermediate step. So that's where we're at. So what are we working with? When it comes to printing from the Linux shell, you have a few different options. If you're running a Unix or Unix-like operating system such as Linux, you're probably using cups. Okay, so I'm going to assume that you already have cups set up, which on most distributions you already do, which means you have a printer working basically. So we have LPR and LPR are two different programs, and they are different programs. They work differently, and they're also under different licenses. If you search your repositories, at least on a Debian-based system, for LPR, you'll find, oops, search LPR, you'll find a package called LPR. You see I don't have it installed. We are going to be working with LPR, but a different version of LPR. That's not the version we're working with. We're also not working with LP. What we're working with is there's a package called CupsBSD. So if you have cups installed, you're also going to want to install CupsBSD, okay? And that's just going to be some tools to use with cups. I'm not saying you can't use LPR. I just want to make sure that we're using the same version here. And one of the ways you can check this is once it's installed, Cups-BSD, you can search man LPR. And at the top here, it says GeneralBSD. You're using a different version. If it says Apple, Inc., then you're using the same version over in this tutorial. So if you're not unaware of this, the Cups, the common UNIX printing system, I think is what it's an acronym for, is basically owned and run by Apple. And it's used on pretty much all UNIX and UNIX operating systems. And it is under a BSD license. That being said, so the first thing you're going to want to do is apt install Cups-BSD. And if you don't already have cups installed, also install Cups. I'm assuming you already do. I'm not going to go over installing Cups. Once you have that installed, then you should have an LPR command. And we're going to go ahead and start using that. So what you can do is once you have that installed, you can do LPRStat-P-D. And this will list all your printers. So I have an HP network printer. That's the name of it right there. I also can print a PDF. We'll talk about that in a moment. And right now, my system default is set to PDF. Now if you don't have a system default, it's going to give you an error unless you tell it what printer you want to print to. So we're going to go over that as well. But let me go ahead and switch my default. Let's say I wanted to print to my HP printer here. I would do LPOptions-P and then give it this name right in there. And now that is my default printer. And if I go back to LPStat-P-D, it will list all my devices. Again, it will list, if you have more than one printer set up, they'll all be listed here. And you can see my default destination is that one right there. Now I'm in the directory that we were looking at, same directory as this. So you can see we have our documents, we have our spreadsheets, we have our PDFs. So I can cat out this file.txt. You can see what's in it. And if I wanted to print that file, all I have to do is LPR and the name of that file. So file.txt. And we'll print that file to the default printer. If I don't have a default printer set, I can tell it which printer I want to print to. For example, if I wanted to print to my PDF one, I can just say dash-p-pdf. So it has to be one of the ones from the list here. Again, the second column here is the name of the printer. So LPR-P and the printer and the file name. Once you want to print to your default printer, in which case you just say LPR and the file name. And again, it can do this for text files, PDF files, and most image files. If you try to print something like an ODT file, a Word document or spreadsheet, it's probably going to give you an error or it might print out a bunch of gibberish. So let's talk about that for a second. How can we print to a PDF? Oh, one other thing. Other than printing a file name, you can print the output of file. So I can say echo hello world and I can pipe that into LPR and it will print that text to whatever my default printer is. So I should be also do this LPR. And right now I had set my default printer. Did I not? Hold on a second here. I just printed those to my real printer. I thought that I was printing to a PDF file. So right now my printer in the other room is printing up those text files. So there's that. Now let's say you want to print to a PDF file. We have to install CUPS PDF. So sudo apt install CUPS-PDF should be the name of the package. Once that is installed, then when we run our LPstat-P-D, you'll see the PDF right there. And if you didn't have that, it will only list your physical printers. Right now we can print to a PDF. I am going to change my default printer to be the PDF printer. So I don't just keep printing and wasting ink and paper. I'm going to say LPoptions-D and just say capital PDF. Now my default printer is a PDF file. Now again I can echo hello world into LPR and it's going to print to a PDF file. But where did that PDF file go? Well if I list out my home directory, there's now a directory called capital PDF inside my home directory. I can list out what's in there and you can see there's a job here. And if I was to open that, xdg-open is a command you would use from the shell to open stuff up with the default viewer. You can see there, oh I got to give it that full name. Let's go ahead and move into that directory. So home PDF. And I have it alias to open so I can just open in that file name. And you can see we have just a plain PDF file with the text hello world in it. I can also, as I said earlier, I can list. Let's do it. I'll list out my root directory into LPR and you'll see now I have two files. And basically it's getting from standard input, it's a PDF, it's a job and it gives the job number. The higher the number so that's going to be my newer one right there. So I can do that and now I have a list of all the files in my root directory. So you can print the output of that. But again, if I come back up into this directory here and let's say I wanted to print the JPEG here. I can just say LPR and the name of that file. And now I should have a PDF right here of that file. And if that's confusing for you, I will go into my home directory PDF and you can see the files here. Let's go ahead and put that right there and then delete these files. But again, I'm printing to a PDF file just so I'm not constantly printing physical paper, but it would print out the same on a physical printer. So another example here is I can print out this letter PDF again, LPR, the name of the file and in this directory in my home directory, I have this. It's now a, well it's already a PDF, but I printed it as a PDF. But again, so it's printing it, it's giving it the name here. Last time it said standard input because we piped into it. This time it gives the name of the file that we printed and then gives a number. It says that it's a PDF job and the job number is that. But we can also set a title. So let's go ahead and do that. I am going to come up here and I will print out that file.txt and what I'll say is LPR-T and I'll just say my text file's name of my project, the title of my project, that file. Now, if I look in here, you can see the beginning of the job name is my text file and then the rest of it and if I click on that, it's a text file but in PDF format. Now let's talk about spreadsheets and Word documents. Those are things you might want to print from the shell. Now if I LPR one of those files, for example, LPR, let's go ahead and list out the files here, LPR and I try to print this Word document, it's going to give me an error, unsupported document format. So what we need to do is basically convert it to a format that it needs, that it understands. A good option for that would be a PDF, it's not the only option but it's one option and there's multiple ways to do that. In this particular case, I'm going to use a program called, I guess you would pronounce it UNOconv, so UNOconvert, which should be in your package manager if you're running a Debian-based system, so sudo apt install UNOconv, U-N-O-C-O-N-V. Once that's installed, we can use it to convert our writer documents and our spreadsheet documents to a PDF but we don't have to save it to a file because it can go to standard output. So if I was typing UNOconv-STDOUT for standard out and then give it a file name, in this case we'll do our Word document here. If I hit enter now, it's going to give me the PDF output to the shell, right there. So that's all PDF file but it's just displaying it to the shell but if I was to take that same command, pipe it into LPR and I'll give it a title of writer doc, there we go. Now I have a PDF here or again, if I point it to a regular printer, it would have printed this out. So that's great. So it's a little silly here, we're converting it to a PDF and then printing it to a PDF but if you were printing to a real printer, you would use the same command and just specify a physical printer. And that UNICONVERT command, also I'm just going to say UNICONVERT because it sounds better or sorry, UNOconvert I should say, not UNI, UNOconvert, will also work with our spreadsheet file. So I have a file here called Sheets, sheet.ods and there we go. I forgot to rename the title but now I have this file here, this is that spreadsheet file and it printed it out. So that is how you will print your standard office documents, PDFs, text files, word documents, spreadsheet documents, all to a physical or a PDF printer, it could be a network printer. Again, whatever you have set up in cups would be what you can print to. Anyway, I hope you found this useful and if you did, like, share, subscribe, check out my Patreon page, patreon.com, forward slash metal x1000, there's a link in the description of this video and I would love your support. If you can't support me financially, think about, again, liking, sharing, subscribing. I hope that you have a great day.