跳到正文

个人记录

NOI Linux 常用 Bash 指令

xubaichuan约 2 分钟
原文

这是 2026年10月29日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年10月26日
收录
2026年10月29日
更新
2026年11月21日
篇幅
约 2 分钟

版本

  1. v2当前
  2. v1

添加配置:

Bash
cat >> ~/.bashrc << 'EOF'

c() { g++ -std=c++14 -O2 -Wall -Wextra -Wshadow "$1" -o "${1%.cpp}" && ./"${1%.cpp}"; }
d() { g++ -std=c++14 -O1 -Wall -Wextra -Wshadow -fsanitize=address,undefined "$1" -o "${1%.cpp} && ./"${1%.cpp}"; }
EOF

source ~/.bashrc 
export -f c d

查看函数:

Bash
type c d

查看配置:

Bash
nl -ba ~/.bashrc

备份配置:

Bash
cp ~/.bashrc ~/.bashrc.bak

删除配置:

Bash
sed -i "119,120d" ~/.bashrc
unset -f c d

授权:

Bash
chmod +x stress.sh

自动对拍脚本:

Bash
set -e
c generator.cpp
c std.cpp
c sol.cpp
for ((i=1; i<=100000; i++)); do
    ./generator "$i"
    if ! timeout 2s ./std; then
        echo "Test $i: std RE/TLE!"
        exit 1
    fi
    if ! timeout 2s ./sol; then
        echo "Test $i: sol RE/TLE!"
        exit 1
    fi
    if ! diff -w -q .ans .out > /dev/null; then
        echo "Test $i: Wrong Answer!"
        exit 1
    fi
done
echo "Accpet!"