二、翻译缩写
| 序号 | 缩写 | 英文全称 | 中文含义 |
|---|---|---|---|
| 1 | CAD | Computer-Aided Design | 计算机辅助设计 |
| 2 | GNU | GNU's Not Unix | GNU 操作系统(递归缩写) |
| 3 | TCP/IP | Transmission Control Protocol / Internet Protocol | 传输控制协议 / 网际协议 |
| 4 | DNS | Domain Name System | 域名系统 |
| 5 | NFS | Network File System | 网络文件系统 |
| 6 | COVID-19 | Coronavirus Disease 2019 | 2019 冠状病毒病 |
三、解释含义
1. ls -alt -R $LOG | grep ^d 2>> dd
- Field Breakdown:
ls: The command to list directory contents.-alt: A combination of three flags:-a: Show all files (including hidden ones starting with.).-l: Use long listing format (shows permissions, owner, size, etc.).-t: Sort by time (modification time), newest first.
-R: Recursive. Lists subdirectories and their contents as well.$LOG: An environment variable(环境变量) representing a directory path (e.g.,/var/log).|: The pipe operator. It takes the output (stdout) of the command on the left (ls) and feeds it as input to the command on the right (grep).grep: A command used to search text using patterns.^d: A regular expression meaning "starts withd". In anls -llisting, lines starting withdrepresent directories.2>>: Redirects Standard Error (file descriptor 2). The>>means "append" rather than overwrite.dd: The filename where the error messages will be appended.
- Complete Meaning:
- Recursively list all files in the directory path stored in the $LOG variable, showing details (long format) and sorting by modification time. Filter this list to display only the directories. If any errors occur (e.g., permission denied), append those error messages to a file named dd.
2. gcc -c -g -I/include test.c; gcc -o test test.o io.o -lX11
- Part 1:
gcc -c -g -I/include test.cgcc: The GNU C Compiler.-c: Compile and assemble, but do not link. This produces an object file (.o).-g: Generate debugging information (for use with GDB).-I/include: (Uppercasei) Adds/includeto the list of directories to search for header files (.h).test.c: The source code file to be compiled.
- Part 2:
gcc -o test test.o io.o -lX11-o test: Specifies the output filename of the executable (namedtest).test.o io.o: The object files to be linked together.(输入文件)-lX11: (LowercaseL) Tells the linker to link against the library namedX11(usuallylibX11.soorlibX11.a).
第一页:基础编译控制与优化
-c# 只编译,不 Link,产生.o文件-g# 可调试的编译- 默认编译生成的可执行文件是无法使用
gdb来跟踪或调试的,因为可执行程序中没有可供gdb调试使用的特殊信息;为了将必要的调试信息整合到可执行文件中,我们便需要用到-g选项
- 默认编译生成的可执行文件是无法使用
-O?# 进行编译优化,级别越高效果越好,时间越长-O1,-O2,-O3,-Os,-Ofast- 可以选择一级、二级、三级、空间优化、速度优化等
-o output_filename# 指定输出文件名称,默认为a.outgcc -o my_program main.c会生成一个名为my_program的可执行文件
第二页:头文件、宏定义与库链接
-Ipathname# 指定额外的头文件搜索路径- 当你在代码中写
#include "myheader.h"时,编译器默认只在当前目录和系统标准目录(如/usr/include)寻找。 - 如果你的头文件放在一个子文件夹(例如
include/)里,你需要告诉编译器去哪里找。 - 如:
gcc -I./include main.c,就添加了路径
- 当你在代码中写
-Dsymbol# 定义宏symbol,等价于#define symbolgcc -Dsymbol直接跟宏名,相当于定义这个宏,默认这个宏的内容是1gcc -DNAME=value表示定义宏,它的内容是value
-Ldirectory# 指定额外的函数库搜索路径- 含义:添加库文件搜索目录。
- 告诉链接器(Linker)去哪里寻找库文件(
.a静态库或.so动态库)。
-lxyz# 链接时搜索指定具体的函数库- 含义:链接名为
libxyz的库。 - 这是最容易混淆的地方。Linux/Unix 下的库文件通常命名为
lib+名字+.a(或.so)。 - 在使用
-l选项时,你需要去掉前缀lib和后缀.a/.so。 - 示例:如果你要链接数学库
libm.so,你应该用-lm。如果你要链接自己的库libtest.a,你应该用-ltest。 - 如果
-L是指定书架,那么-l就是指定具体的书名。
- 含义:链接名为
- Complete Meaning:
- First, compile test.c into an object file with debug info enabled, looking for header files in the /include directory. Then, link the resulting test.o and another object file io.o with the X11 library to create a final executable program named test.
3. gzip -d sec.zip; tar xvf sec.tar .
- Part 1:
gzip -d sec.zipgzip: The GNU zip compression utility.-d: Decompress.sec.zip: The input file. (Note: Usually gzip files end in.gz, but this command attempts to decompress the file namedsec.zip).
- Part 2:
tar xvf sec.tar .tar: Tape ARchive utility.x: Extract files from an archive.v: Verbose (list files as they are processed).(冗长的)f: Use the file specified next (sec.tar).指定文件名(必须放在最后,后面紧跟文件名)sec.tar: The archive file to extract..: Represents the current directory. (Note: In standardtar, this argument is usually implied as the destination, or it might be interpreting it as a file list. In this context, it implies extracting into the current directory).(一般默认当前文件夹)
- Complete Meaning:
- Decompress the file sec.zip (presumably yielding sec.tar), and then extract the contents of the sec.tar archive into the current directory, listing every file as it is extracted.
4. find . -name X*.h -print 2>/dev/null
- Field Breakdown:
find: The utility used to search for files in a directory hierarchy..: The starting path for the search (the current directory).-name X*.h: The search criteria. Look for filenames starting withXand ending with.h(header files).(通配符,*表示0个1个或多个字符)-print: Explicitly print the matching filenames to Standard Output (stdout).2>/dev/null: Redirect Standard Error (2) to/dev/null./dev/nullis a special "black hole" device; writing to it discards the data.
Wild card(文件名)
?匹配当前位置任意一个字符,即当前位置必须有一个字符(不多不少)ls m?n#m4n, man, m!n
*匹配当前位置任意 0 个或多个字符,即当前位置可以匹配 0 个或多个字符ls *#不是 . 开头的任意文件ls [a-z]*#小写字母开头的任意文件a*匹配:a、ab、abc.txt、a___*.c匹配:main.c、test.c
[abc]#匹配括号内的任意一个字符[a-d]#匹配括号内范围的任意字符[!abc]#匹配任意字符不在封闭集内ls chpt[1-4]#chpt1, chpt2, chpt3, chpt4
{abc,bcd,cde}#匹配任一一组中的任一字符,注意用逗号分隔,花括号展开echo {a,b,c}会展开成:echo a b cls {src,include}/*.h等价于:ls src/*.h include/*.h
~#当前用户的 home 目录~user#指定 user 的 home 目录\#对待下一个字符为纯文本
正则表达式(文件内文本)
元字符:最基础的“代号”
元字符是正则的灵魂,它们不代表字面上的意思,而是代表一种范围或位置。
.(点):匹配除换行符以外的任意单个字符。\d:匹配一个数字(0-9)。\w:匹配一个字母、数字或下划线(单词字符)。\s:匹配一个空白符(空格、制表符等)。[abc]:字符集合。匹配a或b或c中的任意一个。[^abc]:反向集合。匹配除了a、b、c以外的任意字符。
量词:决定“出现几次”
如果你想匹配一串数字,而不是一个数字,就需要量词。
*:出现 0 次或多次(可有可无,无限多也行)。+:出现 1 次或多次(至少得有一个)。?:出现 0 次或 1 次(可选符号)。{n}:精确出现 n 次。{n,m}:出现 n 到 m 次。
举例:
\d{3,4}可以匹配 3 位或 4 位数字。
边界与位置:在哪里匹配
有时候你只想匹配行首或行尾的词。
^:匹配字符串的开始。$:匹配字符串的结束。\b:匹配单词边界(比如匹配 "cat" 但不匹配 "category")。
- Complete Meaning:
- Search the current directory and all subdirectories for files that start with "X" and end with ".h". Print their paths to the screen. If any errors occur (like "Permission denied" when trying to search a protected folder), discard those error messages so they don't clutter the screen.
5. cd; chmod 744 *
- Part 1:
cdcd: Change Directory. When used without arguments, it defaults to the user's Home Directory (~).
- Part 2:
chmod 744 *chmod: Change Mode (modify file permissions).744: The permission bitmask.- 7 (Owner): Read (4) + Write (2) + Execute (1) =
rwx. - 4 (Group): Read (4) only =
r--. - 4 (Others): Read (4) only =
r--.
- 7 (Owner): Read (4) + Write (2) + Execute (1) =
*: Wildcard representing all files in the current directory.
- Complete Meaning:
- Return to the user's home directory. Then, change the permissions of every file in that directory so that the owner has full control (read/write/execute), while the group and everyone else can only read them.
6. export PATH='pwd'/bin:$PATH
- Field Breakdown:
export: Makes the variable available to child processes (sets an environment variable).PATH: The environment variable that tells the shell which directories to search for executable programs.=: Assignment operator.pwd: Command Substitution. The shell runs the commandpwd(Print Working Directory) and replaces this part of the string with the output (the current absolute path)./bin: A string appended to the current path.:: The separator used in the PATH variable to distinguish between different directories.路径分隔符,用于分隔不同的搜索目录。$PATH: The current value of the PATH variable (before this change).
- Complete Meaning:
- Update the system PATH variable by adding a new directory to the beginning of the list. Specifically, it adds the bin subdirectory of the current folder (wherever you are right now) to the search path. This allows you to run scripts located in that specific bin folder from anywhere in the current shell session. | 修改系统的
PATH环境变量。将当前目录下的 bin 子目录添加到系统搜索路径的最前面。这意味着,当你以后输入命令时,系统会优先在这个bin目录中查找,然后再去原来的系统路径中查找。(相当于多加了一个路径)
四、简答题
Describe the functions of df and du, and explain why df is faster than du.
- Functions:
df(Disk Free): Displays the amount of disk space available and used on the file system as a whole (summary of file system usage).du(Disk Usage): Estimates and summarizes the file space usage for specific files or directories (recursively).
- Why is
dffaster?- Mechanism:
dfdoes not traverse the file hierarchy. Instead, it simply reads the Super Block (metadata) of the file system, which keeps a running tally of used/free blocks. dumust perform a recursive traversal (walk) of the directory tree, accessing the inode of every single file to calculate its size. This involves significantly more I/O operations.
- Mechanism:
功能:
df(Disk Free): 用于显示文件系统的整体磁盘空间使用情况(如总容量、已用空间、剩余空间、挂载点等)du(Disk Usage): 用于估算和统计文件或目录所占用的磁盘空间大小。为什么
df比du快?
- 原理不同:
df不需要遍历整个文件系统,它直接读取文件系统的 超级块 (Super Block) 或元数据信息,那里记录了整个分区的块使用统计,所以速度极快。du则需要递归遍历目录树,对每个文件调用stat系统调用来获取大小并累加。当文件数量巨大时,du的 I/O 操作非常频繁,因此速度较慢。
Describe the basic rules of a makefile, explain the relationship between make and makefile, and why touch is often used with make.
- Basic Makefile Rule:
- Makefile
target: Dependencies
[tab] command
- This means: The target depends on the Dependencies If the prerequisites are newer than the target, the command is executed.
- Relationship between
makeandmakefile:makefile: A text configuration file that defines the build rules, dependencies, and commands for the project.make: The command-line utility/tool that reads themakefile, interprets the rules, and executes the necessary commands to build the targets.
- Why use
touchwithmake?makedecides whether to recompile based on file modification timestamps.touchupdates a file's timestamp to the current time. Developers usetouchto "trick"makeinto believing a source file has been modified, forcing a re-compilation of the target without actually changing the code content.
- Target (目标): 你要生成的文件(如
myapp.o或myapp.exe)。- Dependencies (依赖): 生成目标所需的源文件或其他目标(如
myapp.c)。- Commands (命令): 生成目标的 shell 命令(必须以 Tab 键开头)。
make 和 makefile 的关系:
makefile是一个文本配置文件,定义了整个工程的编译规则、依赖关系和构建步骤。make是一个命令工具,它读取makefile中的规则,自动判断哪些文件需要重新编译,并执行相应的命令。为什么 touch 经常与 make 一起使用?
make是基于文件时间戳来判断是否需要重新编译的。- 使用
touch命令可以更新源文件的时间戳(使其变为“最新”)。这样做可以欺骗make工具,强制它认为文件已被修改,从而触发重新编译(Rebuild),而无需实际修改代码内容。
Write the format and function of umask, and explain why there is not a specific file name following "umask".
- Format:
umask [mode](e.g.,umask 022). - Function: Sets the file mode creation mask. It determines the default permissions that are subtracted (masked out) when a new file or directory is created by the process.
- Why no file name?
umaskis a shell built-in command that sets an attribute for the current shell process (and its children).- It applies to all future files created by that process, not to a specific existing file. (To change an existing file's permissions, you would use
chmod).
格式:
umask [模式](例如:umask 022或umask -S)。功能: 设置用户创建文件或目录时的默认权限掩码。它决定了新创建的文件或目录不拥有哪些权限(默认权限减去 umask 值即为最终权限)。
为什么不跟文件名:
umask是一个shell 内建命令,它设置的是当前 Shell 进程(及其子进程)的环境属性,而不是针对某个具体文件的属性。- 它影响的是未来创建的所有文件,而不是现有的文件。修改现有文件权限应使用
chmod。
Briefly describe the composition of a disk and the function of each block (referring to a typical Unix/Minix file system).
A typical Unix file system partition is divided into the following sections:
- Super Block: Describes the state of the file system (e.g., total size, number of inodes, list of free data blocks, block size).
- Inode Blocks (Inode Table): Stores the Inodes (Index Nodes). Each inode contains all metadata for a specific file (permissions, owner, size, timestamps, and pointers to data blocks), but not the filename.
- Data Blocks: The largest area, used to store the actual contents (data) of files.
超级块 (Super Block): 记录整个文件系统的元数据,如文件系统的大小、空闲 inode 数量、空闲数据块数量、块大小等。
Inode 块 / Inode 表 (Inode Table): 存储所有的 inode(索引节点)。每个 inode 记录一个文件的属性(权限、所有者、大小、时间戳)以及指向数据块的指针。
数据块 (Data Block): 占据磁盘最大的空间,用于存储文件实际的内容数据。
How to use a regular expression to match integers from 0 to 255.
You cannot use a simple range like [0-255]. You must break the numbers down by the number of digits.
Regex:
代码段
^([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$
Explanation:
[0-9]: Matches single digits (0-9).[1-9][0-9]: Matches double digits (10-99).1[0-9]{2}: Matches 100-199.2[0-4][0-9]: Matches 200-249.25[0-5]: Matches 250-255.^and$: Anchors to ensure the match covers the whole string.
[0-255] 之所以错误,是因为方括号 [] 在正则表达式中代表 “字符集合” (Character Class),它的规则是:匹配括号内的任意 一个 字符。
下面详细拆解一下 [0-255] 实际上在做什么,以及为什么它无法完成你的任务。
[0-255] 的实际含义
当你写下 [0-255] 时,正则表达式引擎是这样理解的:
0-2:这是一个字符范围,代表字符0、1、2。5:代表字符5。5:再次代表字符5(重复了,会被忽略)。
所以,[0-255] 等同于 [0125]。
它只能匹配单个字符,且这个字符必须是 0、1、2 或 5。
^ and $: Anchors to ensure the match covers the whole string.
如果不加 ^ 和 $ (部分匹配)
这就好比你在人群中找坏人,只要人群里混进去一个坏人,就算抓到了。
- 输入内容:
"Price is 500 dollars" - 正则行为: 扫描整个句子。
- 它看到了
"500"。 - 它发现
"50"是一个合法的 0-255 之间的数字。 - 或者它发现
"0"是一个合法的 0-255 之间的数字。
- 它看到了
- 结果: 匹配成功 (True) ✅。
- 问题: 对于程序验证来说,这是错误的!用户输入的是 500,显然超出了 255 的范围,但因为你只要求“包含合法数字”,所以它通过了。
Explain why various scripting languages were created and are widely used in EDA (Electronic Design Automation).
- Text Processing: EDA workflows generate massive amounts of text data (logs, reports, netlists). Scripting languages (Perl, Python, Awk) excel at string manipulation and Regular Expressions.
- "Glue" Language: EDA flows involve chaining many different tools (from vendors like Synopsys, Cadence). Scripts act as the "glue" to convert formats and pass data between these tools automatically.
- Rapid Development: Scripts are interpreted (no compilation required). This allows engineers to quickly write, test, and modify testbenches or automation flows.
- Tcl Integration: Tcl (Tool Command Language) is the industry standard for interacting with EDA tools. Almost all major EDA tools provide a Tcl shell interface for controlling the design process programmatically.
这个最好和他最后一节课结合起来
中文: EDA 里脚本语言之所以被创造并广泛使用,是因为 EDA 是“多工具、多步骤”的流程,需要把编译/链接/运行/检查/重跑自动串起来,并且尽量“只做必须的最少事情”来保持结果最新(类似 make 按依赖关系决定哪些要重做)。同时 EDA 里有大量文本与规则(HDL、约束、报告、日志),脚本很适合批量处理、提取信息、生成配置;再加上调试与复现很重要,脚本能固定参数与环境、一键重跑与回归测试,所以成了 EDA 的“胶水”和自动化核心。
English (simple words):
Scripting languages are common in EDA because EDA has many tools and many steps. We need a quick way to connect steps like build, run, check, and run again, and only redo what is needed (like make). EDA also has lots of text files and rules (HDL, constraints, reports, logs). Scripts are good at reading, changing, and creating these files. Also, debug and repeat runs are very important, and scripts help keep the same inputs and settings for easy reruns.
Bash Programming: Determine what the command line argument is. If it is a command, print its man page; if it is an ASCII file, print the file content; if neither, give a warning.
Bash
#!/bin/bash
if command -v "$1" &>/dev/null; then
man "$1"
elif [ -f "$1" ] && file "$1" | grep -q "ASCII text"; then
cat "$1"
else
echo "Warning: '$1' is neither a command nor an ASCII file"
fi
五、附加
| Symbol | English Name | Symbol | English Name |
|---|---|---|---|
| ~ | Tilde | ? | Question mark |
| ^ | Caret | / | Slash |
| & | Ampersand | \ | Backslash |
| * | Asterisk | < | Less than |
| () | Parentheses | Square brackets | |
| = | Equal sign | {} | Curly brackets |
| > | Greater than | >> | Double greater than |
| ; | Semicolon | _ | Underscore |
评论区