1.
tar -czvf etc.tar.gz /etc
tar -xzvf Python-3.6.5.tgz
c: create 压缩
x: extract 解压
2. 源码安装
.c
javascript
java
3. ./configure --prefix=/usr/local/python
--prefix 指定安装路径
/usr/local = c:/program files
4.make
(1)编译所有源文件 .c -> .o
object 目标文件 , 二进制文件
(2)链接 link
.o -> .exe
5. game 博弈
6.GAN 生成对抗网络
7.AlphaGo-zero
AlphaGo
8. AI
https://www.cnblogs.com/yjlch1016/p/9289588.html
9.
find ./ -name "*.c" -exec tar -czvf c.tar.gz {} \;
tar -xzvf c.tar.gz
10.
找到当前目录下的所有c文件,并把这些文件移动到上一级目录
find ./ -name "*.c" -exec mv {} ../ \;
11
文件操作
创建文件: touch cat
拷贝文件: cp
剪切文件: mv 重命名
删除文件: rm
更改权限: chmod
浏览内容: cat
查找内容: grep
查找文件: find
压缩文件: tar
分屏浏览: more
文件夹
创建:mkdir
删除:rm -rf
切换:cd
查看:pwd
更改权限: chmod 三类用户:
例如:user, group, others
755 所有者:可读可写可执行;同组人和其他人:可读可执行
浏览内容: ls
-----------------2019-9-29
liming@126.com
域名 domain name
DNS Domain name server
1. 用户管理
切换用户 su root su: switch user 交换机 router 路由器
添加用户 useradd hacker
删除用户
查看当前用户:whoami
0: root编号 userID UID=0表示root
扩展:
net use h: \\ip\c$ "密码" /user:"用户名" 直接登陆后映射对方C:到本地为H:
2. 添加用户 useradd hacker
(1) cd /home 看一下hacker文件夹 root的home在 /root
(2) cat /etc/passwd
3. 删除用户.
userdel hacker
4. 修改密码
passwd hacker
Task1.
useradd hacker
cd /home
ls
more /etc/passwd % blankspace下一屏, q quit退出
passwd hacker
su hacker
exit
5. sudo
sudo passwd root
6.关机
init 0
init 6
7. x=50
echo $x
PATH 环境变量 Java
(1)
Linux
echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/lab/.local/bin:/home/lab/bin
(2)windows
C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT
8. tail
tail -n 1 /etc/passwd
----------------------------2019-10-8
1 vi 退出
在命令模式下:
Esc
:q
:q!
2. python
quit()
3. vi 输入
i 或者 a,进入输入模式
insert, append
4. 保存退出
vi 1.c
Esc
:x = :wq
5. cat 1.c
6. gcc 1.c -o 1 编译 compile
./1
7. 底行模式
在命令模式下,输入
:
/
8.:n 光标跳转到第n行。
9. 删除
x单个字符
dd 删除一行
10dd 删除10行
恢复 u
10. copy
yy copy
p paste
11. 搜索
/字符串
12. 替换
:s/str1/str2/g 当前行 substitutions
:m,n s/str1/str2/g
13. :set number
14. :m,nw file 保存第m行至第n行到file中。
15. :r file 读取file的内容输出到正文光标所在位置。
16. /usr/bin python
17. 如何安装 opencv cv2
/usr/lib/python2.7/site-packages
18. pip
conda
19. https://blog.csdn.net/qq_41766361/article/details/79504822
------------------2019-10-10
1. script脚本
javascript web
shell Linux
python
Bash
2.
(1) vi e1.sh
(2) echo "hello world"
(3) :x
(4) chmod +x e1.sh
(5) ./e1.sh 或者 bash e1.sh
3. ./
4. 冲击波
5. windows .bat
Linux .sh
6. PATH
Java
C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT
SystemRoot =c:\Windows
Linux PATH
7. echo $PATH
echo $PATH >path.txt %目的是保存当前PATH环境变量
PATH=
ls
?
cd /bin
ls
/bin/ls
PATH=/bin
8. 保存的PATH变量,恢复
cat path.txt
$PATH 读取PATH变量的内容
PATH=`cat path.txt`
9.
x=50
echo x
echo $x
1. PATH
2. echo $PATH>path.txt
PATH=$PATH:/home/lab
echo $PATH
hello
PATH=`/bin/cat path.txt`
hello
3. Linux执行命令
(1)如果PATH环境变量有文件夹,就到这些文件夹依次查找
(2)如果PATH环境变量为空,则在当前文件夹下查找命令
4. x=50
echo x
echo $x
5. x=50
y=30
echo x+y
echo $[x+y]
echo $((x+y))
6. vi 1.sh
echo $0
chmod +x 1.sh
./1.sh
7. $0 就是进程的名字
$1 第一个参数 argument
8. 带参数的main函数 命令行参数
9.
#include <stdio.h>
int main(int argc, char *argv[])
{
int i;
printf("number of arguments: %d\n",argc);
for( i=0;i<argc;i++)
{
printf("current arg is: %s\n",argv[i]);
}
}
echo $#
echo $0
echo $1
echo $2
-----------------2019.10.17
1. 用SHELL编写一个程序,实现以下功能:
拷贝任意指定的文件,如果目地文件夹不指定,则拷贝到默认文件夹:/home/backup;
如果文件夹已指定,则拷贝到指定文件夹
if [ $# -gt 0 ];then
if [ $# -gt 1 ];then
cp $1 $2/
else
cp $1 /home/backup
fi
else
echo "At least one argument"
echo "Example: mycp example.txt"
echo "Example: mycp example.txt d1/"
fi
2. 用SHELL编写一个程序,实现以下功能:
拷贝任意指定的文件,如果指定的不是一个文件,则提示文件找不到,否则
,如果目地文件夹不指定,则拷贝到默认文件夹:/home/backup;
如果文件夹已指定,则拷贝到指定文件夹
3. Task
用SHELL编写一个程序,实现以下功能:
拷贝任意指定的文件,如果指定的不是一个文件,则提示文件找不到,否则
,如果目地文件夹不指定,则拷贝到默认文件夹:/home/backup;
如果文件夹已指定,则拷贝到指定文件夹.如果指定的文件夹不存在,要求创建这个文件夹,之后在拷贝
.mycp 5.txt
if [ $# -gt 0 ];then
if [ -f $1 ];then
if [ $# -gt 1 -a -d $2 ];then
cp $1 $2/
else
cp $1 /home/backup
fi
else
echo "source file not found!"
fi
else
echo "At least one argument"
echo "Example: mycp example.txt"
echo "Example: mycp example.txt d1/"
fi
---------------------------2019.10.23
1. 读入密码,验证是否与程序中密码一致,一致就输出“pass”,否则,输出“Game over”
echo "Please input the password"
read x
if [ $x = "123456" ];then
echo "pass"
else
echo "Game over"
fi
echo "Please input the password"
read x
if test $x = "123456"
then
echo "pass"
else
echo "Game over"
fi
2. 读入密码,验证是否与文件中密码一致,一致就输出“pass”,否则,输出“Game over”
y=`cat passwd`
echo "Please input the password"
read x
if test $x = $y;then
echo "pass"
else
echo "Game over"
fi
3. 显示某个文件指定行
head -n 5 passwd 取前5行
4. 取第5-10行
head -n 10 | tail -n 5
5.
echo "Please input the password"
read x
for i in 1 2 3 4 5 6
do
y=`cat passwd |head -n $i|tail -n 1`
if test $x = $y;then
echo "pass"
else
echo "Game over"
fi
done
6. 文件的行数
cat passwd | wc -l
7.读入密码,验证是否与文件中每行的密码一致,一致就输出“pass”,否则,输出“Game over”
echo "Please input the password"
read x
lineNum=`cat passwd|wc -l`
i=1
while [ $i -le $lineNum ]
do
y=`cat passwd |head -n $i|tail -n 1`
if test $x = $y;then
echo "pass"
else
echo "Game over"
fi
((i+=1))
done
1.ls
2.man ls
manusl cd
3.
ls -a
. hidden files 隐藏文件
4. Task
如何把一个文件夹或者文件设置成别人不可见,你自己可以看到
此电脑->右键->管理->磁盘管理->更改驱动器号
5. ls -a
. 当前目录
.. 父目录
6. cd .. 任何文件夹,即使空,也有 . ..
7. ctrl + shift + "+"
ctrl -
8. ls -l
long
9. q quit 退出
10. ls -l
(1) 第一个字母:
d:directory 文件夹,目录
-:common file
(2)9个字母,3个一组,每组3个,代表权限
===============================================
1.rwxr--r--
chmod 744 list.txt
2.
cd change directory
普通用的home
3.
pwd
touch 1.txt
ls -l
chmod 744 1.txt
ls -l
6.cp
(1) 把一个文件拷贝到另一个地方
cp 1.txt ../
cd ..
ls
将一个文件1.c复制到本地下面的一个文件夹中(本地下面有一个backup文件夹)
cp 1.c ./backup (若在本地下没有backup这个文件夹,系统会自动生成一个文件backup,即将1.c进行复制,并重命名)。
将一个文件1.c 2.c移动到本地下面的一个文件夹中(本地下面有一个backup文件夹
mv 1.c ./backup
(2)把一个文件拷贝成另一个文件(拷贝的过程,重命名)
cp 1.txt 2.txt
(3)把一个文件拷贝另一个地方,并且重命名
cp 1.txt ../2.txt
===============================================
1. cp -r /etc ./
2. \cp -r /etc ./
3. mv 重命名
mv 1.txt 2.txt
cp 1.txt 2.txt
4.
ls
dir
5.
mv
ren
6. rm--remove
rmdir
rm 1.txt
rm -r d1
7. 创建文件夹
mkdir d1
mkdir
mkdir
8. touch 创建文件
touch 修改文件访问时间
9. 文件相关基本:
创建文件、删除、重命名、修改权限、浏览、拷贝
touch rm mv chmod ls cp
10. grep 搜索 (大小写区分 case sensitive)
gedit 1.txt
grep hello 1.txt
11. cat >2.txt 写文件(覆盖式)
Liaocheng nihao
Ctrl+d
12. 浏览文件的内容 读文件
cat 2.txt
13. cat >>2.txt 写文件(追加式)
cin>>a
cout<<"hello 1"
cout<<"hello 2"
14.
以递归的方式查找符合条件的文件。例如,查找指定目录/etc/acpi 及其子目录(如果存在子目录的话)下所有文件中包含字符
grep liaocheng /etc/
cd
------------------------------------/home/lab
cat >1.txt
hello Liaocheng
Ctrl+d
cat >2.txt
nihao Liaocheng
Ctrl+d
mkdir d1
--------------------------------- /home/lab
cd d1
--------------------------------- /home/lab/d1
ls
cp ../*.txt ./ // cp ..是表示回到上个路径 /*.txt表示找txt文件 ./表示当前文件
ls
--------------------------------- /home/lab/d1
cd ..
--------------------------------- /home/lab
rm -f *.txt
grep -r Liaocheng ./d1
15.查找某个文件夹下有没有指定的文件
16. 深度学习 神经网络 多次训练
======================================================
1. 一个文件里面查找符合条件的字符串
grep liaocheng 1.txt
grep -r liaocheng /etc
grep -r liaocheng /
2. Task1
cp -r /etc/ /home/ //本来etc在根目录文件下面,将它copy到/home/下面
cd /home/etc
ls
cat passwd
grep -r root /
3. ls | grep passwd //将在ls的输出里面找到passwd文件 管道的左边输出,右边输入
Task2. 在指定文件夹中搜索有没有某个文件
cp -r /etc/ /home/
cd /home/etc
ls -l |grep passwd
4. | pipeline 管道
cat >1.txt overwrite
cat >>1.txt append
ctrl+D
| 管道的两边有两条命令,左边命令的输出,作为右边命令的输入
ls -l |grep passwd
ls -l >1.txt
grep passwd 1.txt
5. root 根用户 Linux超级用户 == Windows Administrator
Windows:
net user
Windows Administrator
123456
654321
123567
189326
CPU 3GHZ
scan
字典攻击
123LcU478
ping
TTL=64
6.
cd /home/etc
ls -l | grep passwd
find ./ -name passwd
区别:(1)grep只找当前目录有没有这个文件,find命令可以递归查找
7.
find ./ -name "*.c"
pki PKI publice key instructure
8.
find . -type f 普通文件
find . -type d 目录文件
Task 3.
cd
mkdir d1
touch 1.txt 2.txt
mkdir d1
find ./ -type f
find ./ -type d
9.
find . -ctime -20
1. grep
在/etc/passwd文件中搜索有没有 root字符串
grep root /etc/passwd
在/etc文件夹中搜索有没有包含root字符串的文件
grep -r root /etc/
2. find
execute 执行 exe
access 访问
recursive
force
在当前目录下,查找有没有名为1.txt的文件
find ./ -name 1.txt
在/etc文件夹中搜索有没有名为1.txt的文件--包括子文件--递归
find /etc -name 1.txt
在/etc文件夹中搜索有没有满足条件:(1)名字包含.c的文件;(2)在近5天内修改过
find /etc -name *.c -ctime -5
在/etc文件夹中搜索有没有满足条件:(1)名字包含.o的文件;(2)一年内没访问过
find /etc -name *.o -atime +365
360功能文件清理:在/home/文件夹中搜索有没有满足条件:(1)文件大小超过5M;(2)一年内没访问过
cp -r /etc/ /home/
find /home -size +5M -atime +365
在/home/文件夹中搜索有没有满足条件:(1)名字包含.c的文件,找到后删除
cd /home
mkdir tmp
cd tmp
pwd
touch 1.c 2.c 3.c 4.c 5.c
cd ..
find ./ -name *.c
find ./ -name *.c -exec rm -rf {} \;
ls tmp/
find ./ -name *.c
touch 1.c 2.c 3.c 4.c 5.c
cd ..
find ./ -name *.c
find ./ -name *.c -exec rm -rf {} \;
ls tmp/
find ./ -name *.c
在/home/文件夹中搜索有没有满足条件:(1)名字包含.c的文件,找到后备份到/home/backup
cd /home
mkdir backup
cd tmp
touch 1.c 2.c 3.c 4.c 5.c
cd ..
find ./ -name *.c -exec cp -rf {} backup/ \; 2>>errlog.txt
移动到/home/backup find ./ -name *.c -exec mv {} /home/backup/ \;
3. 压缩文件
Windows: winrar, zip,
Linux: tar
ar: archive 档案
tar to archive 归档
c: create, z:zip
tar -czvf file.tar.gz /etc 压缩/etc文件夹下的所有文件生成etc.tar.gz
tar -xzvf etc.tar.gz 解压
4. 在/home/文件夹中搜索有没有满足条件:(1)名字包含.c的文件,找到后备份到/home/backup
cd /home
mkdir backup
cd tmp
touch 1.c 2.c 3.c 4.c 5.c
cd ..
find ./ -name *.c -exec tar -czvf file.tar.gz {} \;
1.
tar -czvf etc.tar.gz /etc
tar -xzvf Python-3.6.5.tgz
c: create 压缩
x: extract 解压
2. 源码安装
.c
javascript
java
3. ./configure --prefix=/usr/local/python
--prefix 指定安装路径
/usr/local = c:/program files
4.make
(1)编译所有源文件 .c -> .o
object 目标文件 , 二进制文件
(2)链接 link
.o -> .exe
5. game 博弈
6.GAN 生成对抗网络
7.AlphaGo-zero
AlphaGo
8. AI
https://www.cnblogs.com/yjlch1016/p/9289588.html
9.
find ./ -name "*.c" -exec tar -czvf c.tar.gz {} \;
tar -xzvf c.tar.gz
10.
找到当前目录下的所有c文件,并把这些文件移动到上一级目录
find ./ -name "*.c" -exec mv {} ../ \;
11
文件操作
创建文件: touch cat
拷贝文件: cp
剪切文件: mv 重命名
删除文件: rm
更改权限: chmod
浏览内容: cat
查找内容: grep
查找文件: find
压缩文件: tar
分屏浏览: more
文件夹
创建:mkdir
mkdir -p 此时若路径中的某些目录尚不存在,加上此选项后,
系统将自动建立好那些尚不存在的目录,即一次可以建立多个目录;
删除:rm -rf
切换:cd
查看:pwd
更改权限: chmod 三类用户:
例如:user, group, others
755 所有者:可读可写可执行;同组人和其他人:可读可执行
浏览内容: ls
-----------------2019-9-29
liming@126.com
域名 domain name
DNS Domain name server
1. 用户管理
切换用户 su root su: switch user 交换机 router 路由器
添加用户 useradd hacker
设置密码 passwd 123
删除用户 userdel zhang
查看当前用户:whoami
0: root编号 userID UID=0表示root
扩展:
net use h: \\ip\c$ "密码" /user:"用户名" 直接登陆后映射对方C:到本地为H:
2. 添加用户 useradd hacker
(1) cd /home 看一下hacker文件夹 root的home在 /root
(2) cat /etc/passwd
3. 删除用户.
userdel hacker
4. 修改密码
passwd hacker
Task1.
useradd hacker
cd /home
ls
more /etc/passwd % blankspace下一屏, q quit退出
passwd hacker
su hacker
exit
5. sudo
sudo passwd root
6.关机
init 0
init 6
7. x=50
echo $x
PATH 环境变量 Java
(1)
Linux
echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/lab/.local/bin:/home/lab/bin
(2)windows
C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT
8. tail
tail -n 1 /etc/passwd
----------------------------2019-10-8
1 vi 退出
在命令模式下:
Esc
:q
:q!
2. python
quit()
3. vi 输入
i 或者 a,进入输入模式
insert, append
4. 保存退出
vi 1.c
Esc
:x = :wq
5. cat 1.c
6. gcc 1.c -o 1 编译 compile
./1
7. 底行模式
在命令模式下,输入
:
/
8.:n 光标跳转到第n行。
9. 删除
x单个字符
dd 删除一行
10dd 删除10行
恢复 u
10. copy
yy copy
p paste
11. 搜索
/字符串
12. 替换
:s/str1/str2/g 当前行 substitutions
:m,n s/str1/str2/g
:1,$ s/word/liaocheng/g 聊城替换所有行中出现的word
13. :set number
14. :m,nw file 保存第m行至第n行到file中。
15. :r file 读取file的内容输出到正文光标所在位置。
16. /usr/bin python
17. 如何安装 opencv cv2
/usr/lib/python2.7/site-packages
18. pip
conda
19. https://blog.csdn.net/qq_41766361/article/details/79504822
------------------2019-10-10
1. script脚本
javascript web
shell Linux
python
Bash
2.
(1) vi e1.sh
(2) echo "hello world"
(3) :x
(4) chmod +x e1.sh
(5) ./e1.sh 或者 bash e1.sh
3. ./
4. 冲击波
5. windows .bat
Linux .sh
6. PATH
Java
C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT
SystemRoot =c:\Windows
Linux PATH
7. echo $PATH
echo $PATH >path.txt %目的是保存当前PATH环境变量
PATH=
ls
?
cd /bin
ls
/bin/ls
PATH=/bin
8. 保存的PATH变量,恢复
cat path.txt
$PATH 读取PATH变量的内容
PATH=`cat path.txt`
9.
x=50
echo x
echo $x
1. PATH
2. echo $PATH>path.txt
PATH=$PATH:/home/lab
echo $PATH
hello
PATH=`/bin/cat path.txt`
hello
3. Linux执行命令
(1)如果PATH环境变量有文件夹,就到这些文件夹依次查找
(2)如果PATH环境变量为空,则在当前文件夹下查找命令
4. x=50
echo x
echo $x
5. x=50
y=30
echo x+y
echo $[x+y]
echo $((x+y))
6. vi 1.sh
echo $0
chmod +x 1.sh
./1.sh
7. $0 就是进程的名字
$1 第一个参数 argument
8. 带参数的main函数 命令行参数
9.
#include <stdio.h>
int main(int argc, char *argv[])
{
int i;
printf("number of arguments: %d\n",argc);
for( i=0;i<argc;i++)
{
printf("current arg is: %s\n",argv[i]);
}
}
echo $#
echo $0
echo $1
echo $2
-----------------2019.10.17
1. 用SHELL编写一个程序,实现以下功能:
拷贝任意指定的文件,如果目地文件夹不指定,则拷贝到默认文件夹:/home/backup;
如果文件夹已指定,则拷贝到指定文件夹
if [ $# -gt 0 ];then
if [ $# -gt 1 ];then
cp $1 $2/
else
cp $1 /home/backup
fi
else
echo "At least one argument"
echo "Example: mycp example.txt"
echo "Example: mycp example.txt d1/"
fi
2. 用SHELL编写一个程序,实现以下功能:
拷贝任意指定的文件,如果指定的不是一个文件,则提示文件找不到,否则
,如果目地文件夹不指定,则拷贝到默认文件夹:/home/backup;
如果文件夹已指定,则拷贝到指定文件夹
3. Task
用SHELL编写一个程序,实现以下功能:
拷贝任意指定的文件,如果指定的不是一个文件,则提示文件找不到,否则
,如果目地文件夹不指定,则拷贝到默认文件夹:/home/backup;
如果文件夹已指定,则拷贝到指定文件夹.如果指定的文件夹不存在,要求创建这个文件夹,之后在拷贝
.mycp 5.txt
if [ $# -gt 0 ];then
if [ -f $1 ];then
if [ $# -gt 1 -a -d $2 ];then
cp $1 $2/
else
cp $1 /home/backup
fi
else
echo "source file not found!"
fi
else
echo "At least one argument"
echo "Example: mycp example.txt"
echo "Example: mycp example.txt d1/"
fi
---------------------------2019.10.23
1. 读入密码,验证是否与程序中密码一致,一致就输出“pass”,否则,输出“Game over”
echo "Please input the password"
read x
if [ $x = "123456" ];then
echo "pass"
else
echo "Game over"
fi
echo "Please input the password"
read x
if test $x = "123456"
then
echo "pass"
else
echo "Game over"
fi
2. 读入密码,验证是否与文件中密码一致,一致就输出“pass”,否则,输出“Game over”
y=`cat passwd`
echo "Please input the password"
read x
if test $x = $y;then
echo "pass"
else
echo "Game over"
fi
3. 显示某个文件指定行
head -n 5 passwd 取前5行
4. 取第5-10行
head -n 10 | tail -n 5
5.
echo "Please input the password"
read x
for i in 1 2 3 4 5 6
do
y=`cat passwd |head -n $i|tail -n 1`
if test $x = $y;then
echo "pass"
else
echo "Game over"
fi
done
6. 文件的行数
cat passwd | wc -l
7.读入密码,验证是否与文件中每行的密码一致,一致就输出“pass”,否则,输出“Game over”
echo "Please input the password"
read x
lineNum=`cat passwd|wc -l`
i=1
while [ $i -le $lineNum ]
do
y=`cat passwd |head -n $i|tail -n 1`
if test $x = $y;then
echo "pass"
else
echo "Game over"
fi
((i+=1))
done
8.读入密码,验证是否与文件中每行的密码一致,一致就输出“pass”停止循环;如果没有的匹配的行,则输出"no match"
echo "Please input the password"
read x
lineNum=`cat passwd|wc -l`
i=1
flag=0
while [ $i -le $lineNum -a $flag -eq 0 ]
do
y=`cat passwd |head -n $i|tail -n 1`
if test $x = $y;then
echo "pass"
flag=1
fi
((i+=1))
done
if [ $flag -eq 0 ];then
echo "no match.."
fi
----------------------2019.10.24
1.
例1.需要完成一个程序,用户输入百分制的分数,之后返回“A”“B”“C”“D”“E”的等级。其中,A等级为90至100分,B等级为80至89分,C等级为70至79分,D等级为60至69分,E等级为0至59分。
flag=0
while [ $flag -eq 0 ]
do
echo "please input a score"
read score
case $score in
9[0-9]|100) echo "A";;
8[0-9]) echo "B";;
7[0-9]) echo "C";;
6[0-9]) echo "D";;
[1-5][0-9]) echo "E";;
[0-9]) echo "E";;
q|quit) flag=1
echo "quit";;
*) echo "wrong input";;
esac
done
2. shell /etc/profile
cp /etc/profile ./
System wide environment and startup programs, for login setup
/etc/profile.d/
/etc/rc.d/
3. umask 002 022
file: 644
dir: 755
002 1
-----------------------
file: 644
dir: 755
022 2
----------------------
umask 022
file 默认权限: 666-umask subnet mask,默认没有可执行权限,为了安全考虑
文件夹默认权限:777-umask
192. 168. 1. 1
255. 255. 255. 0
4.
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
5.编写一个函数,添加文件夹到PATH变量,如果该文件夹已经存在,则输出found it.否则,根据第二个参数决定加到PATH变量的前面还是后面
path1()
{
case ":${PATH}:" in
*:$1:*)
echo "found it" ;;
*)
if [ $2 = "after" ];then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
echo $PATH
esac
}
path1 /home/lab/bin
echo $PATH
==============================================2019.10.19
1. 把PATH环境变量按照分隔符进行分解,输出每个文件夹
old_IFS = $IFS
IFS=':'
for x in $PATH
do
echo $x
done
IFS= $old_IFS
2.
old_IFS = $IFS
IFS=':'
y="root:x:0:0:root:/root:/bin/bash"
for x in $y
do
echo $x
done
IFS= $old_IFS
3.在PATH中添加一个指定的文件夹,如果该文件夹已经在PATH中,则提示"已有";否则,追加到PATH
1:2:3:4 3
old_IFS = $IFS
IFS=':'
flag=1
for x in $PATH
do
if [ $x = $1 ];then
echo "has it"
flag=0
fi
done
IFS= $old_IFS
if [ $flag -eq 1 ];then
PATH=$PATH:$1
echo $PATH
fi
4. /etc/profile
用户主目录下 .bash_profile是当前用户的配置文件
source .bash_profile
5. 安装软件,例如gcc,步骤:
(1)下载.tar.gz
(2)tar xzvf gcc-9.tar.gz
(3)cd gcc-9
(4)./configure --prefix=/usr/local
作用:1. 指定安装目录;2. 生成Makefile文件
(5)make
(6)make install
gcc main.c 1.c 2.c 3.c 4.c 5.c -o main
----------------------------------------------2019.10.31
1. 产生10个随机数,随机范围[0,100)
#include <stdio.h>
#include <time.h>
int main()
{
int a[10];
int i,j,k;
//printf("time... %ld\n",time(0)/(3600*24*12));
//step 1. set the random seed
srand(time(0)); //seed for the random.
//step 2.generate random values, range [0,100)
for(i=0;i<10;i++)
{
int r1=rand()%100; // random number, range in [0,100)
a[i]=r1;
}
//step3. output
for(i=0;i<10;i++)
{
printf("%d \n ",a[i]);
}
printf("\r");
}
2. 文件分解
#include <stdio.h>
2 #include <time.h>
3
4 void seed();
5 void setValues(int a[]);
6 void display(int a[]);
7
8 int main()
9 {
10 int a[10];
11 int i,j,k;
12
13 //printf("time... %ld\n",time(0)/(3600*24*12));
14 //step 1. set the random seed
15 seed();
16 //step 2.generate random values, range [0,100)
17 setValues(a);
18 //step3. output
19 display(a);
20 }
21
22 void seed()
23 {
24 srand(time(0)); //seed for the random.
25 }
26 void setValues(int a[])
27 {
28 int i;
29 //step 2.generate random values, range [0,100)
30 for(i=0;i<10;i++)
31 {
32 int r1=rand()%100; // random number, range in [0,100)
33 a[i]=r1;
34 }
35 }
36 void display(int a[])
37 {
38 int i;
39 //step3. output
40 for(i=0;i<10;i++)
41 {
42 printf("%d \n ",a[i]);
43 }
44 printf("\r");
45
46 }
3. 分解:
main.c seed.c setvalues.c display.c common.h
4,6 w common.h
------------------------------------------main.c
1 #include <stdio.h>
2 #include <time.h>
3
4 int main()
5 {
6 int a[10];
7 //step 1. set the random seed
8 seed();
9 //step 2.generate random values, range [0,100)
10 setValues(a);
11 //step3. output
12 display(a);
13 }
14
-----------------------------------------seed.c
22 void seed()
23 {
24 srand(time(0)); //seed for the random.
25 }
-----------------------------------------setValues.c
26 void setValues(int a[])
27 {
28 int i;
29 //step 2.generate random values, range [0,100)
30 for(i=0;i<10;i++)
31 {
32 int r1=rand()%100; // random number, range in [0,100)
33 a[i]=r1;
34 }
35 }
--------------------------------------------- display.c
36 void display(int a[])
37 {
38 int i;
39 //step3. output
40 for(i=0;i<10;i++)
41 {
42 printf("%d \n ",a[i]);
43 }
44 printf("\r");
45
46 }
--------------------------------------------- common.h
4 void seed();
5 void setValues(int a[]);
6 void display(int a[]);
gcc main.c seed.c setvalues.c display.c -o main
====================================================================2019.11.5
main.c
#include <stdio.h>
#include <time.h>
#include "common.h"
int main()
{
int a[10];
int i,j,k;
//printf("time... %ld\n",time(0)/(3600*24*12));
//step 1. set the random seed
seed();
//step 2.generate random values, range [0,100)
setValues(a);
//step3. output
display(a);
}
--------------------common.h
void seed();
void setValues(int a[]);
void display(int a[]);
---------------------- seed()
void seed()
{
srand(time(0)); //seed for the random.
}
-----------------------------------------setValues.c
void setValues(int a[])
{
int i;
//step 2.generate random values, range [0,100)
for(i=0;i<10;i++)
{
int r1=rand()%100; // random number, range in [0,100)
a[i]=r1;
}
}
--------------------------------------------- display.c
void display(int a[])
{
int i;
//step3. output
for(i=0;i<10;i++)
{
printf("%d \n ",a[i]);
}
printf("\r");
}
2. C 编译,链接
compile link
编译:.c -> .o 二进制文件
链接:.o -> .exe
IDE
3. 增量
4. Makefile
main: main.o display.o setValues.o seed.o
gcc main.o display.o setValues.o seed.o -o main
main.o: main.c
gcc main.c -c
display.o: display.c
gcc display.c -c
setValues.o: setValues.c
gcc setValues.c -c
seed.o: seed.c
gcc seed.c -c
clean:
rm -rf *.o
rm -rf main
-------------------------------------------
1. fork()
pid=fork();
(1)fork函数返回一个大于0的数给父进程,这个大于0的值就等于子进程的PID, process ID
(2)子进程也有变量pid,pid=0
父进程获得了子进程的PID,子进程的pid=0. 子进程可以通过一个函数获得父进程的PID
2. ps -ef
#include <unistd.h>
#include <stdio.h>
int main()
{
pid_t pid;
pid=fork();
if(pid<0)
printf("error\n");
else if(pid==0)
{
printf("child....\n");
printf("my parent PID is ...%d",getppid());
sleep(2);
}
else
{
printf("parent....\n");
printf("my child PID is...%d\n",pid);
sleep(5);
}
}
======================
1. 生成子进程,分别打印自己的PID和父/子进程的PID
#include <stdio.h>
#include <unistd.h>
int main()
{
pid_t pid;
pid=fork();
if(pid<0)
printf("error\n");
if(pid==0)
{
printf("child.... %d \t ",getpid());
printf("parent...%d \n",getppid());
}
if(pid>0)
{
printf("my PID is... %d \t",getpid());
printf("my child... %d \n", pid);
}
}
2. pid变量的值: 对于父进程,pid=子进程的进程号; 对于子进程来说,pid=0
3. daemon 精灵进程,守护进程,孤儿进程
孤儿进程的父进程 PID=1
4. 木马 是一种精灵
杀毒软件是守护进程
5. 如何生成一个孤儿进程?
当父进程提前结束,而子进程还在运行,此时,子进程就成为孤儿进程
#include <stdio.h>
#include <unistd.h>
int main()
{
pid_t pid;
pid=fork();
if(pid<0)
printf("error\n");
if(pid==0)
{
sleep(1);
printf("child.... %d \t ",getpid());
printf("parent...%d \n",getppid());
}
if(pid>0)
{
printf("my PID is... %d \t",getpid());
printf("my child... %d \n", pid);
}
}
--------------------
1. python多进程
https://www.cnblogs.com/caikehe/p/3533413.html
python中fork()函数生成子进程分析
python的os module中有fork()函数用于生成子进程,生成的子进程是父进程的镜像,但是它们有各自的地址空间,子进程复制一份父进程内存给自己,两个进程之 间的执行是相互独立的,其执行顺序可以是不确定的、随机的、不可预测的,这点与多线程的执行顺序相似。
import os
def child():
print 'A new child:', os.getpid()
print 'Parent id is:', os.getppid()
os._exit(0)
def parent():
while True:
newpid=os.fork()
print newpid
if newpid==0:
child()
else:
pids=(os.getpid(),newpid)
print "parent:%d,child:%d"%pids
print "parent parent:",os.getppid()
if raw_input()=='q':
break
parent()
#include <stdio.h>
#include <unistd.h>
int main()
{
pid_t pid;
pid=fork();
if(pid<0)
printf("error\n");
if(pid==0)
{
sleep(1);
printf("child.... %d \t ",getpid());
printf("parent...%d \n",getppid());
}
if(pid>0)
{
printf("my PID is... %d \t",getpid());
printf("my child... %d \n", pid);
}
}
在我们加载了os模块之后,我们parent函数中fork()函数生成了一个子进程,返回值newpid有两个,一个为0,用以表示子进程,一个是大于 0的整数,用以表示父进程,这个常数正是子进程的pid. 通过print语句我们可以清晰看到两个返回值。如果fork()返回值是一个负值,则表明子进程生成不成功(这个简单程序中没有考虑这种情况)。如果 newpid==0,则表明我们进入到了子进程,也就是child()函数中,在子进程中我们输出了自己的id和父进程的id。如果进入了else语句, 则表明newpid>0,我们进入到父进程中,在父进程中os.getpid()得到自己的id,fork()返回值newpid表示了子进程的id,同时我们输出了父进程的父进程的id. 通过实验我们可以看到if和else语句的执行顺序是不确定的,子、父进程的执行顺序由操作系统的调度算法来决定。
2. python 哲学家就餐
https://www.cnblogs.com/nerdlerss/p/10607466.html
#!/usr/bin/env python
#coding:utf-8
import threading
import time
mutex = threading.RLock()
state = [0,0,0,0,0]
rlock0 = threading.RLock()
rlock1 = threading.RLock()
rlock2 = threading.RLock()
rlock3 = threading.RLock()
rlock4 = threading.RLock()
class Phd():
def __init__ (self,key,left,right,lock):
self.key = key
self.left = left
self.right = right
self.lock = lock
z1 = Phd(0,1,4,rlock0)
z2 = Phd(1,0,2,rlock1)
z3 = Phd(2,1,3,rlock2)
z4 = Phd(3,2,4,rlock3)
z5 = Phd(4,3,0,rlock4)
obj_Phd_list = [z1,z2,z3,z4,z5]
inter = 0
def take_forks(zname):
global inter
while 1:
inter += 1
key = zname.key
mutex.acquire()
state[key] = 1
res = test(zname)
mutex.release()
if res == 1:
print ("----",zname.key,"hava eating----")
print ("----" ,zname.key,"put forks")
put_forks(zname)
else:
print("----",zname.key,"no forks")
zname.lock.acquire()
if (inter >= 30):
break
def test(i):
print(i.key,"--in the test")
if (state[i.key] == 1 & state[i.left] !=2 & state[i.right] != 2):
state[i.key] = 2
try:
i.lock.release()
except:
pass
return 1
return 0
def put_forks(i):
mutex.acquire()
state[i.key] = 0
test(obj_Phd_list[i.right])
test(obj_Phd_list[i.left])
mutex.release()
for i in range(5):
s = threading.Thread(target=take_forks,args=(obj_Phd_list[i],))
s.start()
3. python多进程协作
import multiprocessing as mp
def job(q):
res=0
for i in range(1000):
res+=i+i**2+i**3
q.put(res) #queue
if __name__=='__main__':
q = mp.Queue()
p1 = mp.Process(target=job,args=(q,))
p2 = mp.Process(target=job,args=(q,))
p1.start()
p2.start()
p1.join()
p2.join()
res1 = q.get()
res2 = q.get()
print(res1+res2)
4.
--------------------------------------------------------------- 多核多线程 python代码
https://blog.csdn.net/weixin_38611497/article/details/81490960
import multiprocessing as mp
import threading as td
import time
def job(q):
res = 0
for i in range(1000000):
res += i + i**2 + i**3
q.put(res) # queue
def multicore():
q = mp.Queue()
p1 = mp.Process(target=job, args=(q,))
p2 = mp.Process(target=job, args=(q,))
p1.start()
p2.start()
p1.join()
p2.join()
res1 = q.get()
res2 = q.get()
print('multicore:',res1 + res2)
def normal():
res = 0
for _ in range(2):
for i in range(1000000):
res += i + i**2 + i**3
print('normal:', res)
def multithread():
q = mp.Queue() # thread可放入process同样的queue中
t1 = td.Thread(target=job, args=(q,))
t2 = td.Thread(target=job, args=(q,))
t1.start()
t2.start()
t1.join()
t2.join()
res1 = q.get()
res2 = q.get()
print('multithread:', res1 + res2)
if __name__ == '__main__':
st = time.time()
normal()
st1 = time.time()
print('normal time:', st1 - st)
multithread()
st2 = time.time()
print('multithread time:', st2 - st1)
multicore()
print('multicore time:', time.time() - st2)
==================================================== 2019.11.26
1. Python编程实现模拟哲学家就餐的过程
import threading,time
rlock1 = threading.RLock()
rlock2 = threading.RLock()
rlock3 = threading.RLock()
rlock4 = threading.RLock()
rlock5 = threading.RLock()
class Zhexuejia():
def __init__(self,left,right):
self.left = left
self.right = right
z1 = Zhexuejia(rlock5,rlock1)
z2 = Zhexuejia(rlock1,rlock2)
z3 = Zhexuejia(rlock2,rlock3)
z4 = Zhexuejia(rlock3,rlock4)
z5 = Zhexuejia(rlock4,rlock5)
def run(z,name):
f=z.left.acquire()
if f:
print(name,"left")
ff = z.right.acquire()
if ff:
print(name,"right")
print("begin eating",name)
time.sleep(1)
z.right.release()
print(name,"release right...")
z.left.release()
print(name,"release left...")
t1 = threading.Thread(target=run,args=(z1,"z1"))
t2 = threading.Thread(target=run,args=(z2,"z2"))
t3 = threading.Thread(target=run,args=(z3,"z3"))
t4 = threading.Thread(target=run,args=(z4,"z4"))
t5 = threading.Thread(target=run,args=(z5,"z5"))
t1.start()
t2.start()
t3.start()
t4.start()
t5.start()
--------------
2. Linux C实现模拟哲学家就餐的过程
#include "mysemop.h"
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
//(1) 定义两类信号量,一个房间;五支筷子
int root_sem_id = 0;
int chopsticks_sem_id[5];
int main()
{
//(2) pid用于fork函数; chldpid[5]用于保存5个子进程(5个哲学家)的进程号,用于结束这些子进程
pid_t pid;
pid_t chldpid[5];
char ch;
int i = 0;
//(3) 初始化信号量
int room_sem_id = CreateSem(4);
for (i = 0; i < 5; i++) {
chopsticks_sem_id[i] = CreateSem(1);
}
//(4) 初始化信号量
for (i = 0; i < 5; i++) {
pid = fork();
if (pid < 0) {
fprintf(stderr,"When fork philosopher %d Failed!\n", i);
exit(-1);
}
if (pid == 0) {
while (1) {
printf("Philopher %d is thinking,No disterb!\n", i);
sleep(1);
Psem(room_sem_id);
printf("Philopher %d is hungry,so he entered the room.\n", i);
Psem(chopsticks_sem_id[i]);
printf("Philopher %d pick up left chopstick\n", i);
Psem(chopsticks_sem_id[(i + 1) % 5]);
printf("Philopher %d pick up right chopstick\n", i);
printf("Philopher %d begins to eat!\n", i);
sleep(5 - i);
printf("Philopher %d ends to eat!\n", i);
Vsem(chopsticks_sem_id[(i + 1) % 5]);
printf("Philopher %d put down right chopstick\n", i);
Vsem(chopsticks_sem_id[i]);
printf("Philopher %d put down left chopstick\n", i);
Vsem(room_sem_id);
printf("Philopher %d left the room!\n",i);
printf("Philopher %d begins thinking!\n",i);
sleep(1);
}
} else
{
chldpid[i] = pid;
}
}
do
{
ch = getchar();
if (ch == 'q')
{
for (i = 0; i < 5; i++)
kill(chldpid[i], 9);
//kill -9 chldpid[i]
}
} while (ch != 'q');
}
===================================================2019-11-28
1. Windows 实现 360安全卫士
(1)关闭端口
netstat -ano | findstr 8080
tasklist | findstr 2181
taskkill -PID 2188 -F
C++程序实现,(1)基本语法;(2)MFC带界面的编程;(3)STL Standard Template Library
C
#include <stdio.h>
#include <windows.h>
int main()
{
system("netstat -ano | findstr 8080");
}
---------------------------- 9
捕获信号
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
void fx()
{
printf("hello world\n");
}
int main()
{
signal(10,fx);
pause();
}
2.生成子进程,子进程的过程如下:(1)绑定在10号信号,绑定函数是child(); (2)悬挂等待;
父进程:(1)休眠2秒钟;(2)向子进程发送10号信号
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
void child()
{
printf("child....\n");
}
int main()
{
pid_t pid;
pid=fork();
if(pid<0)
printf("error\n");
if(pid==0)
{
signal(10,child);
pause();
}
if(pid>0)
{
sleep(2);
kill(pid,10);
}
}
Linux随堂笔记
猜你喜欢
转载自blog.csdn.net/weixin_43788290/article/details/104827717
今日推荐
周排行