Linux Tips

Ubuntu Development environment build commands

Disable Windows ENV:PATH

1
2
sudo su
echo -e "[interop] \nappendWindowsPath=false">>/etc/wsl.conf

Necessary software pack

1
2
3
sudo apt update
sudo apt install cmake
sudo apt install build-essential

Bypass DNS Host Parse

Why? Bypass DNS server parse to avoid domain name pollution by GFW in China.

  • Find IP of Hostname by DNS lookup
1
2
nano /etc/hosts
# Format: XXX.XXX.XXX.XXX example.com

Use Windows Proxy

https://zhuanlan.zhihu.com/p/153124468
Get DNS Server IP, which point to windows
Apply only once

1
2
cat /etc/resolv.conf
export ALL_PROXY="<DNS Server IP Address>"

Persistence the proxy

1
2
3
4
sudo su
echo "host_ip=\$(cat /etc/resolv.conf | grep nameserver | cut -f 2 -d \" \")">>/etc/profile
echo "export ALL_PROXY=\"<Protocol>://\$host_ip:<your proxy port>\"">>/etc/profile
source /etc/profile

Install Homebrew

Install and config Oh-my-posh

Install LLVM

1
2
3
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh <version number> all

WSL Commands

1
2
3
4
5
wsl --install
wsl --list --online
wsl --shutdown
wsl --mount <DiskPath>
wsl --unmount <DiskPath>

Environement Variables

https://blog.csdn.net/xjjxjy_2021/article/details/130875975

Common Environement Variables

PATH: Search path of commands.
HOME
LOGNAME
HOSTNAME
SHELL

Usage in Shell

Print environment variable values
echo $<env var name>
Example: echo $PATH

Set a new environment variable
Example:

1
2
export a_env_var="A Environment Variable"
env | grep a_env_var

Unset a environment variable
Example:

1
2
unset a_env_var
env | grep a_env_var

Add/Delete a item for $PATH

1
2
3
4
5
6
# Add
export PATH=$PATH:<path>

# Delete
echo $PATH # Copy without the path that ready to delete
export PATH=<paths>

Persistence environment varibale

1
2
3
sudo su
echo "export PATH=\$PATH:<path>">>/etc/profile
source /etc/profile

Proxy

Set DNS Server

1
2
3
4
5
6
7
nano /etc/resolv.conf

# Add nameserver below (Google DNS Server)
nameserver 8.8.8.8
nameserver 8.8.4.4

source /etc/resolv.conf

Set proxy alias

1
2
3
4
sudo su
echo -e "\nalias setproxy=\"export ALL_PROXY=socks5://198.18.0.1:16001 && echo \${ALL_PROXY}\"\n">>~/.bashrc
echo -e "\nalias unsetproxy=\"unset ALL_PROXY && echo 'proxy unseted.'\"\n">>~/.bashrc
source ~/.bashrc

Commands

update-alternatives

Switch the software version by update-alternatives
https://blog.csdn.net/qq_21367897/article/details/89606953

Add a new alternatives group

1
2
update-alternatives --install <link> <name> <path> <priority>
# example: sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-16 1

Switch the version of software

1
2
update-alternatives --config <name>
# example: sudo update-alternatives --config clang

Remove alternatives group link

1
2
update-alternatives --remove <name> <path>
# example: sudo update-alternatives --remove clang /usr/bin/clang-14

alias

Define alias

1
2
3
# Example: 
alias print_hello_world="echo 'Hello world!'"
print_hello_world # Output: Hello world!

Show alias
alias -p

Persistence alias by put command into shell configuration file

1
2
3
4
sudo su
echo -e "\n <Some commands>">>~/.bashrc
echo -e "\n <Some commands>">>~/.bashrc
source ~/.bashrc

source

The Linux source command is a shell command that reads and executes commands from a file in current shell environment. file is typically a shell script, but it can also be any text file containing a series of commands. source command is often used to set environment variables, define functions, and execute initialization scripts.

find

https://www.linuxcool.com/find

Usage: find [path...] [expression]

1
2
3
4
find / -name *.conf     # Find file by name
find /etc -size +1M # Find file by size
find /home -user user # Find file own to specific user
find . # List all file, directory

Linux 字体

为当前用户安装字体 Install fonts for current user

Copy .ttf file into ~/.fonts

为所有用户安装字体 Install fonts for all users

Copy .ttf file into /usr/local/share/fonts/

加载导入的字体 Load fonts

fc-cache -fv

Other commands

mkfontscale
mkfontdir

Other Tips

sudo apt autoremove

Remove not required packages

Difference between profile and bashrc

https://www.linuxprobe.com/diff-bashrcprofile.html

从管理员账户返回到用户账户 Admin back to user account

Use: su <user name>

在Ubuntu通过终端开启文件资源管理器 Open File resource manager on Ubuntu

1
nautilus [path]

/dev/tty* Linux设备串口

https://blog.csdn.net/qq_38880380/article/details/96436604

软链接和硬链接(符号链接)

https://zhuanlan.zhihu.com/p/442336297
https://blog.csdn.net/LEON1741/article/details/100136449