栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

5.19 作业 基于linux的基本操作

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

5.19 作业 基于linux的基本操作

1 在当前目录下建立文件aaa.txt,将文件aaa.txt拷贝到/tmp这个目录下,并改名为 bbb.txt

[root@192 ~]# ls
anaconda-ks.cfg  Documents  Hello.java  original-ks.cfg  Public     tmp
Desktop          Downloads  Music       Pictures         Templates  Videos
[root@192 ~]# touch aaa.txt
[root@192 ~]# cp aaa.txt tmp/
[root@192 ~]# ls
aaa.txt          Documents   Music            Public     Videos
anaconda-ks.cfg  Downloads   original-ks.cfg  Templates
Desktop          Hello.java  Pictures         tmp
[root@192 ~]# ls tmp/
aaa.txt
[root@192 ~]# cd tmp/
[root@192 tmp]# mv aaa.txt bbb.txt
[root@192 tmp]# ls
bbb.txt


2 在任何目录下回到用户主目录(家)

[root@192 tmp]# pwd
/root/tmp 
[root@192 tmp]# cd
[root@192 ~]# pwd
/root


3 打印当前目录(隐藏文件也显示)

[root@192 ~]# ls
aaa.txt          Documents   Music            Public     Videos
anaconda-ks.cfg  Downloads   original-ks.cfg  Templates
Desktop          Hello.java  Pictures         tmp
[root@192 ~]# ls -l       list-list 详细信息
total 8
-rw-r--r--. 1 root root    0 May 19 07:31 aaa.txt
-rw-------. 1 root root 2757 May 18 23:15 anaconda-ks.cfg
drwxr-xr-x. 2 root root   33 May 19 06:14 Desktop
drwxr-xr-x. 2 root root    6 May 18 23:53 Documents
drwxr-xr-x. 2 root root    6 May 18 23:53 Downloads
-rw-r--r--. 1 root root    0 May 19 02:11 Hello.java
drwxr-xr-x. 2 root root    6 May 18 23:53 Music
-rw-------. 1 root root 2037 May 18 23:15 original-ks.cfg
drwxr-xr-x. 2 root root    6 May 18 23:53 Pictures
drwxr-xr-x. 2 root root    6 May 18 23:53 Public
drwxr-xr-x. 2 root root    6 May 18 23:53 Templates
drwxr-xr-x. 2 root root   21 May 19 07:38 tmp
drwxr-xr-x. 2 root root    6 May 18 23:53 Videos
[root@192 ~]# ls -a            显示全部文件 包含隐藏文件
.                .a.txt.swp     .cshrc      .hello.java.swp  .tcshrc
..               .bash_history  .dbus       .ICEauthority    Templates
aaa.txt          .bash_logout   Desktop     .local           tmp
anaconda-ks.cfg  .bash_profile  Documents   Music            Videos
.a.txt.swn       .bashrc        Downloads   original-ks.cfg  .viminfo
.a.txt.swo       .cache         .esd_auth   Pictures
.a.txt].swo      .config        Hello.java  Public
[root@192 ~]# 


4 创建5个文件分别是 1.txt 2.txt 3.txt 4.txt 5.txt,压缩这5个文件,压缩包的名字是my.tar

[root@192 ~]# touch 1.txt
[root@192 ~]# touch 2.txt
[root@192 ~]# touch 3.txt
[root@192 ~]# touch 4.txt
[root@192 ~]# touch 5.txt
[root@192 ~]# ls
1.txt  5.txt            b.txt      Downloads        Pictures   Videos
2.txt  aaa.txt          c.txt      Hello.java       Public
3.txt  anaconda-ks.cfg  Desktop    Music            Templates
4.txt  a.txt            Documents  original-ks.cfg  tmp
[root@192 ~]# tar zcvf my.tar 1.txt 2.txt 3.txt 4.txt 5.txt
1.txt
2.txt
3.txt
4.txt
5.txt
[root@192 ~]# ls
1.txt  5.txt            b.txt      Downloads   original-ks.cfg  tmp
2.txt  aaa.txt          c.txt      Hello.java  Pictures         Videos
3.txt  anaconda-ks.cfg  Desktop    Music       Public
4.txt  a.txt            Documents  my.tar      Templates
[root@192 ~]# 


5 查看文件最后10行

[root@192 ~]# ls
1.txt  5.txt            b.txt      Downloads   original-ks.cfg  tmp
2.txt  aaa.txt          c.txt      Hello.java  Pictures         Videos
3.txt  anaconda-ks.cfg  Desktop    Music       Public
4.txt  a.txt            Documents  my.tar      Templates
[root@192 ~]# vim 1.txt
[root@192 ~]# tail -n 1.txt
tail: 1.txt: invalid number of lines
[root@192 ~]# tail -10 1.txt
f
m
c 
cv
n
dcv
 c
 dgs
c
sdgdsg
[root@192 ~]# 


6 将指定文件中所有的a ,替换成b

进入vim后  使用
 %s /源字符串/目标字符串   (不加g只替换每一行开头的第一个字符)
:%s /源字符串/目标字符串/g 替换每一行中的所有源字符串的字符

[root@192 ~]# vim 1.txt
[root@192 ~]# more 1.txt
jhsmdgfaaaa
asgaaaaa
asafadaaadg
agsfdfsf
afadsfa
ASAGA
asfa
AAAAAAAAAAAA
aaasfagsdada
aaaaaaaaaaaa

[root@192 ~]# vim 1.txt
[root@192 ~]# more 1.txt
jhsmdgfbbbb
bsgbbbbb
bsbfbdbbbdg
bgsfdfsf
bfbdsfb
ASAGA
bsfb
AAAAAAAAAAAA
bbbsfbgsdbdb
bbbbbbbbbbbb

[root@192 ~]# 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/919460.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号