Lab3 Common Commands

Linux

Linux is a family of open-source Unix operating systems based on the Linux Kernel.
There are some popular distributions such as Ubuntu, Fedora, Debian, openSUSE, and Red Hat.

Linux command

A Linux command is a program or utility that runs on the Command Line Interface –
a console that interacts with the system via texts and processes.

Linux command’s general syntax looks like

Pasted image 20241001120159.png

Common commands in Linux(using)

linux commandlink
Pasted image 20241001120705.png

命令 描述
pwd 打印当前工作目录的名称
cd <directory name> 更改当前目录
ls 列出目录的内容
mkdir <directory name> 在任何目录下创建新目录
rmdir <directory name> 删除没有文件的目录
cat <file name> 显示文件的内容
rm <file name> 删除一个文件
cp <source> <dest> 将文件复制到另一个位置
mv <source> <dest> 将文件移动到另一个目录

Absolute path and relative path

Pasted image 20241001121617.png

cd command

Pasted image 20241001121921.png

ls command

Pasted image 20241001122535.png

mkdir command

Pasted image 20241001122844.png

rmdir command

Pasted image 20241001122936.png

rm command

Pasted image 20241001123014.png

cp command and mv command

rename重命名的方法在这里。
Pasted image 20241001123337.png

cat command

Pasted image 20241001123544.png

some other commands

命令 描述
cat/tail/head cat 显示整个文件内容;tail 显示最后几行;head 显示前几行
less/more 分页显示文件内容,less 支持前后滚动,more 只能向前滚动
nano/vim 文本编辑器,nano 简单易用;vim 功能强大,适合编程
file 查看文件类型(文本、可执行文件等)
where 查找可执行文件在系统中的路径
echo 打印文本或变量的值,常用于输出环境变量信息,如 echo $PATH

shortcut keys

Pasted image 20241001212517.png

gcc and g++

其他实验中讲解过 Lab1 environment configuration(done)#compile
Pasted image 20241001213857.png

Pasted image 20241001214702.png

Pasted image 20241001214739.png

Pasted image 20241001214819.png

Exercise

1

Pasted image 20241001124202.png
这个不用了呀。

2

Pasted image 20241001124220.png
答案:
Pasted image 20241001221921.png

3

Pasted image 20241001124230.png
解答:
Pasted image 20241001223027.png
打开之后是一个死循环

原因就是:
Pasted image 20241001223103.png
怎么减都是大于等于0的,因此一直运行。

4

Pasted image 20241001124242.png
解答:
显然n没有变化一直符合condition,因此死循环

5

Pasted image 20241001124252.png
解答:
Pasted image 20241001223731.png
实际上:
Pasted image 20241001223819.png
每次都不一样,都是垃圾数值,声明之后没有初始化变量。