2023.7.3(Linux)

在Linux中/被称为路径分隔符,最开始的/被称为根目录

/home 家目录  普通用户默认在家目录下

相对路径与绝对路径

相对路径
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ ./test
hello Linux
绝对路径
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ /home/ycc/lesson/test
hello Linux

在Linux下执行一个程序,必须找到相应程序的二进制文件

三大重定向

输出,追加,输入

[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ echo "hello world" > log.txt
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ cat log.txt
hello world
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ echo "hello world" >> log.txt
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ cat log.txt
hello world
hello world
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ cat < log.txt
hello world
hello world

echo后面跟的是字符串

cat后面跟的是文件名

uname -r 显示内核版本信息

Liunx指令就是一个个二进制文件,在/usr/bin目录下

粘滞位

在一个多人共享的目录中,如果你有w权限,你就可以任意删除别人的文件,为了避免这种情况

chmod +t 文件名   x权限变为t,这样你就无法删除别人的文件4

yum

应用商城

yum源

[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ ls /etc/yum.repos.d
CentOS-Base.repo  epel.repo  epel.repo.rpmnew  epel-testing.repo

make和m(M)akefile

make是一个指令

Makefile是一个当前目录下的文件。(首字母大小写均可)

比如打电话时,你要先说你是谁(依赖关系),再表明你要做什么(依赖方法)。

依赖关系

依赖方法(必须以Tab键开头)

makefile基于依赖关系的自动化推导

这里是复杂一点的编译过程,递归往下走,直到找到有存在的文件形成依赖关系

test:test.o
  2   gcc $^ -o $@                                                                                              
  3 test.o:test.s
  4   gcc -c $^ -o $@ 
  5 test.s:test.i
  6   gcc -S $^ -o $@ 
  7 test.i:test.c
  8   gcc -E $^ -o $@
  9 
 10 clean:
 11   rm -rf test.i test.s test.o test
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ make clean
rm -rf test.i test.s test.o test
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ vim makefile
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ make clean
rm -rf test.i test.s test.o test
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ make
gcc -E test.c -o test.i
gcc -S test.i -o test.s 
gcc -c test.s -o test.o 
gcc test.o -o test
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ ./test
hello Linux
哪怕你在Makefile文件当中,依赖关系是乱序的,它也不受影响

就像函数放在什么位置不重要,重要的是能够找到就行

make默认

make不加目标文件通常默认为第一个

make clean指定目标文件

make会自顶向下扫描Makefile

为什么make了一次以后,不改动的情况下,就不允许make编译了呢?

[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ make clean
rm -rf test.i test.s test.o test
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ make
gcc -E test.c -o test.i
gcc -S test.i -o test.s 
gcc -c test.s -o test.o 
gcc test.o -o test
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ make
make: `test' is up to date.
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ make
make: `test' is up to date.
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ make
make: `test' is up to date.

因为没必要,为了提高你的编译效率,但是问题是它是怎么做到的

make会根据源文件和目标文件的新旧,判定是否需要重新执行依赖关系进行编译!

因此导致我们的make命令不一定总是执行的

将时间转换成时间戳,按时间戳的大小进行比较,看谁新谁旧

一般都是比较Modify

stat(查看源文件和可执行程序的时间问题)

ACM
Access:最近访问时间(你对该文件的任何操作几乎都会修改它)

但是当一个多人协做的文件,过于频繁的修改,会影响linux系统整机效率提高,所以设计了只有当Modify和Change修改了一定次数后,才会更改

文件=内容+属性

Modify:对文件内容做修改
Change:对文件属性做修改

不过文件内容改了,文件属性也势必会改

ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ stat test.c
  File: ‘test.c’
  Size: 74        	Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d	Inode: 1316923     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/     ycc)   Gid: ( 1000/     ycc)
Access: 2023-07-11 13:48:49.343107468 +0800
Modify: 2023-07-06 15:14:05.891370122 +0800
Change: 2023-07-06 15:14:05.891370122 +0800
 Birth: -
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ vim test.c
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ stat test.c
  File: ‘test.c’
  Size: 317       	Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d	Inode: 1316923     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/     ycc)   Gid: ( 1000/     ycc)
Access: 2023-07-11 13:48:49.343107468 +0800
Modify: 2023-07-11 14:17:10.839040434 +0800
Change: 2023-07-11 14:17:10.839040434 +0800
 Birth: -
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ chmod g-w test.c
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ stat test.c
  File: ‘test.c’
  Size: 317       	Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d	Inode: 1316923     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/     ycc)   Gid: ( 1000/     ycc)
Access: 2023-07-11 13:48:49.343107468 +0800
Modify: 2023-07-11 14:17:10.839040434 +0800
Change: 2023-07-11 14:18:30.472407336 +0800
 Birth: -

touch 命令更改时间

touch跟文件名,没有这个文件直接创建一个新文件

这个文件已经存在,就把它的三个时间全部更新

[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ stat test.c
  File: ‘test.c’
  Size: 317       	Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d	Inode: 1316923     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/     ycc)   Gid: ( 1000/     ycc)
Access: 2023-07-11 13:48:49.343107468 +0800
Modify: 2023-07-11 14:17:10.839040434 +0800
Change: 2023-07-11 14:18:30.472407336 +0800
 Birth: -
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ touch test.c
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ stat test.c
  File: ‘test.c’
  Size: 317       	Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d	Inode: 1316923     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/     ycc)   Gid: ( 1000/     ycc)
Access: 2023-07-12 13:51:33.670246049 +0800
Modify: 2023-07-12 13:51:33.670246049 +0800
Change: 2023-07-12 13:51:33.670246049 +0800
 Birth: -

加 -a修改access和change,加-c全部修改,加-m修改modify和change

如果我们想总是编译,又应该怎么办?

.PHONY: +目标文件(总是被执行)

.PHONY:修饰的目标,我们称之为伪目标

伪目标对应的依赖方式和依赖方法总是被执行

.PHONY:test

 test:test.c
     gcc $^ -o $@
   
 clean:
     rm -rf test         
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ vim makefile
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ make clean
rm -rf test
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ make
gcc test.c -o test
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ make
gcc test.c -o test
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ make
gcc test.c -o test

但是并不建议用.PHONY来修饰目标文件,因为不同的编译器可能会将之前的源文件重新编译,造成相同的问题。

.PHONY用来修饰clean

.PHONY:clean

特殊符号

$^代表左边的依赖文件,$@代表生成的目标文件



 test:test.c
     gcc $^ -o $@

.PHONY:clean
   
 clean:
     rm -rf test    

不在命令行中显示依赖方法

test:test.c                                                                                                 
  @gcc $^ -o $@
                
.PHONY:clean
clean:      
  @rm -rf test
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ make
[ycc@iZbp1czm5p4go6poel4l8tZ lesson]$ make clean

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值