tar -Sczvf sparse_file.tar.gz sparse_file
Search This Blog
Compress sparse files preserving their holes
Find sparse files in Linux
find ./ -type f -printf "%S\t%p\n" | awk '$1 < 1.0 {print}'
find ./ -type f -printf "%S\t%p\n" | awk '$1 < 1.0 {print $2}'
To find and remove the sparse files:
find ./ -type f -printf "%S\t%p\n" | awk '$1 < 1.0 {print $2}' | xargs rm -f
To find and compress the sparse files:
find ./ -type f -printf "%S\t%p\n" | awk '$1 < 1.0 {print $2}' | xargs -I {} sh -c "tar -Sczvf {}.tar.gz {}; rm -f {}"
SSH public key authentication rejected with debug message: no mutual signature algorithm
ssh user@remote-server -vvvv
debug1: no mutual signature algorithm
Cause
The RSA SHA-1 hash algorithm is being quickly deprecated across operating systems and SSH clients because of various security vulnerabilities, with many of these technologies now outright denying the use of this algorithm.
Solution
Generate SSH key using ED25519 algorithm:ssh-keygen -t ed25519
See also
Use GNU grep to count the length of substring between two words
brew install grep
and command is called ggrep instead of grep.
Get the substring between two words
echo "<person><name>abc</name></person>" | grep -o -P '(?<=<name>).*(?=</name>)'
Output should be:
abc
Count the length of substring
echo "<person><name>abc</name></person>" | grep -o -P '(?<=<name>).*(?=</name>)' | wc -c
Output should be:
3
Count substring lengths for each line
cat multi-lines.txt | while read line; do echo $line | grep -o -P '(?<=<name>).*(?=</name>)' | wc -c; done
see also
Use grep to count number of occurs of a specific element in a single line XML text
<result><id>1</id><id>5</id><id>7</id></result> <result><id>71</id></result> <result><id>15</id><id>33</id></result>
I use grep -o:
cat input.txt | while read line; do echo $line | grep -o '<id>' | wc -l; done
The output should be:
3 1 2
Install Starcraft on Ubuntu Linux 22.04 LTS
1. Enable 32 bit (i386) arcitecture
sudo dpkg --add-architecture i386
2. Install wine-staging
- Add WineHQ gpg key
wget -nv https://dl.winehq.org/wine-builds/winehq.key -O - | sudo apt-key add -
- Add WineHQ repository
sudo add-apt-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ jammy main' sudo apt update
- Install winehq-staging
sudo apt install --install-recommends winehq-staging
wine-staging will be installed into /opt/wine-staging
3. Install required packages
sudo apt update sudo apt install libgl1-mesa-glx:i386 libasound2:i386 libasound2-plugins:i386 libc6:i386 libncurses5:i386 libstdc++6:i386 libxtst6:i386 libldap-2.5-0:i386 libfreetype6:i386
4. Download StarCraft-Setup.exe
Download StarCraft-Setup.exe from https://us.battle.net/download/getInstaller?os=win&installer=StarCraft-Setup.exe
5. Install StarCraft
Run the commands below in a Terminal window to install StarCraft:
export WINEDLLPATH=/opt/wine-staging/lib/wine/fakedlls export LD_LIBRARY_PATH="/opt/wine-staging/lib:$LD_LIBRARY_PATH" WINEDEBUG=-all WINEPREFIX="${HOME}/.wine" /opt/wine-staging/bin/wine ./StarCraft-Setup.exe
While installation, you may be asked to install "Mono" and "Gecko" packages for the wine prefix.
6. Fix QT platform plugin error
Installation may be failed with error: This application failed to start because it could not find or load the QT platform plugin "Windows"
To work around this, you need to install attr package and use setfattr command to removed the atrribute: user.DOSATTRIB
6.1. Install attr package
sudo apt install attr
6.2. Remove file attribute
find "${HOME}/.wine/drive_c/Program Files (x86)/Battle.net" -name qwindows.dll -exec setfattr -x user.DOSATTRIB {} \;or
setfattr -x user.DOSATTRIB "${HOME}/.wine/drive_c/Program Files (x86)/Battle.net/Battle.net.13894/platforms/qwindows.dll"More details about this issue: see
6.3. Continue the installation
After removing the attribute, you can then continue the installation by executing the command below in the Terminal window:
WINEDEBUG=-all WINEPREFIX="${HOME}/.wine" /opt/wine-staging/bin/wine "${HOME}/.wine/drive_c/Program Files (x86)/Battle.net/Battle.net.exe"
7. Create StarCraft startup script
After installation, you can start StarCraft using the command below:
WINEDEBUG=-all WINEPREFIX="${HOME}/.wine" /opt/wine-staging/bin/wine "${HOME}/.wine/drive_c/Program Files (x86)/StarCraft/x86/StarCraft.exe"You can also create a wrapper script at ~/.local/bin/starcraft and add contents below
#!/bin/bash export WINEDLLPATH=/opt/wine-staging/lib/wine/fakedlls export LD_LIBRARY_PATH="/opt/wine-staging/lib:$LD_LIBRARY_PATH" WINEDEBUG=-all WINEPREFIX="${HOME}/.wine" /opt/wine-staging/bin/wine "${HOME}/.wine/drive_c/Program Files (x86)/StarCraft/x86/StarCraft.exe"You need to make the script executable:
chmod +x ~/.local/bin/starcraft
You can now start StarCraft with command
starcraft
See also
AND OR NOT operators for grep
grep OR
- use '\|'
grep 'pattern1\|pattern2' file
- use -E
grep -E 'pattern1|pattern2' file
- use -e
grep -e pattern1 -e pattern2 file
grep AND
- use pattern1.*pattern2
grep -E 'pattern1.*pattern2|pattern2.*pattern1' file
- use multiple (piped) grep commands
grep pattern1 file | grep pattern2
grep NOT (invert) option
- use -v option
grep -v pattern file
see also
Install Chinese Input Method on Kubuntu 22.04
sudo apt install ibus-libpinyin
- Right click IBus icon in the system tray, select Restart
- Right click IBus icon in the system tray, select Preferences
- In Preferences window, activate Input Method tab, click Add button, select Chinese, then Inteligent Pinyin
Install missing library for Cisco AnyConnect VPN client on Linux
"You are missing the required libraries for the authentication method you requested"
To fix the issue, install the library: libwebkit2gtk-4.0-37
sudo apt install libwebkit2gtk-4.0-37
See also
Install SimpleNote on Ubuntu Linux
- Download SimpleNote for Linux from https://github.com/Automattic/simplenote-electron/releases/tag/v2.21.0
- Install it:
sudo apt install ~/Downloads/Simplenote-linux-2.21.0-amd64.deb
- Start SimpleNote:
/opt/SimpleNote/simplenote
It may fail to start with errors:libva error: /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so init failed
- Adding
--disable-gpu-sandbox
could work around the issue./opt/SimpleNote/simplenote --disable-gpu-sandbox
- /usr/share/applications/simplenote.desktop also need to editted to add the arg:
[Desktop Entry] Name=Simplenote Exec=/opt/Simplenote/simplenote --disable-gpu-sandbox %U
- Adding
See also
Remove CTRL-M characters from a file in Linux or MacOS
You may need to do this when you import a text file from MS-DOS (or MS-Windows), and forget to transfer it in ASCII or text mode. Here are several ways to do it; pick the one you are most comfortable with.
- The easiest way is probably to use sed to remove the ^M characters. Type this command:
% sed -e "s/^M//" filename > newfilename
To enter ^M, type CTRL-V, then CTRL-M. That is, hold down the CTRL key then press V and M in succession. - You can also do it in vi: % vi filename
Inside vi [in ESC mode] type: :%s/^M//g
To enter ^M, type CTRL-V, then CTRL-M. That is, hold down the CTRL key then press V and M in succession. - You can also do it inside Emacs. To do so, follow these steps:
Go to the beginning of the document
Type: M-x replace-string RET C-q C-m RET RET
where "RET" means <press the return key> and C-q and C-m mean <hold the CTRL key and press the m (or q) key>.
see also
File name encoding on Linux
Linux File Name Encoding
- check LANG environment variable
echo $LANG
- See also
iocharset option of mount
iocharset=value
Character set to use for converting between 8 bit characters and 16 bit Unicode characters.
The default is iso8859-1. Long filenames are stored on disk in Unicode format.
- See also
convmv - converts filenames from one encoding to another
See also
Rocky Linux: enable maximise button in window titlebars
- Install gnome-tweaks
sudo yum install gnome-tweaks
- Start Tweaks via Activities, select Window Titlebars, check Maximise
Disable Gnome auto hide dock
- Install Dash to Dock extension for Gnome:
- Debian Linux:
sudo apt install gnome-shell-extensions gnome-shell-extension-dashtodock
- Ubuntu Linux:
sudo yum install gnome-extensions-app gnome-shell-extension-dash-to-dock
- Debian Linux:
- Open Extensions via Activities, enable Dash to Dock, click the gear button to customize, then disable Intelligent autohide
Install Chinese input method on Debian 11 (Gnome)
- Install ibus-pinyin
sudo apt install ibus-pinyin
- Settings -> Region & Language add Chinese (Pinyin) to Input Sources
- Log off and
Install openconnect on Mac OS
Install openconnect and openconnect-sso
brew install openconnect
pip3 install pyqt5 pyqtwebengine openconnect-sso
Connect to VPN
openconnect-sso -s your.vpn/address
Uninstall openconnect and openconnect-sso
brew uninstall openconnect
pip3 uninstall PyQt5-Qt5 PyQt5-sip PyQtWebEngine-Qt5 PySocks attrs colorama importlib-metadata keyring lxml openconnect-sso prompt-toolkit pyqt5 pyqtwebengine pyxdg structlog toml wcwidth zipp
NoMachine: Solve display issues on headless Linux machine
sudo systemctl stop display-manager sudo systemctl disable display-manager # sudo /etc/NX/nxserver --restart sudo systemctl restart nxserver
See also
Count code lines with cloc
- Install cloc:
brew install cloc
sudo apt install cloc
sudo yum install cloc
- Count total lines of code:
cloc ./src
see alos
Enable epel and powertools repositories on Rocky Linux
- enable epel repository:
For Rocky Linux 8:
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
For Rocky Linux 9:
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
For Rocky Linux 8/9:
sudo dnf upgrade --refresh -y sudo dnf repolist | grep epel
- enable powertools repository:
sudo dnf config-manager --set-enabled powertools sudo dnf repolist | grep powertools