Linux大牛直呼“内行“

入门1

1.1文件查找

(1)在$HOME目录及其子目录中,查找2天前被更改过的文件

[root@localhost ~]# find /home/ -mtime -2

(2)在/etc/目录下寻找以host开头的文件

[root@localhost ~]# find /etc -name "host*" -print

(3)在/test/下面查找目录文件

[root@localhost ~]# find /test -type d

(4)在/test目录及子目录中,查找超过2KB的文件

[root@localhost ~]# find /test -size -10

打包压缩
(1)将/test目录下的所有文件和文件夹全部压缩成myfile.zip文件

[root@localhost ~]# zip myfile.zip /test
  adding: test/ (stored 0%)

(2)把myfile.zip文件解压到 /opt

[root@localhost ~]# unzip myfile.zip -d /opt
Archive:  myfile.zip
   creating: /opt/test/
[root@localhost ~]# ll /opt
total 4
drwxr-xr-x. 2 root root 4096 Aug  4 17:36 test

(3)将/opt目录下的文件全部打包并用gzip压缩成/test/newfile.tar.gz

[root@localhost test]# tar -czvf newfile.tar.gz /opt
tar: Removing leading `/' from member names
/opt/
/opt/test/

(4)查看/test/newfile.tar.gz文件中有哪些文件?

[root@localhost test]# tar tvf newfile.tar.gz 
drwxr-xr-x root/root         0 2022-08-04 20:20 opt/
drwxr-xr-x root/root         0 2022-08-04 17:36 opt/test/

(5)在/test目录内,备份/etc下的所有文件并保留其权限

[root@192 test]# tar -cvf etc.tar  /etc

1.2 别名修改

1.当前用户永久生效的命令别名

(1)写一个命令命为hello,实现的功能为每输入一次hello命令,就有hello,everyone写入文

件/file.txt中。

[root@192 ~]# echo "alias hello=`echo hello,everyone >> /file.txt`" >> ~/.bashrc
[root@192 ~]# source ~/.bashrc
[root@192 ~]# hello
[root@192 ~]#  cat /file.txt 
hello,everyone

(2)写一个命令别名为shuaxin,实现的功能为每输入一次该命令,file.txt文件的所有时间就更新为当前时间。

[root@192 ~]# echo 'alias shuaxin="touch file.txt"' > ~/.bashrc 
[root@192 ~]# source ~/.bashrc 
[root@192 ~]# shuaxin
[root@192 ~]# stat file.txt 
  File: file.txt
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: 10301h/66305d	Inode: 273698      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2022-08-05 16:48:21.235124296 +0800
Modify: 2022-08-05 16:48:21.235124296 +0800
Change: 2022-08-05 16:48:21.235124296 +0800
 Birth: 2022-08-05 16:15:21.834090851 +0800

2.所有用户生效的命令别名
写一个所有用户都生效的命令别名为hh,每一个用户输入这个命令之后可以在该用户家目录下创建一个file1文件。

[root@192 ~]# vim ~/.bashrc 
alias hh=`touch ~/file$(date "+%F %T")`
[root@192 ~]# source ~/.bashrc
[root@192 ~]# hh
[root@192 ~]# ll
total 48
-rw-r--r--. 1 root root    0 Aug  5 17:42 file2022-08-05


1.3 用户管理

1、新建一个名为sarah的用户,不属于adminuser组,并将其shell设置为不可登陆shell

[root@192 ~]# useradd sarah 
[root@192 ~]# usermod -s /sbin/nologin sarah

2、创建alex用户,使alex用户满足以下要求:用户id为3456,描述名为alian,密码为glegung

[root@192 ~]# useradd  alex -u 3456 -c "alian"

[root@192 ~]# passwd alex glegung

入门2

1、新建目录要求如下:

1)/pub目录为公共存储目录对所有用户可以读,写,执行,但用户只能删除属于自己的文件(t权限)

创建公共目录
[root@192 ~]# mkdir /pub
设置读写执行的权限
[root@192 ~]# chmod  777 /pub
用户之只能删除字段文件
[root@192 ~]# chmod o+t /pub

[root@192 ~]# ll -d /pub
drwxrwxrwt. 2 root root 4096 Aug  5 20:41 /pub


2)/sc目录为生产部存储目录只能对生产部人员可以写入,并且生产部人员该目录所建立的文件都自动归属到shengchan中

创建目录
[root@192 ~]# mkdir  /sc
创建组
[root@192 ~]# groupadd shengchan
更改sc的组
[root@192 ~]# chown :shengchan /sc
2---自动归属到组 7是拥有者 7是组中用户 0其他用户
[root@192 ~]# chmod 2770 /sc

[root@192 ~]# ll -d /sc
drwxrws---. 2 root shengchan 4096 Aug  5 20:43 /sc

3)/cw目录为财务部存储目录只能对财务部人员可以写入并且财务部人员所建立的文件都自动属于caiwu组中

创建目录
[root@192 ~]# mkdir/cw

创建财务组
[root@192 ~]# groupadd caiwu

设置自动归属到财务
[root@192 ~]# chmod 2770 /cw
设置自动归属到财务
[root@192 ~]# chgrp caiwu /cw


4) admin用户对于/sc和/cw目录可以读,写,执行

创建asmin组
[root@192 ~]# useradd admin
设置admin对于/sc和/cw的读写执行
[root@192 ~]# setfacl -m u:admin:rwx /cw  /sc
查看目录权限
[root@192 ~]# getfacl /sc  /cw
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在MATLAB中,可以使用数值计算工具箱中的ode45函数来求解太阳系内行星运动轨迹问题。以下是一个示例代码,可以绘制太阳系内行星的运动轨迹: ```matlab G = 6.674e-11; % 万有引力常数 M = [1.989e30, 3.301e23, 4.869e24, 5.972e24, 6.419e23, 1.899e27, 5.685e26, 8.683e25]; % 太阳、水星、金星、地球、火星、木星、土星、天王星、海王星的质量 r0 = [147e9, 0, 0, 0, -35.98e6, 0, 778.57e9, 0, 0, -227.94e9, 0, 0, 0, 1427.0e9, 0, 0, 0, 4497.1e9, 0, 0]; % 初始位置和速度(假设所有行星在平面上运动,单位是米和米/秒) % 定义ODE f = @(t, r) nbody_ode(t, r, M, G); % 求解ODE [t, y] = ode45(f, [0, 165*365*24*3600], r0); % 绘制轨迹 figure; hold on; colors = ['r', 'b', 'g', 'm', 'c', 'y', 'k', 'r', 'b']; for i = 1:9 plot(y(:, 4*i-3)/1e9, y(:, 4*i-2)/1e9, colors(i)); end axis equal; xlabel('x (10^9 m)'); ylabel('y (10^9 m)'); title('Solar System'); legend('Sun', 'Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune'); ``` 其中,nbody_ode是一个自定义的函数,可以计算所有天体的运动状态。如果你需要使用该代码,可以在同一文件夹下创建一个名为nbody_ode.m的文件,并将以下代码复制到该文件中: ```matlab function drdt = nbody_ode(t, r, M, G) % 计算太阳系内所有天体的运动状态 n = length(M); % 天体数目 drdt = zeros(4*n, 1); % 初始化运动状态 % 计算速度和加速度 v = r(n+1:end); a = zeros(3*n, 1); for i = 1:n for j = 1:n if i ~= j rij = r(4*(j-1)+1:4*(j-1)+3) - r(4*(i-1)+1:4*(i-1)+3); a(3*(i-1)+1:3*i) = a(3*(i-1)+1:3*i) + G*M(j)*rij/norm(rij)^3; end end end % 计算运动状态 drdt(1:n) = v; drdt(n+1:end) = a; end ``` 运行该代码,即可得到太阳系内行星的运动轨迹。你可以根据需要调整初始位置和速度、ODE以及绘图参数。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值