nju-ics2023 PA0

Disk free

show how much disk space Ubuntu occupies

df -h

Shut down

poweroff

Swith user

Sometimes, when we run command like poweroff, it will show permission deny or command not found
then we need to switch user to root to do some operations.

try to switch to root

su root
# or
su -
More info

su - and su root serve the same purpose, which is to switch to the root user's permissions, but they have slight differences in usage:

  1. su -:

    • The su - command switches to the root user and emulates logging into that user's environment. This means it loads the root user's environment variables, working directory, and other settings, making you enter an environment similar to when logging in as the root user.
    • This command can also be used to switch to other users on some systems, not just root, depending on the specified target user.
  2. su root:

    • The su root command directly switches to the root user's permissions but does not emulate logging into the root user's environment. It maintains the current environment, including the current user's working directory and environment variables.
    • This command is typically used when you need superuser permissions without affecting the current environment.

Therefore, su - is more suitable when you need to fully utilize the root user environment, while su root is more suitable when you only need superuser permissions without changing the environment.

Add sudo to user

su -   # we still need to switch to the root account first
adduser username sudo  # change `username` to your user name
exit

Setting APT source file

echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ stable main" > /etc/apt/sources.list

Output the file

cat /etc/apt/sources.list

Updating APT package information

apt-get update

Installing tools for PAs

The following tools are necessary for PAs:

sudo apt-get install build-essential    # build-essential packages, include binary utilities, gcc, make, and so on
sudo apt-get install man                # on-line reference manual
sudo apt-get install gdb                # GNU debugger
sudo apt-get install git                # reversion control system
sudo apt-get install libreadline-dev    # a library to use compile the project later
sudo apt-get install libsdl2-dev        # a library to use compile the project later
sudo apt-get install libc6-dev-i386     # a library to use compile the project later
sudo apt-get install qemu-system        # QEMU

Configuring vim

sudo apt-get install vim
cp /etc/vim/vimrc ~/.vimrc
setlocal noswapfile " 不要生成swap文件
set bufhidden=hide " 当buffer被丢弃的时候隐藏它
colorscheme evening " 设定配色方案
set number " 显示行号
set cursorline " 突出显示当前行
set ruler " 打开状态栏标尺
set shiftwidth=4 " 设定 << 和 >> 命令移动时的宽度为 4
set softtabstop=4 " 使得按退格键时可以一次删掉 4 个空格
set tabstop=4 " 设定 tab 长度为 4
set nobackup " 覆盖文件时不备份
set autochdir " 自动切换当前目录为当前文件所在的目录
set backupcopy=yes " 设置备份时的行为为覆盖
set hlsearch " 搜索时高亮显示被找到的文本
set noerrorbells " 关闭错误信息响铃
set novisualbell " 关闭使用可视响铃代替呼叫
set t_vb= " 置空错误铃声的终端代码
set matchtime=2 " 短暂跳转到匹配括号的时间
set magic " 设置魔术
set smartindent " 开启新行时使用智能自动缩进
set backspace=indent,eol,start " 不设定在插入状态无法用退格键和 Delete 键删除回车符
set cmdheight=1 " 设定命令行的行数为 1
set laststatus=2 " 显示状态栏 (默认值为 1, 无法显示状态栏)
set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ Ln\ %l,\ Col\ %c/%L%) " 设置在状态行显示的信息
set foldenable " 开始折叠
set foldmethod=syntax " 设置语法折叠
set foldcolumn=0 " 设置折叠区域的宽度
setlocal foldlevel=1 " 设置折叠层数为 1
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR> " 用空格键来开关折叠