Linux考场用的到的命令&快捷键&对拍
FReQuenter · · 科技·工程
注意 Linux 命令行区分大小写,比如cd Code和Cd Code和cd CODE是不一样的
全局 Ctrl+Shift+? 快捷键总览
Ctrl+Shift+~ VSCode 启动命令行
Ctrl+Alt+T 打开系统命令行
cd xxx 切换到当前目录下的 xxx
cd ~ 回退到用户根目录
cd .. 回退到上一目录
ls 列出当前目录下的文件
pwd 列出当前目录
cp xxx yyy 把 xxx 复制到 yyy 里
g++ test.cpp -o test ... ... 编译指令(注意 -o xxx,xxx 指运行文件,pdf第一页有指令)
./xxx 运行 xxx
./xxx <1.in>1.out 重定向输入输出流
code xxx VSCode 打开 xxx
gedit xxx gedit 打开 xxx
mkdir xxx 新建目录 xxx
bash xxx 运行 shell xxx
#!/bin/bash 告诉系统用 bash 跑(环境变量)
echo xxx 输出 xxx
touch xxx 新建 xxx
cat xxx 输出 xxx
time 输出运行时间(以 user 为准,real 带输入时间)
timeout xxx 运行 xxx 秒后关闭
#xxx 命令行中替换为 xxx(如 #? 获得程序返回值)
对拍小程序(.sh)当然 C++ 写也是可以的:
#!/bin/bash
# 我是注释,上一句话=告诉系统用bash运行
# 命令行 bash xxx.sh 运行
# 编译指令,-fsanitize=address数组越界自动停,undefined就是UB自动停
g++ std.cpp -o std -Wall -Wextra -std=c++17 -D LOCAL -fsanitize=address,undefined
g++ wrong.cpp -o wrong -Wall -Wextra -std=c++17 -D LOCAL -fsanitize=address,undefined
g++ gen.cpp -o gen -Wall -Wextra -std=c++17 -D LOCAL -fsanitize=address,undefined
for T in $(seq 1 100) # for(int T=1;T<=100;T++)
do
echo "========== Test Case $T =========="
./gen > test.in
timeout 1 ./std < test.in > test.ans
timeout 1 ./wrong < test.in > test.out
if [[ $? != 0 ]] # 测试返回值是不是0
then
echo "TLE or RE!"
cp test.in error-$T.in # 把出错的数据拷出去
break
fi # 结束if
diff -q test.ans test.out
if [[ $? != 0 ]]
then
echo "Wrong answer!"
cp test.in error-WA-$T.in # 同上
break
fi
done