1 touch命令 :创建不存在文件 or 修改文件时间(文件已经存在)
#cd
#mkdir -p test
#cd test
#touch 1.txt
#ll // 查看文件的最近修改时间
#sleep 30 //休眠30秒
#touch 1.txt
#ll // 可以看到文件的修改时间变化了
2 创建or生成文件的N种方式
2.1 #touch 2.txt //创建空文件
2.2 #cp /proc/cpuinfo 3.txt
2.3 #cat /proc/cpuinfo /proc/meminfo > 4.txt // 拼接
2.4 # echo "hello world !" > 5.txt // echo重定向
# cat 5.txt
# echo “hello world 2” >> 5.txt
# cat 5.txt
3 相对目录与绝对目录
# cd
# mkdir -p quhp // 请改成你自己的简称
# cd /root/quhp
# cp /proc/cpuinfo .
# cp /proc/cpuinfo cpuinfo2
# cp /proc/cpuinfo /root/quhp/cpuinfo3
# cp /proc/cpuinfo ../quhp/cpuinfo4
# mkdir quhp2
# cp /proc/cpuinfo quhp2/
# cd quhp2
# pwd //确认你在哪个目录
# cd //再次确认你在哪个目录
# cd /root/quhp/quhp2
# pwd
# cd ..
# pwd
# cd ..
# pwd
4 umask 003 进行权限的修改,003表示在当前基础上减去该值
默认 文件 -rw-rw-rw-
默认 目录 drwxrwxrwx
#mkdir -p /root/test
#cd /root/test
#umask –S //显示默认权限 u=rwx,g=rx, o=rx
#umask //数字显示 022
#touch 1.txt
#ll 1.txt //可以看到它的权限是 -rw-r--r--, 因为g与o的两个w已经被去掉了
#cd ..
#ll // 可以看到 test 的权限为 drwxr-xr-x
#umask 002
#mkdir -p test2
#ll //test2 的权限为 drwxrwxr-x 比test 多了个w
#cd test2
#touch 2.txt
#ll // 2.txt 的权限为 -rw-rw-r-- 也比 2.txt 多了个w
5 #whereis ls
#locate top // 显示所有文件的绝对路径中有top 字符串的文件
#locate top | less
Od 显示非文本文件
#od -t c /bin/ls
6
#echo $PATH //注意有/root/bin ,实际上这个目录当前还不存在
#cd //回到/root目录
#mkdir bin
#cp /bin/ls bin/lsquhp
#lsquhp // 效果同 ls
#mv bin/lsquhp /home/
#lsquhp //找不到命令
#rm -f /home/lsquhp
6 find
-mtime n :n天之前的一天之内被更改的文件
-mtime +n: n天之前(不含n天本身)被更改的文件
-mtime –n: n天之内(含n天本身)被更改的文件
-newer file: 列出比file 还要新的文件
#find /root -mtime 0 // root 目录下当天修改过的文件
#find /etc -newer /etc/passwd // etc 目录下比 passwd 还要新的文件
7 排序
#cd /root/test
#cat /proc/meminfo /proc/cpuinfo /proc/cpuinfo /proc/meminfo > test.txt
#less test.txt
#sort test.txt > test_sorted.txt //排序
#less test_sorted.txt
#uniq test_sorted.txt > test_uniqed.txt //去冗
#less test_uniqed.txt
一条语句实现以上的功能
#cat /proc/meminfo /proc/cpuinfo /proc/cpuinfo /proc/meminfo | sort | uniq > test2.txt
#less test2.txt
8 比较
#cd /root
#mkdir old
#mkdir new
#cp -a quhp/* old/ //保留原文件属性的前提下复制文件
#cp -a quhp/* new/
#diff old new // 比较两目录
#gvim new/cpuinfo //分别删除某行、增加某新行、修改某行
#diff old/cpuinfo new/cpuinfo //分别确认 上述三个修改操作的 比较结果
#mv new/cpuinfo new/cpuinfo.bak
#diff old new
9 通过ps 与grep 查看现在的活跃进程
#ps aux
#ps aux | less
#ps aux | grep usr // 过滤并显示带有 usr 字符串的行\
#ps aux | grep usr | grep 21 // 再次过滤
思考题:
1 依次将cpuinfo (2遍) 和meminfo(2遍)合并为一个文件 ludong.txt,然后截取其第15行到30行的内容病再次命名为 ludong.txt。
2 请辨别 将目录拷贝 与 目录下内容拷贝的 区别
3 分屏显示命令ls 的帮助文件
4 显示当前同时含有“b”和“v”两个字符的进程
5 给出命令 sort 所在的目录
#cd
#mkdir -p test
#cd test
#touch 1.txt
#ll // 查看文件的最近修改时间
#sleep 30 //休眠30秒
#touch 1.txt
#ll // 可以看到文件的修改时间变化了
2 创建or生成文件的N种方式
2.1 #touch 2.txt //创建空文件
2.2 #cp /proc/cpuinfo 3.txt
2.3 #cat /proc/cpuinfo /proc/meminfo > 4.txt // 拼接
2.4 # echo "hello world !" > 5.txt // echo重定向
# cat 5.txt
# echo “hello world 2” >> 5.txt
# cat 5.txt
3 相对目录与绝对目录
# cd
# mkdir -p quhp // 请改成你自己的简称
# cd /root/quhp
# cp /proc/cpuinfo .
# cp /proc/cpuinfo cpuinfo2
# cp /proc/cpuinfo /root/quhp/cpuinfo3
# cp /proc/cpuinfo ../quhp/cpuinfo4
# mkdir quhp2
# cp /proc/cpuinfo quhp2/
# cd quhp2
# pwd //确认你在哪个目录
# cd //再次确认你在哪个目录
# cd /root/quhp/quhp2
# pwd
# cd ..
# pwd
# cd ..
# pwd
4 umask 003 进行权限的修改,003表示在当前基础上减去该值
默认 文件 -rw-rw-rw-
默认 目录 drwxrwxrwx
#mkdir -p /root/test
#cd /root/test
#umask –S //显示默认权限 u=rwx,g=rx, o=rx
#umask //数字显示 022
#touch 1.txt
#ll 1.txt //可以看到它的权限是 -rw-r--r--, 因为g与o的两个w已经被去掉了
#cd ..
#ll // 可以看到 test 的权限为 drwxr-xr-x
#umask 002
#mkdir -p test2
#ll //test2 的权限为 drwxrwxr-x 比test 多了个w
#cd test2
#touch 2.txt
#ll // 2.txt 的权限为 -rw-rw-r-- 也比 2.txt 多了个w
5 #whereis ls
#locate top // 显示所有文件的绝对路径中有top 字符串的文件
#locate top | less
Od 显示非文本文件
#od -t c /bin/ls
6
#echo $PATH //注意有/root/bin ,实际上这个目录当前还不存在
#cd //回到/root目录
#mkdir bin
#cp /bin/ls bin/lsquhp
#lsquhp // 效果同 ls
#mv bin/lsquhp /home/
#lsquhp //找不到命令
#rm -f /home/lsquhp
6 find
-mtime n :n天之前的一天之内被更改的文件
-mtime +n: n天之前(不含n天本身)被更改的文件
-mtime –n: n天之内(含n天本身)被更改的文件
-newer file: 列出比file 还要新的文件
#find /root -mtime 0 // root 目录下当天修改过的文件
#find /etc -newer /etc/passwd // etc 目录下比 passwd 还要新的文件
7 排序
#cd /root/test
#cat /proc/meminfo /proc/cpuinfo /proc/cpuinfo /proc/meminfo > test.txt
#less test.txt
#sort test.txt > test_sorted.txt //排序
#less test_sorted.txt
#uniq test_sorted.txt > test_uniqed.txt //去冗
#less test_uniqed.txt
一条语句实现以上的功能
#cat /proc/meminfo /proc/cpuinfo /proc/cpuinfo /proc/meminfo | sort | uniq > test2.txt
#less test2.txt
8 比较
#cd /root
#mkdir old
#mkdir new
#cp -a quhp/* old/ //保留原文件属性的前提下复制文件
#cp -a quhp/* new/
#diff old new // 比较两目录
#gvim new/cpuinfo //分别删除某行、增加某新行、修改某行
#diff old/cpuinfo new/cpuinfo //分别确认 上述三个修改操作的 比较结果
#mv new/cpuinfo new/cpuinfo.bak
#diff old new
9 通过ps 与grep 查看现在的活跃进程
#ps aux
#ps aux | less
#ps aux | grep usr // 过滤并显示带有 usr 字符串的行\
#ps aux | grep usr | grep 21 // 再次过滤
思考题:
1 依次将cpuinfo (2遍) 和meminfo(2遍)合并为一个文件 ludong.txt,然后截取其第15行到30行的内容病再次命名为 ludong.txt。
2 请辨别 将目录拷贝 与 目录下内容拷贝的 区别
3 分屏显示命令ls 的帮助文件
4 显示当前同时含有“b”和“v”两个字符的进程
5 给出命令 sort 所在的目录