Posted inInformation Technology

Linux Cheats

Here is a list of Linux cheats I just want to keep handy. They will be added to as time goes on. When creating OpenSource software, you have to develop and test on many different distros. No, you can’t “just do Ubuntu.” Given the medical devices I help create and the Yocto building I do, I’m constantly frustrated by differing package managers and such.

List Installed Packages


sudo dnf list installed | grep -i <package-name>


sudo dpkg -l | grep -i <package-name>

90% of the time I’m looking for a specific package so I pipe it into grep and look for part of the package name.


sudo pacman -Qqe | grep -i <package-name>

There is a second option with Manjaro which might prove of more use.

sudo pamac list --installed

It provides more information like the repository group/section. When blank it was AUR or local install.

Search for Package to Install


sudo dnf search <package-name>
sudo dnf info <package-name>     # to get more info on the package


# either of these will work. apt-cache doesn't require sudo
apt-cache search <package-name>
sudo apt search <package-name>

# to get more information either of these will work
apt-cache show <package-name>
sudo apt show <package-name>


sudo pacman -Ss <package-name>     # official repositories
sudo pamac search <package-name>   # AUR - doesn't always find partial

For AUR it’s generally best to use a Web browser and search the AUR directly.

Remove a Package


sudo dnf remove <package-name>


sudo dpkg --purge <package-name>

Yes, there are other options you can use with dpkg, but only purge will attempt to find all of the “application data” stored in .config, .local, and the other usual places for each user. Everything else leaves this trash lying around so even if you re-install, you tend to have the same issues. Nine times out of ten the problem is in data stored in these trees.

Bad applications create $HOME/.my-app-data type directories and forget to add a postrm step to nuke them. The OS cannot save you from a bad developer.


sudo pacman -R <package-name>

Install a Package


sudo dnf install <package-name>

#if you have local RPM file to install
sudo rpm -i <file_name.rpm>
sudo dnf localinstall <file_name.rpm>


sudo apt-get install <package-name>
sudo dpkg -i <package-name>

#if you have local DEB file to install
sudo dpkg -i <file_name.deb>
sudo apt-get install <file_name.deb>
# whenever installing using dpkg need to follow with
sudo apt-get install -f<br><br># dpkg does not install missing dependencies


sudo pacman -Sy <package-name>
sudo pacman -sy --needed <package-name>   # to skip re-install of existing

# from AUR
sudo pamac build <package-name>

System Update


sudo dnf upgrade --refresh


sudo apt-get update
sudo apt-get upgrade


sudo pacman -Syyu

Command Recall

Everybody knows that most modern Linux distros support command recall via the up-arrow key in a terminal. Some will even let you go forward with the down-arrow key if you go too far back using up-arrow.

Back in the 1980s OpenVMS had RECALL which is much like the history command Linux finally has. RECALL would list in order your command history. You could issue RECA 22 to recall the 22nd entry in the list. Then you could edit the command or just execute it by hitting return. We could also pipe the output into the DCL SEARCH command to find just the commands we were interested in.

Linux has finally caught up!

Search for command in your history

Recall a command without execution

The “!” is the history command. (Isn’t that obvious???) The :p at the end tells history to print rather than execute. Without the :p it just executes.

Note: “!” commands do not get added to the command history like text history commands in most distros.

Change Git repo from Read-Only to Write

This sucks. It happens a lot when you are working across multiple Linux distros and intending only to build stuff. Inevitably you find something wrong, fix it, then git gags on the push.

cd <root of project directory>/.git
nano config

Of course, you need to have visited the remote repository and found the url for write access first. Your read-only URL will be a bit obvious.

You will notice the “origin” url has no username.

Replace with proper url. Assuming you have your ssh-key registered with the server, you can push once you save this. Yes, you will find all kinds of warnings about this, but, gotta do what ya gotta do!

Mercurial Push 403 Forbidden

You most likely have the exact same problem. You did a pull using a read-only url, then found an issue, made a change, now you want to put it back.

cd <project-directory>
cd .hg
nano hgrc

After you have found the read-write url, comment out the “default” that has a read-only url and add a default line with the proper read-write url. After you save the new config file, assuming you already have proper username+password or ssh-keygen values configured, you should be able to push.

List Package Contents


rpm -qpl file.rpm


dpkg --contents file.deb

Oh Shit, Ctrl-Z!

Yeah, you’ve all done it. If you are lucky you launched the executable from a terminal and you get to see the message about it being stopped.

fg [job-spec]

If you are unfortunate enough to have more than one stopped/suspended job, you need to get a list of them


you can then use the job job-spec listed by jobs to bring that job to foreground. The name job-spec can be

If you don’t want to wait for a bunch of stuff to get done you can use Ctrl+Z to get the stopped message then send the stopped job to the background with


When you list with jobs command you will see the status changed to running.

Change Password for PostgreSQL User

sudo su - postgres
psql postgres
ALTER ROLE username WITH PASSWORD 'newPassWord';

Add a User to a Group

sudo usermod -a -G boinc roland

sudo usermod -a -G group_name user_name

Ubuntu – set root password

sudo passwd

After you are prompted for your password to enable sudo, you will be prompted for a new password and you will be root at the time. That will allow you to run those annoying scripts that want you to

su -i

Search and Replace Within All Files in a Directory

cd ~/home/some_directory
sed -i 's/search_text/replacement_text/g' *

The “-i” is important because it means to substitute “in place.” The “g” at the end means global.

Roland Hughes started his IT career in the early 1980s. He quickly became a consultant and president of Logikal Solutions, a software consulting firm specializing in OpenVMS application and C++/Qt touchscreen/embedded Linux development. Early in his career he became involved in what is now called cross platform development. Given the dearth of useful books on the subject he ventured into the world of professional author in 1995 writing the first of the "Zinc It!" book series for John Gordon Burke Publisher, Inc.

A decade later he released a massive (nearly 800 pages) tome "The Minimum You Need to Know to Be an OpenVMS Application Developer" which tried to encapsulate the essential skills gained over what was nearly a 20 year career at that point. From there "The Minimum You Need to Know" book series was born.

Three years later he wrote his first novel "Infinite Exposure" which got much notice from people involved in the banking and financial security worlds. Some of the attacks predicted in that book have since come to pass. While it was not originally intended to be a trilogy, it became the first book of "The Earth That Was" trilogy:
Infinite Exposure
Lesedi - The Greatest Lie Ever Told
John Smith - Last Known Survivor of the Microsoft Wars

When he is not consulting Roland Hughes posts about technology and sometimes politics on his blog. He also has regularly scheduled Sunday posts appearing on the Interesting Authors blog.