linux 开发常用操作(持续更新)

1.杀掉某个用户的所有进程

killall -u 用户名

2.Ubuntu20.04查看mac地址

ip addr show

结果在link/ether查看

3.获取某个文件夹下以某个后缀结尾的文件的个数(这里以.h5为例)

3.1 先进入该目录

3.2 输入以下命令

ls -1 *.h5 | grep -c ''

4.服务器之间rsync命令传输文件免密

https://lxblog.com/qianwen/share?shareId=f7b2edbd-8a6c-491e-8fc3-ec6338d030c5

5.vim默认支持读UTF-8

To ensure Vim on Ubuntu reads Simplified Chinese (zh_CN) files correctly using UTF-8 encoding by default, you need to properly configure both the system locale and Vim's encoding settings. This ensures that files containing Simplified Chinese characters (e.g., 你好,世界) are displayed and edited without garbled text (乱码).


✅ Step 1: Enable and Set System Locale to zh_CN.UTF-8

First, ensure the Simplified Chinese UTF-8 locale is generated and active.

1. Reconfigure locales:

sudo dpkg-reconfigure locales
  • In the list, enable zh_CN.UTF-8 UTF-8 (press Space to select).
  • Set zh_CN.UTF-8 as the default locale if desired, or keep en_US.UTF-8 for mixed use.

2. Alternatively, generate locale manually:

sudo locale-gen zh_CN.UTF-8

3. Verify:

locale -a | grep zh_CN

✅ Output should include:

zh_CN.utf8

✅ Step 2: Configure Vim to Support UTF-8 and Chinese by Default

Edit your Vim configuration file:

nano ~/.vimrc

Add the following lines:

" Set internal encoding to UTF-8 (critical)
set encoding=utf-8

" Automatically detect file encodings — UTF-8 first, then BOM, then others
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936,latin1

" Default encoding when saving new files
set fileencoding=utf-8

" Terminal encoding (for terminal-based Vim)
set termencoding=utf-8

" Support Chinese in interface (optional)
language messages zh_CN.UTF-8

" Prevent line breaks from corrupting Chinese
set formatoptions+=mM

" Optional: Improve rendering of CJK characters
set ambiwidth=double

🔍 Key Points:

  • gb18030 is the official Chinese encoding standard and superset of gb2312/gbk. It's essential for full Simplified Chinese support.
  • UTF-8 is tried first; fallback to GB18030 if UTF-8 fails (e.g., legacy Chinese files).
  • ambiwidth=double ensures full-width display of Chinese characters.

✅ Step 3: Ensure Terminal Supports UTF-8

Your terminal must support UTF-8:

echo $LANG

Should output:

en_US.UTF-8
# or
zh_CN.UTF-8

If not, set it in ~/.bashrc:

export LANG=en_US.UTF-8
# or for full Chinese interface:
# export LANG=zh_CN.UTF-8

Then reload:

source ~/.bashrc

✅ Step 4: Test with a Simplified Chinese File

1. Create a test file:

echo "你好,世界!这是一段简体中文。" > chinese_test.txt

2. Open in Vim:

vim chinese_test.txt

✅ You should see Chinese text displayed correctly.

3. Check encoding detection:

Inside Vim, type:

:set fileencoding?
:set encoding?

Should show:

fileencoding=utf-8
encoding=utf-8

✅ Optional: System-wide Vim Configuration

For all users:

sudo nano /etc/vim/vimrc.local

Add the same settings, then ensure /etc/vim/vimrc includes:

source /etc/vim/vimrc.local

🛠 Troubleshooting

Issue Solution
Shows 你好 File opened in wrong encoding; use :e ++enc=gb18030 or ++enc=utf-8
Can't type Chinese Use ibus or fcitx input method: sudo apt install ibus-pinyin
Font missing Install a Chinese font: sudo apt install fonts-wqy-zenhei

✅ Final Recommendation

Add this minimal, robust config to ~/.vimrc:

set encoding=utf-8
set fileencodings=utf-8,gb18030,latin1
set fileencoding=utf-8
set termencoding=utf-8
set ambiwidth=double

This ensures Simplified Chinese files are read correctly by default, whether they are in UTF-8 or legacy GB18030/GBK encodings, while keeping UTF-8 as the preferred standard.

6.vim默认支持读GBK

To configure Vim to open text files in GBK encoding by default, you need to modify your Vim configuration file (~/.vimrc) to set appropriate encoding detection and conversion options.

GBK is a Chinese character encoding, and Vim uses fileencodings (plural) to define the order of encodings it tries when opening a file.

✅ Step-by-Step Configuration

  1. Open or create your ~/.vimrc file:
    bash
    vim ~/.vimrc

  2. Add the following lines:

vim
" Set internal encoding to UTF-8 (recommended)
set encoding=utf-8

" Define the order of encodings to try when opening a file
set fileencodings=ucs-bom,utf-8,cp936,gb18030,gbk,gb2312,latin1
🔍 Explanation:
cp936 is Microsoft's code page for GBK (Vim recognizes cp936 as equivalent to gbk).
gb18030 is a superset of GBK and commonly used in modern Chinese systems.
Placing cp936, gbk, and gb18030 early in the list ensures Vim detects GBK-encoded files correctly.
latin1 at the end acts as a fallback (since every file is valid Latin-1).

  1. (Optional) Force GBK for specific files
    If you want to always open files with .txt extension as GBK, add:

vim
autocmd BufReadPost .txt set fileencoding=cp936

Or for all files without a BOM and unknown encoding:

vim
autocmd BufNewFile,BufRead if &fileencoding == '' set fileencoding=cp936 endif

⚠️ Use this only if you're sure most of your files are GBK—otherwise, it may corrupt non-GBK files.

🔧 Verify It Works

Create a test GBK file (e.g., on Windows or using iconv):

bash
echo "中文测试" iconv -f utf-8 -t gbk > test_gbk.txt

Then open it in Vim:

bash
vim test_gbk.txt

Inside Vim, run:

vim
:set fileencoding?

It should show: fileencoding=cp936 or fileencoding=gbk.

🌐 Additional Notes
Vim internally uses encoding (default: usually UTF-8) for display. The fileencoding is the encoding of the file on disk.
Always keep encoding=utf-8 for modern compatibility.
On some systems, you may need to ensure GBK support is installed (usually included by default in Ubuntu/Debian via locales).

✅ Final Minimal ~/.vimrc for GBK Support

vim
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,gbk,latin1

This setup lets Vim auto-detect GBK files while safely falling back to UTF-8 or Latin-1 when needed.

Ubuntu20.04 安装docker

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04

posted @ 2024-01-15 09:40  Mr42Sir  阅读(20)  评论(0)    收藏  举报