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
Fedora
sudo dnf list installed | grep -i <package-name>
Ubuntu
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.
Manjaro
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
Fedora
sudo dnf search <package-name>
sudo dnf info <package-name> # to get more info on the package
Ubuntu
# 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>
Manjaro
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
Fedora
sudo dnf remove <package-name>
Ubuntu
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.
Manjaro
sudo pacman -R <package-name>
Install a Package
Fedora
sudo dnf install <package-name>
#if you have local RPM file to install
sudo rpm -i <file_name.rpm>
#or
sudo dnf localinstall <file_name.rpm>
Ubuntu
sudo apt-get install <package-name>
#or
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
Manjaro
sudo pacman -Sy <package-name>
#or
sudo pacman -sy --needed <package-name> # to skip re-install of existing
# from AUR
sudo pamac build <package-name>
System Update
Fedora
sudo dnf upgrade --refresh
Ubuntu
sudo apt-get update
sudo apt-get upgrade
Manjaro
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
Fedora
rpm -qpl file.rpm
Ubuntu
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
jobs
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
bg
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';
\q
exit
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.