Skip to content
Vitaliy Zhiltsov edited this page Jun 24, 2022 · 12 revisions

Update OS

sudo apt update && sudo apt upgrade && sudo apt autoremove -y && cat /var/run/reboot-required

Cool Tools

Add Alias

only for current session:

alias apt-get="sudo apt-get"

permanently

sudo gedit ~/.bashrc
alias apt-get="sudo apt-get"

Update certificates

if after apt update command you see:

An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: ...

sudo apt-key adv --refresh-keys --keyserver keyserver.ubuntu.com

Manage disks

Manage a disk

Turn on swap file:

How To Add Swap Space on Ubuntu 18.04

Manage permissions

Copy File Permissions to Another File

chmod --reference=reference_file file

Copy File Ownership to Another File

is the same: chown --reference=reference_file file

#Execute sudo without password

echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/$USER
sudo chmod --reference /etc/sudoers.d/README /etc/sudoers.d/$USER

Systemd logs (journalctl) are too large and slow

To limit log files to a specific size systemd provides a vacuum feature to "suck out" older information from log files.

journalctl --vacuum-size=200M

To archive:

> journalctl --disk-usage
Archived and active journals take up 136.0M on disk.

to set value a permanently: set SystemMaxUse=200M in /etc/systemd/journald.conf file and restarts the service:

systemctl restart systemd-journald

Yarn package and so on ... key expiry date updated (EXPKEYSIG ...)

Universal command to fix this issue for many different packages that have this issue:

sudo apt-key adv --refresh-keys --keyserver keyserver.ubuntu.com

How do I find all files containing specific text?

Do the following:

grep -rnw '/path/to/somewhere/' -e 'pattern'

-r or -R is recursive, -n is line number, and -w stands for match the whole word. -l (lower-case L) can be added to just give the file name of matching files. -e is the pattern used during the search Along with these, --exclude, --include, --exclude-dir flags could be used for efficient searching:

This will only search through those files which have .c or .h extensions:

grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"

This will exclude searching all the files ending with .o extension:

grep --exclude=\*.o -rnw '/path/to/somewhere/' -e "pattern"

For directories it's possible to exclude one or more directories using the --exclude-dir parameter. For example, this will exclude the dirs dir1/, dir2/ and all of them matching *.dst/:

grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"

This works very well for me, to achieve almost the same purpose like yours.

How do I get back to nano after hitting Ctrl-Z

#List your jobs
jobs
#Bring a job to the foreground
fg 1