Linux / Unix Shell: Set Default Printer

How do I set default printer in my Bash shell under CentOS Linux or FreeBSD unix desktop operating systems?

CUPS is default printing system for Unix and Linux systems. It provides many ways to set the default printer destination. The “LPDEST” and “PRINTER” environment variables are consulted first for the default printer.


The syntax is as follows:

export PRINTER=printer-Name-Here

Linux / Unix: Bash Set Default Printer

Open a terminal and edit ~/.bashrc file, enter:
$ vi ~/.bashrc
Set default printer to sales_hplj_1536:

export PRINTER=sales_hplj_1536


export PRINTER

Save and close the file. Relogin into your account and print a test page using lp* commands such as lp, lpr, lpq, and lprm.
$ cat testfile.txt | lp
OR print ls command man page:
$ zcat /usr/share/man/man1/ls.1.gz | groff -man -Tps | lpr

Linux / Unix: CSH / TCSH Set Default Printer

Edit ~/.cshrc, enter:
$ vi ~/.cshrc
Set default printer to lab_hp8500:

setenv PRINTER lab_hp8500

Save and close the file. Relogin your account and print a test page using standard Unix lp* commands.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum