Showing posts with label Linux Knowledge. Show all posts
Showing posts with label Linux Knowledge. Show all posts

8/19/2021

Grub loader set default to Windows boot manager

 If you have dual boot setup, one of the frustrating things that you'll immediately notice is that Ubuntu is now set as the default OS in the Grub loader. There is an easy way to switch back to using Windows as the default.

sudo emacs /etc/default/grub

Change: GRUB_DEFAULT=? (? is the 0-based index of the Grub menu)

sudo update-grub

This is for grub-mkconfig (GRUB) 2.02-2ubuntu8.23

Ubuntu 18.04

3/02/2021

How to adjust Linux Ubuntu 18.04 screen brightness

sudo apt install  brightnessctl

sudo brightnessctl set 20%

5/11/2020

Enable Ubuntu 18.04/22.04 hibernate

To make things easy: create a swap drive instead of using a swap file.

In the BIOS settings: disable secure boot FIRST.

Then follow: https://www.geeksforgeeks.org/how-to-enable-hibernate-in-ubuntu-22-04-lts/

Edit the file /etc/systemd/sleep.conf with the following configuration:


[Sleep]
HibernateMode=shutdown


Enable the hibernation menu:

sudo gedit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.desktop.pkla
 
[Enable hibernate in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

[Enable hibernate in logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.handle-hibernate-key;org.freedesktop.login1;org.freedesktop.login1.hibernate-multiple-sessions;org.freedesktop.login1.hibernate-ignore-inhibit
ResultActive=yes
  

1/22/2018

Font of Microsoft OneDrive Text or text editor

Apparently Microsoft OneDrive website font depends on your operating system's browser version.
I like to use the Consolas font for the display, but it always uses Courier New as the font for my Ubuntu/Linux Firefox browser.

The solution is to install User Agent Switcher in Firefox and use Windows/Firefox to enable the Consolas font.

1/19/2018

How to install the latest cinnamon on Ubuntu 16.04

sudo add-apt-repository ppa:embrosyn/cinnamon
sudo apt update
sudo apt install cinnamon 

1/11/2018

VIM frequently commonly used commands

Left: h
Right: l
Up: k
Down: j
Undo: u
Start Editing: i
Append at line end: A
Edit after cursor: a
Goto line: number then G
Delete line: dd

1/06/2018

Linux下的飞鸽传书 iptux

sudo apt install iptux

Tools | Preferences | System
Use gb2312 for Preference network encoding

11/29/2017

X11 Forwarding over Screen (gnome terminal screen command)

Before running screen:
echo $DISPLAY

Once you have re-attached to screen, explicitly set the environment variable:

export DISPLAY=:N.0

How to set up Canon MF247 dw printer on Ubuntu 16.04

1. Go to https://www.usa.canon.com/internet/portal/us/home/support/details/printers/black-and-white-laser/imageclass-mf247dw?tab=drivers_downloads and download the Linux driver.
2. Manually install "sudo apt install libgcrypt20-dev"
3. Run sudo ./install.sh. (I had to edit the file and make sure it runs DEB instead of RPM by changing "if which rpm > /dev/null 2>&1;" to  if [ 1 -eq 0];

NOTE: I got this error:
#----------------------------------------------------#
# cups restart
#----------------------------------------------------#
/etc/init.d/cups restart
[ ok ] Restarting cups (via systemctl): cups.service.


Could not install.

But it seems this error doesn't matter.

4. Then I can add the printer by using its ip: 10.1.30.154

11/22/2017

11/02/2017

emacs paste text wrong indent

It turned out that I was using emacs version 24.5.1, which has a bug that caused the wrong paste indent.
The solution to it:
  Install Emacs 25.3 by using the following command:
sudo add-apt-repository ppa:kelleyk/emacs
sudo apt update
sudo apt remove --purge emacs24
sudo apt install emacs25


8/30/2017

CloudCompare hangs on Linux/Ubuntu 16.04

To fix that:
Display | Display Options | Change Auto-compute octree for picking to NEVER

8/16/2017

Use Cloud on Linux

Use OneDrive: https://github.com/skilion/onedrive

7/20/2017

.inputrc file content

set bell-style none  # disable bell
"\e[1;5C": forward-word   # ctrl + right
"\e[1;5D": backward-word  # ctrl + left

1/06/2017

How to change terminal cursor shape and color

For gnome-terminal:
Profile Preference | Cursor Shape (Prefer no blinking block)
Then:
Add "echo -ne '\e]12;#ff0000\a'" to change the color to red

To disable cursor blinking:
gsettings set org.gnome.Terminal.Legacy.Profile:/org/gnome/terminal/legacy/profiles:/:$(gsettings get org.gnome.Terminal.ProfilesList default|tr -d \')/ cursor-blink-mode off

To disable Ubuntu Cinnemon cursor blinking:
System settings | Keyboard Turn off text cursor blinks

For Putty:
Window | Appearance | Cursor Appearance: to change shape
Window | Colors | Cursor Color: to change the color  

For Google Docs:

12/26/2016

How to restart Ubuntu cinnamon

pkill -HUP -f "cinnamon --replace"

9/07/2016

How to fix Docker

Sometime the Docker won't stop and it just hangs on any commends.

So far I haven't figured out a way to fix it without rebooting the machine.

Even worse: docker daemon won't start after reboot. I need to reinstall docker to get it to work. And I had to use the following commands to uninstall and reinstall to make it work.

$ sudo apt-get autoremove --purge docker-engine
$ rm -rf /var/lib/docker
$ sudo apt-get install docker-engine

8/03/2016

How to use SSHFS

# To install
sudo apt install sshfs

# To mount
sshfs -o idmap=user dev@192.168.1.45:/ /mnt/sshfs/

# to umount
fusermount -u /mnt/sshfs/

8/02/2016

Best Linux Apps

App store: https://gitee.com/spark-store-project/spark-store Ways to change the HDPI scale: Find the scale.txt file in the .deepinwine folder and change it, e.g. ~/.deepinwine/Spark-CloudMusic/scale.txt

Video editing software: Kdenlive
Screen recorder software: Simple Screen Recorder (sudo apt install simplescreenrecorder)

Music: Install Spark Store, install Netease Cloudmusic(wine)(Setup keyboard shortcut to the wine application: ① Put the cloudmusic.sh to the ~/bin folder 【
#!/bin/sh

case $1 in
   "play")
       key="Control_L+Alt_L+P"
       ;;
   "next")
       key='Control_L+Alt_L+Right'
       ;;
   "prev")
       key='Control_L+Alt_L+Left'
       ;;
   "up")
       key='Control_L+Alt_L+Up'
       ;;
   "down")
       key='Control_L+Alt_L+Down'
       ;;
   *)
       echo "Usage: $0 play|next|prev|up|down"
       exit 1
        ;;
esac
xdotool key --window $(xdotool search --classname "cloudmusic.exe"|head -n1) $key
exit 0
② Use keyboard | custom shortcuts to setup different keyboard keys, e.g. Ctrl + Alt + Right, command: ~/bin/cloudmusic.sh next)

Office software: WPS office (To install: flatpak install flathub com.wps.Office)
Reminder notes: Firefox/Edge tabliss
Notes: p3x Onenote (Setup keyboard shortcut: keyboard | custom shortcuts | Ctrl + Alt + S, command: p3x-onenote, need to remove the Ctrl+Alt+S binding first if it's not available)
Remote ssh (Host IP may change): N/A yet
Onedrive client: https://github.com/bpozdena/OneDriveGUI https://github.com/abraunegg/onedrive (Install as a service and use the GUI if possible) systemctl --user status onedrive.service
systemctl stop [servicename]
systemctl disable [servicename]
rm /etc/systemd/system/[servicename]
rm /etc/systemd/system/[servicename] # and symlinks that might be related
rm /usr/lib/systemd/system/[servicename] 
rm /usr/lib/systemd/system/[servicename] # and symlinks that might be related
systemctl daemon-reload
systemctl reset-failed
Cloud notes: sudo snap install p3x-onenote to use Microsoft OneNote and OneDrive
PDF Viewer: Master PDF Editor, http://code-industry.net/public/master-pdf-editor-4.3.89_qt5.amd64.deb (Don't upgrade to 5.0 versions because some features need to be paid)
Image Viewer: XnView MP
Microsoft Teams: Install Teams as an app via Chrome app
Chinese Input: sogou pinyin, but need to do fcitx 搜狗输入法100%CPU占用解决方法
在fcitx配置里把搜狗云拼音这个选项去掉就可以很完美的解决这问题了
安装:对于Ubuntu22.04,sudo apt remove fcitx* (要把fcitx5的全部卸载,必须用fcitx4),然后再安装sogou.deb, 最后再sudo apt install -f
对于hdpi 高分辨率两个显示器,可以修改~/.config/
sogou-qimpanel/skin 下面的一个皮肤font_size,对于高分辨率可以通过修改皮肤来切换字体大小
IMPORTANT: 需要取消掉Ctrl+Alt+P and Ctrl+Alt+B, Ctrl+Alt+S hotkey shortcuts的占据:打开Fcitx配置,Global Config, Show Advanced Options, disable Ctrl+Alt+P, Ctrl+Alt+B and Ctrl+Alt+S

SSHFS: to mount a remote system to your machine
Hex Binary Data Viewer: bless
Text Editor: Emacs
Disk management: gparted
Get network IP of other devices: wireshark
Markdown language viewer: https://github.com/retext-project/retext
Symbols: /opt/sogoupinyin/files/bin/sogoupinyin-specialsymbol associate to Ctrl + Shift + Z
Dictionary: Install Spark, install 欧路, bind ~/bin/run-dict.sh to Super + 2
/usr/share/eusoft-eudic/eudic
wmctrl -a 欧路

Wechat:
  - First choice: Install Spark Store, install 微信 linux version
Use Ctrl + Alt + W to bring up the window, save the following code to ~/bin/open_linux_wechat.sh, then Keyboard | shortcuts
#!/bin/bash

# 获取所有微信窗口的ID并存储在数组中
wechat_windows=($(xdotool search -name '微信'))

# 获取当前活动窗口的ID
current_window=$(xdotool getactivewindow)

# 初始化标志,判断是否找到匹配的微信窗口
found=0

# 遍历微信窗口ID数组
for window_id in "${wechat_windows[@]}"
do
    # 如果当前窗口ID与微信窗口ID匹配
    if [ "$current_window" -eq "$window_id" ]; then
        # 设置标志为1,表示找到了匹配的微信窗口
        found=1
        break
    fi
done

# 如果找到匹配的微信窗口
if [ "$found" -eq 1 ]; then
    # 最小化该微信窗口
    xdotool windowminimize "$window_id"
else
    # 否则激活微信窗口
    for window_id in "${wechat_windows[@]}"
    do
        xdotool windowactivate "$window_id"
    done
fi
exit 0

  - Second choice: Install Spark Store, install 微信(wine)https://docs.qq.com/doc/DQmZGVXVNaGlDeXlx 
    WINEPREFIX="/home/liangzou/.deepinwine/Mejituu-WeChat/" WINEARCH=win64 /opt/mejituu-wine8/bin/wine control
修改scale:Press command key to search for Spark Wine App Launcher, change the global scale setting.
Use Ctrl + Alt + W to bring up the window: /opt/apps/com.qq.weixin.mejituu/files/shortcut_key.sh "Ctrl+Alt+W"


========================DEPRECATED==============================
安装完需要修复黑色边框的问题:https://github.com/MiderWong/deepin_wechat_shadow_killer

有时候系统更新完之后会出现打不开微信的情况,重新启动一下电脑就好了

* /opt/deepinwine/tools/run_v4.sh needs to be modified to use: WINE_CMD="LC_ALL=zh_CN.UTF-8 $APPRUN_CMD"
* Setup shortcut ctrl + alt + w:

请在路径:设置中心->键盘->快捷键中添加,如下:

昵称:提取微信消息

命令:/opt/deepinwine/tools/sendkeys.sh w WeChat

快捷键:Ctrl+Alt+w

按照以上就能设置成功。


* 常用命令:安装最新Wechat,WINEPREFIX=~/.deepinwine/Deepin-WeChat-latest/ deepin-wine WeChatSetup.exe

修改分辨率:WINEPREFIX=~/.deepinwine/Deepin-WeChat/ deepin-wine winecfg

* If not using deepin-wine and wine instead, the method to change default Linux browser to open links:
Modify ~/.wine32/drive_c/Program Files/Internet Explorer/iexplore.exe to a script:
#!/bin/bash
exec /usr/bin/firefox "$@"

* If not using deepin-wine and wine instead, fix the shadow issue:

Reference: (https://zhuanlan.zhihu.com/p/106926984). Solution is already in OneDrive ubuntu_home/bin-scripts.tar fix-wechat.py

在 Ubuntu 下安装 Deepin-wine 环境后,QQ 界面的字体看着不太舒服,于是就找了些文章看看能不能改成微软雅黑,经过一番折腾后修改成功,主要步骤如下:

    在 /usr/share/fonts/ 目录下建立个文件夹用于存放 windows 的字体,例如:windows
    下载微软雅黑字体文件 msyh.ttc (https://github.com/owent-utils/font/blob/master/%E5%BE%AE%E8%BD%AF%E9%9B%85%E9%BB%91/MSYH.TTC),并复制到这个目录
    运行 fc-cache 更新字体信息缓存
    打开注册表:WINEPREFIX=~/.deepinwine/Deepin-Wechat deepin-wine regedit
    找到键 HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLink
    修改里面的三个字段的数据,在前面加上 MSYH.TTC,Microsoft YaHei

Image Viewer: wine + faststone image view (windows version)
* To install: WINEARCH=win32 WINEPREFIX=~/.deepinwine/Deepin-FSViewer deepin-wine6-stable FSViewerSetup78.exe
* Use the open with to open: command is: env WINEPREFIX=/home/liangzou/.deepinwine/Deepin-FSViewer deepin-wine6-stable /home/liangzou/.deepinwine/Deepin-FSViewer/drive_c/Program\ Files/FastStone\ Image\ Viewer/FSViewer.exe
* 常用命令:WINEPREFIX="/home/liangzou/.deepinwine/Deepin-FSViewer" deepin-wine6-stable uninstaller
* 常用命令:https://bbs.deepin.org/en/post/238765


7/22/2016

Shell/Bash frequently/commonly used commands

Bash Commands:
==============
# Find all cpp files with debug in it.
$find . -name \*.cpp -exec grep -q "debug" '{}' \; -print

# Import Bash script tips
http://www.davidpashley.com/articles/writing-robust-shell-scripts/

if [ -z "${ZONE-}" ]  # if ZONE is null
if [ -n "${ZONE-}" ]  # if ZONE is non-zero
if [ -f "/cluster/env.sh" ] then  # if file exists
  echo "haha"
fi

RSRC=${1:-"/var/www"}  # default to /var/www if the first arg is null.

# Get group members
getent group docker


status (an init conf file in /etc/init/*.conf)

# Rename file extensions
for i in `ls --color=never`; do j=`echo $i | awk -F "." '{print $1}'`; echo $j; mv $i $j.bin; done
# Rename a file with leading 0 prefix
for i in `ls *.jpg`; do j=`echo $i | awk -F "." '{print $1}'`; k=$(printf "%06d" $j); mv $i $k.jpg; done

# To find and replace
sed -i 's/haha/xixi/g' $input
use -i to change the input file directly


for i in `grep -r "2009 Google" * -l`; do sed -i 's/2009\ Google/2010\ Google/g' $i; done
for i in `find . -name BUILD`; do echo $i; sed -i 's/\"\/\/third_party/\"@deepmap_base\/\/third_party/g' $i; done
for i in `find . -name BUILD`; do for j in common point_cloud protos third_party public anga_clients; do sed -i "s/\"\/\/$j/\"@deepmap_base\/\/$j/g" $i; rm -rf $j; done; buildifier $i; done
for i in `find . -iname "SCon*"`; do if grep -q "\\.a" $i; then echo $i; fi done

# Loop a bash array
ids=(1 2 3)

for i in ${ids[@]} do echo $i; done;

for i in {0..10}; do echo $i; done;

# Loop file content: each line
cat run.txt | while read line; do echo $line; done

# Change file name
for i in `cat files.txt`; do echo $i; j=`echo $i | awk -F hgt '{print $1}'`; mv $i ${j}.hgt.zip; done

# Change files names based on pages
j=0
for i in `ls *.pdf`; do mv $i "第${j}页.pdf"; j=$(($j+1)); done

# Sort by size
du -sh * | gsort -h

# cd to real path of a link
cd -P

# List files with full absolute path
ls -d -1 $PWD/*

# tar filter
find . -name '*.php' | tar -cvjf my.tar.bz2 --files-from -

http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz -O - | tar -xz
The wget option -O specifies a file to which the documents is written, and here we use -, meaning it will written to standard output and piped to tar and the tar flag -x enables extraction of archive files and -z decompresses, compressed archive files created by gzip.

# To get computer hardware info
inxi