Tags: technicalNotes Linux notes
[2023-07-16 Sun] Other notes are collected in smaller, atomic pages or articles. View a list of pages at Linux Notes.
These is an eclectic collection of notes on interesting topics and troubleshooting references that I come across related to using Linux. Expect many headings to be incomplete or even incorrect as they are often written in my own words based on my understanding at that moment, however - the notes should prove useful as an overview and general reference.
The source of this content is the markdown export of an org file and then using Oddmuse to display the page.
[disk usage - How do I count all the files recursively through directories - Unix & Linux Stack Exchange](https://unix.stackexchange.com/questions/4105/how-do-i-count-all-the-files-recursively-through-directories) provides several options to do this.
On a Mac, the .
after find
is necessary to specify the starting directory.
find . -type f | wc -l
The article How to check if a cron job ran | Benjamin Cane has detailed information on the logging of cron and grepping through the results.
New information for 2020: cron is now a systemctl service, so you can have the logs of cron / anacron with:
journalctl -u cron.service
if you did install anacron, it is the same with:
journalctl -u anacron.service
(anacron is for desktop, when your computer is not garanteed to be always on. It enforce that even if your computer is down at 5'00, daily jobs are run when the computer has started up).
- How to check cron logs in Ubuntu - Server Fault
If there is a unified log which may the default in the OS being used, then the syslog has to be grepped through for cron entries. This behavior can be changed:
By default on Ubuntu your cron output should be logged to varlog/syslog If you would like cron to log to it’s own file you can edit etcrsyslog.d/50-default.conf and uncomment the line
#cron.*
Then run
sudo service rsyslog restart
and your cron jobs will be logged to /var/log/cron.log
- Where are Cron Job errors logged? | DigitalOcean
For example converting jpg to png:
mogrify -format png abcd.jpg
The above also works on files like abcd.ico
.
Some words of wisdom from #emacs
<homerj> msys2, displayfusion, fences, and autohotkey are must-haves
Most of Linux is written in C, though newer developments often involve using Python as well. A user or a system admin need not know C to efficiently use Linux. A kernel developer must know C to be able to develop with the core of Linux.
Initial RAM filesystem. Generally created after each installation, and usually automatically updated after each system or kernel upgrade. These are the files and libraries and configurations that are loaded into the RAM during the system startup.
The Linux Kernel is a bunch of libraries which directly interact with the hardware. The user does not directly interact with the Kernel. The user, or any command can access the kernel using a combination of 'intermediaries' like system calls, [Capabilities and permissions](linux-notes.md). System calls form the glue between the user land and the kernel land which are essentially separate.
Kernel modules are essentially drivers. Each hardware component generally comes with a driver.
Windows OS Admins are not equivalent of a root
user. Windows admins are essentially users with special capabilities, but is not a kernel level user.
DLL's in Windows OS are the equivalent of kernel modules.
The extension .d could refer to a daemon or more commonly to a directory.
Core security in Linux is handled by SE Linux. Apparently the SE Linux library was open sourced by the NSA and is a significant contribution to Linux.
Reference: <https://unix.stackexchange.com/questions/125385/combined-mkdir-and-cd>
$_
is a special parameter that holds the last argument of the previous command. The quote around $\_ make sure it works even if the folder name contains spaces.
mkdir foo && cd "$_"
bg
.fg
brings the process to the foreground.See link to ubuntu manpages. On debian / ubuntu installing this is as simple as
sudo apt-get install dtrx
This actually seems useful for quick extractions and meta data exploration of deb packages, compared to struggling with the knobs of other tools like gzip, gunzip and so on.
This is based on an ubuntu droplet
Logged in as root: adding a user and adding the user to the sudo group:
adduser shrysr usermod -aG sudo shrysr
After this the password and other details have to be entered which is self explanatory.
Note on SSH keys and access: Using digital ocean - it is easy to create SSH keys for the root user. However, this has to be manually scp'd or added for any lesser users on the server. If the folder .ssh
is copied from the root user to the lesser user's home folder then the folder permission has to be changed appropriately.
The local ssh key can be accessed via cat:
cat ~/.ssh/id_rsa.pub
The authorised keys are stored in .ssh/authorised_keys
. The ownership of the folder can be changed with:
sudo chown -R $USER ~/.ssh
ssh-copy-id -i ~/.ssh/id_rsa shrysr@s.ragavan.co:~/.ssh/
curl -sL https://deb.nodesource.com/setup_12.x | bash - apt-get install -y nodejs
Instructions followed of Linode worked well. The latest version has to be noted and replaced below from Go's download page.
cd ~/temp curl -O https://storage.googleapis.com/golang/go1.12.7.linux-amd64.tar.gz
Verifying the sign
sha256sum ~/temp/go1.12.7.linux-amd64.tar.zg
Change ownership of the file
sudo chown -R ~/temp/go sudo mv go /usr/local
Change the .profile file
cat >> ~/.profile << EOF # Adding go to the path export GOPATH=$HOME/go export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin EOF
Re-read the profile
source ~/.profile
hostnamectl set-hostname example_hostname
Add this to the ~/.tmux.conf file. This may have to be created if unavailable.
Reference link
touch ~/.tmux.conf cat >> ~/.tmux.conf << EOF set -g default-terminal "tmux-256color" EOF
<span class="timestamp-wrapper"><span class="timestamp">[2019-08-03 Sat] </span></span> I have recently started using tmux to manage my VPS, which hosts my website and hopefully many more convenient things down the line.
A good prefix could be C-/
. Some of the commands are not totally intuitive like in Emacs. However, there are a number of plugins that can make life easier.
This blog post outlines a good good approach, that starts with installing the tmux plugin manager, which makes it easy to install plugins. I will reproduce the steps here for convenient reference. This is a part of converting my entire configuration into org source blocks, which can be tangled into configuration files. In this way, it also becomes easier to maintain.
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm # Append the following configuration to the .tmux.conf file cat >> ~/.tmux.conf << EOF # List of plugins set -g @plugin 'tmux-plugins/tpm' set -g @plugin 'tmux-plugins/tmux-sensible' set -g @plugin 'tmux-plugins/tmux-copycat' set -g @plugin 'tmux-plugins/tmux-pain-control' # .... maybe more plugins here # Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) run -b '~/.tmux/plugins/tpm/tpm' EOF
Detach the tmux process and return to the server's shell. The configuration of the server will have to be refreshed. It does not appear that the server has to be shut down, atleast for the changes above.
tmux source ~/.tmux.conf
jobs
: to find a list of the suspended programs, with number tags.Use AUR to install iosevka in Antergos / Arch as the package is already available.
yay -S ttf-iosevka
Setting the font in Emacs. This should be added to the init. The font height could vary based on the monitor size.
(set-face-attribute 'default nil :family "ttf-iosevka" :height 120)
For some reason, it appears though the gpg-agent is shown to be running, this configuration is required to make sure that the entered keys are stored in the keyring.
cat >> ~/.gnupg/gpg.conf <<EOF no-greeting no-permission-warning lock-never keyserver-options timeout=10 use-agent EOF
This is pertinent to Arch based distros.
sudo pacman -S tk
git config --global user.email "abcs@gmail.com" git config --global user.name "Mad Max"
scp
: tranfer a folder to the serverThe command will look like:
scp -r <from> user@45.56.88.290:<location>
Transferring a single file does not require the -r switch.
sudo apt-get update sudo apt-get dist-upgrade
Some apps are not available in the so called stable debian software archives. Therefore alternative sources have to be established for the same.
Installing flatpak on debian and adding the flatpak repository:
sudo apt-get install flatpak sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
Reboot after the above commands.
Note: Calling a flatpak based app is rather verbose, and is better served by defining appropriate aliases.
This app covers Slack and Whatsap and other networks. It still takes up about 1GB of RAM and the app itself is about 500MB, but it atleast covers all the platforms in one go and should be useful in the office.
In addition, the org.freedesktop.Platform
package has to be installed. The latter gets installed automatically, when executed in the terminal.
Pre-requisites for debian/ubuntu
sudo apt install libx11-dev libxext-dev libxss-dev libxkbfile-dev
flatpak install flathub com.meetfranz.Franz
The Slack app takes up a lot of memory.
flatpak install flathub com.slack.Slack
Creating xmodmap script : Swapping control and capslock keys Source: link
cat > ~/.xmodmap <<EOF ! ! Swap Caps_Lock and Control_L ! remove Lock = Caps_Lock remove Control = Control_L keysym Control_L = Caps_Lock keysym Caps_Lock = Control_L add Lock = Caps_Lock add Control = Control_L EOF
Executing xmodmap on the configuration above
xmodmap ~/.xmodmap
The developer edition of Firefox contains interesting features, and it appears to perform better. The developer edition is available as a package on Arch Linux (AUR). For Debian, the procedure is a little round-about.
The following procedure using flatpak is picked up from the Debian wiki page.
Using flatpak
Unofficial builds are provided by Fedora at <https://firefox-flatpak.mojefedora.Cz/>
sudo apt install flatpak sudo flatpak remote-add --from gnome https://sdk.gnome.org/gnome.flatpakrepo sudo flatpak remote-add --from org.mozilla.FirefoxRepo https://firefox-flatpak.mojefedora.cz/org.mozilla.FirefoxRepo.flatpakrepo
Then for "developer edition" (aka "Beta"):
flatpak install org.mozilla.FirefoxRepo org.mozilla.FirefoxDevEdition
and Running:
flatpak run org.mozilla.FirefoxRepo org.mozilla.FirefoxNightly
The Debian wiki also describes a method to add the flatpak installations to the Path. However, this is a newer feature and is unavailable at the moment on my machine.
echo 'export PATH=$PATH:/var/lib/flatpak/exports/bin' >> ~/.zshrc
The advantage of using conda is being able to quickly install reasonably recent versions of Emacs quickly on Debian type OS's which often reference older (stable) versions of software packages by default. Using conda would avoid adding PPA's or hunting for binaries or even compiling from source. Another advantage is that this approach can be used cross platform.
One disadvantage of this method is that the package is installed into the miniconda / anaconda package installation path. Though the instillation script of miniconda adds the path for bash, it has to be manually set for any other shell like zsh. However, once this is done - there appear to be no issues in using Emacs.
conda install -c conda-forge emacs
Reference: <http://derekmolloy.ie/resize-a-virtualbox-disk>
It does not appear to be possible to expand the size of a fixed format vdi. The floating format has a disadvantage of a read-write overhead for expanding the disk image as it is utilised.
However, as per the documentation, after the hard disk size reaches a stable stage, this overhead becomes negligible on an average.
Therefore the vdi has to be copied (or cloned), and the floating format has to be selected. This is done using the copy option in the virtualbox media manager. Once copied, the expanded vdi image has to be attached to the guest OS.
When the attachment is complete, the hardisk will show up in the virtualbox media manager app. Now the vdi size can be adjusted to the desired value.
The next step is to download the live iso of gparted. This should be loaded as a storage device with the live CD option selected. With this loaded, the existing partitions have to be changed appropriately<sup><a id="fnr.1" class="footref" href="#fn.1">1</a></sup>. This step has to be done to enable Linux to recognise the expanded harddisk.
Once this has been, the gparted iso can be removed and the guest OS can be booted as usual. However, the UUID of the paritions have to be changed appropriately. If not changed, there will be delay during boot, especially if the swap partition has been modified.
The actual partition setup and the UUIDs can be viewed with:
lsblk -f
The appropriate UUID has to be replaced in the file /etc/fstab
. Technically, the fstab file is generated by the command mkinitcpio
, but sometimes a manual change is necessary.
From the Arch linux wiki : archive : downgrading via downloading the Package from URL. Find the package you want under packages and let pacman fetch it for installation. For example:
pacman -U https://archive.archlinux.org/packages/ ... packagename.pkg.tar.xz
Downgrading via local cache
pacman -U /var/cache/pacman/pkg/<package-name>
It seems to be a very good idea to maintain a few older versions of packages in the cache, even at the expense of Harddisk space.
Further options are provided at this Unix stack exchange discussion.