HowTo Set Default Printer in Linux using Command Line Interface (CLI)
How Do i set an Default Printer to print anything from Command Line Interface in Linux. Simple Steps to setup Default Printer in Linux. Let’s see HowTo Set Default Printer Linux using lp commands.
HowTo Set Default Printer Linux Command Line
Before Configuring the Default Printer in Linux check with lpstat command
ravi@Arkit-Serv:~# lpstat -t scheduler is running no system default destination device for PRINTER1: socket://192.168.2.31:9100 PRINTER1 accepting requests since Mon 05 Aug 207 05:06:49 PM IST printer PRINTER1 is idle. enabled since Mon 06 Aug 2017 05:07:49 PM IST
If your Linux system uses CUPS, you can change the default printer using Command Line Interface Using simple one liner command. Set Default Printer Linux CLI.
# lpoptions -d <Printer Name>
The ‘d’ option sets the default printer.
ravi@Arkit-Serv:~# lpoptions -d PRINTER1 auth-info-required=none copies=1 device-uri=socket://192.168.2.31:9100 finishings=3 job-hold-until=no-hold job-priority=50 job-sheets=none,none marker-change-time=0 media=na_letter_8.5x11in number-up=1 printer-commands=none printer-info='HP DesignJet 500PS42' printer-is-accepting-jobs=true printer-is-shared=true printer-location=Hyderabad printer-make-and-model='Generic text-only printer' printer-state=3 printer-state-change-time=1502096629 printer-state-reasons=none printer-type=4100 printer-uri-supported=ipp://localhost:631/printers/PRINTER1
After Setting Up an Default Printer using lpoptions see the lpstat -t command output
ravi@Arkit-Serv:~# lpstat -t scheduler is running system default destination: PRINTER1 device for PRINTER1: socket://192.168.2.31:9100 PRINTER1 accepting requests since Mon 08 Aug 17 05:05:49 PM IST printer PRINTER1 is idle. enabled since Mon 09 Aug 217 05:04:49 PM IST
You can also setup an Default printer using simple environment variable adding into user profile file called ~/.bashrc. Why you have to add into .bashrc file because always when user logged into machine bashrc will be executed as part of profile loading.
If you use csh or tcsh, put this in your ~/.cshrc or ~/.tcshrc files because for CSH and TCSH prompt profile files
setenv PRINTER printer-name
If you’re a csh person, you might ask the difference between set PRINTER=printer-name and setenv PRINTER printer-name. The difference is that set makes a regular variable, and setenv creates an environmental variable. Regular variables are available only within csh. With an environmental variable, any program that you run from csh can also see the environmental variable.
If you set default printer whenever you issue an print command lpr <File Name> by default it uses default printer. If you want specify printer name do remember to add printer name while issuing print command from CLI.