linux基本命令操作(二)
· du命令使用:
[root@localhostboot]# du //后没有选项和参数,默认评估当前目录下的所有目录的大小,当然也包括当前目录的大小//
237 ./grub
12 ./lost+found
6555 .
[root@localhostboot]# ls
config-2.6.18-348.el5 initrd-2.6.18-348.el5.img System.map-2.6.18-348.el5
file1.txt] lost+found vmlinuz-2.6.18-348.el5
grub symvers-2.6.18-348.el5.gz
[root@localhostboot]# du -s //-s统计每个参数所占的总空间大小,这里由于没有参数,默认当期目录,即“.”//
6555 .
[root@localhostboot]# du -h //-h 提供易读的容量单位,K或M,同样,这里没有参数对象,默认作用于当期目录下的所有目录,包括本目录//
237K ./grub
12K ./lost+found
6.5M .
[root@localhostboot]# du -sh //-sh,两者合并,用易读的显示方法统计参数的总大小,这里没有参数,默认当前目录//
6.5M .
[root@localhostboot]# du -sh /boot/ //显示根目录下的boot目录的总大小//
6.5M /boot/
[root@localhostboot]# du -sh / //显示根目录的总大小//
2.8G /
[root@localhostboot]# du -sh /etc/ //显示根目录下的etc目录下的总空间大小//
113M /etc/
[root@localhostboot]# du -sh /boot/ /etc/pki/ //可以同时显示多个对象//
6.5M /boot/
792K /etc/pki/
总结:du -sh 多个对象(目录和文件)
· mkdir命令的使用
[root@localhostmnt]# ls
hgfs
[root@localhostmnt]# mkdir 123 //默认直接创建目录123,也可直接指定在其他目录下//
[root@localhostmnt]# ls
123 hgfs
[root@localhostmnt]# mkdir -p 123 //-p递归创建目录//
[root@localhostmnt]# ls
123 hgfs
[root@localhostmnt]#
[root@localhostmnt]# mkdir -p /home/zcy //在/home/下创建zcy,这里也可以不使用-p//
[root@localhostmnt]# ls -R /home/zcy
/home/zcy:
[root@localhostmnt]# ls -R /home
/home:
zcy
/home/zcy:
[root@localhostmnt]# pwd
/mnt
[root@localhostmnt]# mkdir 1406
[root@localhostmnt]# ls
123 1406 hgfs
[root@localhostmnt]# mkdir abc mp4 mp3 //可以同时创建多个目录//
[root@localhostmnt]# ls
123 1406 abc hgfs mp3 mp4
[root@localhostmnt]# mkdir -p aaa/bbb/ccc/ddd //创建递归目录,在当前目录下创建aaa,在aaa下创建bbb,在bbb下创建ccc,在ccc下创建ddd//
[root@localhostmnt]# ls
123 1406 aaa abc hgfs mp3 mp4
[root@localhostmnt]# ls -R aaa
aaa:
bbb
aaa/bbb:
ccc
aaa/bbb/ccc:
ddd
aaa/bbb/ccc/ddd:
[root@localhostmnt]# mkdir -p /test data/mp4 mp3
[root@localhostmnt]# ls
123 1406 aaa abc data hgfs mp3 mp4
[root@localhostmnt]# ls data
Mp4
· cp命令的使用
[root@localhostsbin]# ls /root/Desktop/ //查看Desktop目录,发现什么都没有//
[root@localhostsbin]# cp -rf /boot/grub /etc/host.conf/root/Desktop //将目录grub和文件host.conf复制到Desktop目录下
[root@localhostsbin]# ls /root/Desktop/ //再次查看,复制成功//
grub host.conf
· rm命令的使用:
[root@localhostmnt]# ls
123 1406 aaa abc data file.txt hgfs mp3 mp4
[root@localhostmnt]# touch file //创建空文件file//
[root@localhostmnt]# ls
1406 aaa data file file.txt hgfs mp4
[root@localhostmnt]# rm file //删除file文件//
rm:是否删除一般空文件 “file”? Y //提示是否进行删除,这里选择y,进行删除//
[root@localhostmnt]# ls
1406 aaa data file.txt hgfs mp4 //可以看到该文件已被删除//
[root@localhostmnt]# rm 123 //删除目录123,没有选项,无法删除//
rm: 无法删除目录“123”: 是一个目录
[root@localhostmnt]# rm -r 123 //-r,递归删除整个目录,这时123才会被提示是否要进行删除//
rm:是否删除目录 “123”? y
[root@localhostmnt]# ls
1406 aaa abc data file.txt hgfs mp3 mp4
[root@localhostmnt]# rm aaa
rm: 无法删除目录“aaa”: 是一个目录
[root@localhostmnt]# rm aaa
rm: 无法删除目录“aaa”: 是一个目录
[root@localhostmnt]# rm -r aaa
rm:是否进入目录 “aaa”?n
[root@localhostmnt]# rm -f abc
rm: 无法删除 “abc”: 是一个目录
[root@localhostmnt]# rm -fr abc //-f:force,强制进行删除文件abc,这里-f效能大于自带的-i,因此不会被提示//
[root@localhostmnt]# ls
1406 aaa data file.txt hgfs mp3 mp4
[root@localhostmnt]# alias //查看系统那些命令有“别名”,发现rm相当于rm -i,删除之前会自动提示,这就是为什么之前删除为什么会出现提示的原因//
alias cp='cp -i'
aliasl.='ls -d .* --color=tty'
aliasll='ls -l --color=tty'
aliasls='ls --color=tty'
aliasmv='mv -i'
alias rm='rm -i'
aliaswhich='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@localhostmnt]# \rm -r abc
rm: 无法删除 “abc”: 没有那个文件或目录
[root@localhostmnt]# \rm -r ma3
rm: 无法删除 “ma3”: 没有那个文件或目录
[root@localhostmnt]# \rm -r mp3 //在rm前面添加一个反斜杠“\”,就会使rm -i还原到原来的状态,没有了之前的特异功能,这里就不用再添加选项-f了,他俩功能一样//
[root@localhost~]# cp /etc/passwd . //将根下的etc目录下的passwd文件复制到当前工作目录“.”//
[root@localhost~]# ls
anaconda-ks.cfg Desktop install.log install.log.syslog passwd
· mv命令的使用:
[root@localhostmnt]# ls
123 aaa data file.txt hgfs mp4
[root@localhostmnt]# mv aaa bbb //将aaa文件重命名为bbb//
[root@localhostmnt]# ls
123 bbb data file.txt hgfs mp4
[root@localhostboot]# cd /mnt/
[root@localhostmnt]# ls
123 data file.txt hgfs mp4
[root@localhostmnt]# mv data /home/ //将目录data移动至根下的home目录下//
[root@localhostmnt]# ls
123 file.txt hgfs mp4
[root@localhostmnt]# ls /home/ //查看data的位置,移动成功//
123 aaa ccc data zcy
[root@localhostmnt]# ls /home //已知aaa目录在home目录中//
123 aaa ccc data zcy
[root@localhostmnt]# ls /home /aaa
ls:/aaa: 没有那个文件或目录
/home:
123 aaa ccc data zcy
[root@localhostmnt]# mv /home/aaa /mnt //将根目录下的home目录下的aaa移动至根下的mnt目录//
[root@localhostmnt]# ls //移动成功//
123 aaa file.txt hgfs mp4
[root@localhostmnt]# ls aaa
bbb
[root@localhostmnt]# ls -R aaa
aaa:
bbb
aaa/bbb:
ccc
aaa/bbb/ccc:
ddd
aaa/bbb/ccc/ddd:
[root@localhostsbin]# touch /root/ls-man.txt //在/root/下创建空文件ls-man.txt//
[root@localhost/]# mkdir /root/Desktop //由于先前不小心删掉了/root/Desktop,因此在这里重新创建这个文件夹(目录)//
[root@localhost/]# ls /root/Desktop //查看Desktop文件夹是空的//
[root@localhost/]# mv /root/ls-man.txt/root/Desktop //将创建好的ls-man.txt移动到桌面--不同目录之间进行移动//
[root@localhost/]# ls /root/Desktop //查看桌面内的文件,发现移动成功//
ls-man.txt
[root@localhost/]# mv /root/Desktop/ls-man.txt/root/Desktop/123.txt //将位于同一目录下的文件进行改名//
[root@localhost/]# ls /root/Desktop //查看改名成功//
123.txt
[root@localhost/]# ls /root/ls-man.txt //而/root/下的新建文件ls-man.txt已经消失//
ls:/root/ls-man.txt: 没有那个文件或目录
[root@localhostmnt]# mkdir -p aaa/bbb/ccc //在当前目录下递归创建文件夹(目录)//
[root@localhostmnt]# ls //验证创建成功//
aaa hgfs
[root@localhostmnt]# mv aaa /root //将该目录移动至/root/下//
[root@localhostmnt]# ls //当前目录该目录消失//
hgfs
[root@localhostmnt]# ls /root //验证/root/目录下该目录存在,移动目录成功//
aaa anaconda-ks.cfg Desktop install.log install.log.syslog
小结:mv移动命令无需添加任何选项,即可移动文件和目录,这一点和删除、复制有所区别
· Find查找工具:
[root@localhost~]# find /boot -type l //查找根下boot目录里类型为链接的文件//
/boot/grub/menu.lst
[root@localhost~]# ls -l /boot/grub/menu.lst //使用ls验证是否存在,查找成功//
lrwxrwxrwx1 root root 11 2013-07-10 /boot/grub/menu.lst -> ./grub.conf
[root@localhost~]#
[root@localhost~]# find /boot/ -type d //查找根下boot目录下文件类型为目录的文件//
/boot/
/boot/grub
/boot/lost+found
[root@localhost~]# find /etc -name"resolv*conf" //按名称查找根下etc目录,可以使用通配符,这里查找以resolv开头,以conf结尾的所有文件
/etc/resolv.conf
[root@localhost~]# find /dev -type c -a -name"tty[1-3]" //-a将类型和名称合并起来,必须同时满足这两个条件//
/dev/tty3
/dev/tty2
/dev/tty1
[root@localhost~]# ls -lh /boot/* //以长格式显示根目录下的boot目录下的任何文件的属相和大小//
-rw-r--r--1 root root 67K 2012-11-29/boot/config-2.6.18-348.el5
-rw-r--r--1 root root 0 07-24 16:21 /boot/file1.txt]
......
/boot/grub:
总计 235K
-rw-r--r--1 root root 63 2013-07-10 device.map
-rw-r--r--1 root root 7.5K 2013-07-10 e2fs_stage1_5
-rw-r--r--1 root root 7.3K 2013-07-10 fat_stage1_5
......
/boot/lost+found:
总计 0
[root@localhost~]# find /boot/ -size +2M //在根下boot目录下查找文件大小大于2M的所有文件//
/boot/initrd-2.6.18-348.el5.img
/boot/vmlinuz-2.6.18-348.el5
[root@localhost~]# cp install.log install.new //将本录下的install.log文件仍在本目录下复制并重命名为install.new文件//
[root@localhost~]# ls -lh install.??? //使用ls和通配符验证上述步骤产生的新文件//
-rw-r--r--1 root root 33K 2013-07-10 install.log
-rw-r--r--1 root root 33K 07-25 13:06 install.new
[root@localhost~]# find -name "install.???"-mtime +30 //当没有指定查找范围时,默认查找范围为本目录,mtime这个查找条件,不同于其他条件,可以不需-a就可以附带在其他条件之后,这里是查找以install.为开头的并且是30天前修改或变动的文件,从上面可以看出,install.new刚刚创建,不会显示出来。//
./install.log
[root@localhost~]# find /boot -size +2M
/boot/initrd-2.6.18-348.el5.img
/boot/vmlinuz-2.6.18-348.el5
[root@localhost~]# find /boot/ -size +2M -exec ls -lh{} \; //{}代表find查找出来的结果,并通过-exec后面直接跟的命令对这个结果进行相应的处理//
-rw-------1 root root 2.7M 2013-07-23 /boot/initrd-2.6.18-348.el5.img
-rw-r--r--1 root root 2.1M 2012-11-29 /boot/vmlinuz-2.6.18-348.el5
· locate和updatedb命令:
[root@localhost~]# updatedb //建立定位索引库//
[root@localhost~]# locate shutdown //使用locate定位工具,shutdown为关键字//
/sbin/shutdown
/sys/module/pcmcia_core/parameters/shutdown_delay
/usr/bin/pm-shutdown
/usr/lib/hal/scripts/hal-system-power-shutdown
/usr/lib/hal/scripts/linux/hal-system-power-shutdown-linux
…..
[root@localhost~]# locate shutdown cd ls //可以同时查找多个文件//
[root@localhost~]# ls
aaa anaconda-ks.cfg Desktop f install.log install.log.syslog install.new
[root@localhost~]# touch myhttpd.conf //创建空文件myhttpd.conf//
[root@localhost~]# updatedb //建立定位索引库//
[root@localhost~]# locate myhttpd.conf //locate定位myhttpd.conf文件//
/root/myhttpd.conf
[root@localhost~]# rm myhttpd.conf //删除myhttpd.conf文件,不更新定位索引库//
rm:是否删除一般空文件 “myhttpd.conf”? y
[root@localhost~]# locate myhttpd.conf //再次定位myhttpd.conf文件,发现该文件还存在//
/root/myhttpd.conf
[root@localhost~]# updatedb //使用updatedb再次更新定位库//
[root@localhost~]# locate myhttpd.conf //再次定位myhttpd.conf文件,发现才消失//
· 显示文件内容工具cat、more、less
[root@localhost~]# cat /etc/resolv.conf //cat显示文件内容,适合查看小型文本//
[root@localhost~]# cat -n /etc/resolv.conf //-n number,显示行号//
[root@localhost~]# cat /root/install.log
[root@localhost~]# cat -n /root/install.log //由于/root/install.log文件过大,显示不完全,可以使用行号//
[root@localhost~]# cat -n /etc/passwd
[root@localhost~]# more /root/install.log //more可以全屏分页显示,查看完全//
[root@localhost~]# type ls
[root@localhost~]# ls --help
[root@localhost~]# ls --help | more //利用管道工具“|”对输出信息进行分页显示//
[root@localhost~]# cat /root/install.log | more
[root@localhost~]# more /root/install.log
[root@localhost~]# less /root/install.log //less是more的扩展//
· 显示文件内容的首尾部分head、tail命令的使用:
[root@localhost~]# head /etc/passwd //默认显示内容的前10行//
[root@localhost~]# head -n 2 /etc/passwd //指定显示的前面的行数-n//
[root@localhost~]# tail /var/log/messages //默认显示内容的尾部10行//
[root@localhost~]# tail -n 2 /etc/passwd //指定显示内容的尾部行数-n//
[root@localhost~]# head -n 12 /etc/passwd | tail -n5 //指定显示的中间几行,用套管实现//
[root@localhost~]# touch news.txt
[root@localhost~]# tail -f news.txt //动态观察显示的内容//
切换终端(Ctrl + Shift + t)
[root@localhost~]# echo 111111111 >>news.txt //将内容写入news。txt
[root@localhost~]# echo 222222222 >> news.txt
[root@localhost~]# echo 333333333 >> news.txt
· 文件的字数统计wc命令
[root@localhost~]# wc /etc/passwd //默认统计该文件的-wlc包括行数,字节数和单词数//
[root@localhost~]# wc -l /etc/passwd //统计该文件的行数//
[root@localhost~]# find /etc -name "*.conf"-a -type f | wc -l //在/etc/目录下以.conf结尾的文件查找出来交给wc来完成统计行数//
· 筛选命令grep:
[root@localhost~]# cat /etc/hosts
[root@localhost~]# grep 127.0.0.1 /etc/hosts //在hosts文件中检索出带有“127.0.0.1”的数据//
[root@localhost~]# grep --color 127.0.0.1/etc/hosts //将检索出的“127.0.0.1”附带上颜色输出//
[root@localhost~]# grep -v 127.0.0.1 /etc/hosts //在hosts文件中检索出不含“127.0.0.1”的数据,-v即反向检索的选项//
[root@localhost~]# grep root /etc/passwd
[root@localhost~]# grep Root /etc/passwd
[root@localhost~]# grep -i Root /etc/passwd //-i忽略大小写,即检索时忽略大小写//
[root@localhost~]# dmesg | grep eth //利用dmesg查看启动消息,并进行筛选出有关eth字符的数据//
[root@localhost~]# dmesg | grep sda
[root@localhost~]# grep "^#"/etc/hosts //在hosts文件中检索出以“#”开头的行//
[root@localhost~]# grep -v "^#"/etc/hosts //在hosts文件中检索出除“#”开头的行//
[root@localhost~]# grep "bash$"/etc/passwd //在passwd文件中检索出以“bash”结尾的行//
[root@localhost~]# grep -v "^#"/etc/xinetd.conf | grep -v "^$" //利用套管检索出不以“#”开头的行和空行//
[root@localhost~]# grep -vE "^#|^$"/etc/xinetd.conf //利用选项-E扩展查找模式,检索出不以“#”开头的行和空行//
[root@localhost~]# grep -c "/bin/bash$"/etc/passwd //统计含有"/bin/bash"内容的行数//
[root@localhost~]# grep -E"127.0.0.1|localhost6" /etc/hosts //在hosts文件中检索出存在“127.0.0.1”和“localhost6”的行//
转载于:https://blog.51cto.com/zcyns/1530941
linux基本命令操作(二)相关推荐
- 第二章Linux 基本命令操作
第二章Linux 基本命令操作 本节所讲内容: 2.1 Linux 终端介绍.Shell 提示符.Bash Shell基本语法: 2.2 基本命令操作: 2.3 系统时间管理: 2.4 帮助命令使用: ...
- Linux学习入门级教程:Linux基本命令操作
本人从事IT行业已有十多年,有着丰富的实战经验,总结了大量的学习方法,更是积累了很多的学习资料,很高兴能在这里跟大家交流学习,希望能在这里跟大家共同进步和成长! 更多学习资料添加扣扣资源群:66130 ...
- linux课程--实验二 Linux 基本命令操作2
一.实验目的: (1)掌握文件和目录的区别 (2)熟悉文件和目录的相关操作:建立.复制.移动.删除.重命名.查找.统计等 (3)掌握输入.输出重定向的用法 (4)掌握find的常见查找模式 (5)理解 ...
- Linux FrameBuffer操作(二十七)
所有的这些操作,都是在控制台界面下,root登录. 一.读屏与写屏操作 1.获取一屏的数据 # cat /dev/fb0 > 111.bmp2.将屏幕数据显示 # cat sreensnap & ...
- linux 基本命令初学,Linux基本命令学习二
清除/opt/temp 下,7天之前所有的文件夹 find /opt/temp -mtime +7 -type d -exec rm -rf {} \; linux 开放防火墙端口: 开启防火墙端口: ...
- linux课程--实验一 Linux 基本命令操作1
一.实验目的: (1)掌握Linux各类命令的使用方法. (2)熟悉Linux字符界面操作环境. 二.实验准备 (1)了解Linux命令行的基本概念. (2)自己建立目录结构以及目录下的文件. 三.实 ...
- Linux系统设置共享命令,Linux 基本命令操作 (文件共享) 一
前言:在学习Linux过程中,遇到一些经典而又基本的命令操作,想记录下来去帮助刚学Linux的同学.下面是有关相关的操作,我会进行详细的分解步骤:希望能够帮助到你们.由于时间仓促,再加上笔者的能力有限 ...
- Linux基础操作二
编程语言的作用及与操作系统和硬件的关系 编程语言的作用:用来定义计算机程序的形式,程序员用它来编写程序,进而控制其向计算机发出指令,使计算机完成人类布置的任务. 编程语言的作用及与操作系统和硬件的关系 ...
- linux 基本命令操作su、ls、touch、rm、alias
linux基本操作 命令提示符 1.用户切换 su 2.查看文件信息 ls 3.创建文件touch 4.删除文件rm 5. 关机重启 6.命令别名 alias 7.防火墙 命令提示符 1.用户切换 s ...
- Linux 基本命令(二)--cd 常用命令
2019-07-30 cd 切换到宿主的根目录 [root@localhost var]# pwd /var [root@localhost var]# cd [root@localhost ~ ...
最新文章
- 视频动作识别--Towards Good Practices for Very Deep Two-Stream ConvNets
- 利用尾递归减少栈空间的消耗
- 13KB的代码能做什么?有些人可是弄出了一个完整的游戏!
- redis持久化实现原理
- pytorch:ResNet50做新冠肺炎CT照片是否确诊分类
- python 苹果id申请_如何申请百度机器翻译API的ID和Key,为Python调用做准备
- 如何在阿里云•对象存储OSS托管用户域名的https证书
- 【bzoj2759】一个动态树好题
- 阿里云IoT安全运营中心-Link SOC,安全运营托管功能发布
- 润乾集算报表实现多数据集关联的示例
- FFMPEG详解(完整版)
- Python语言程序设计基础_实验3 流程控制I_答案_通识教育必修课程_上海师范大学
- vulcan 编程_我如何在四天内使用Vulcan.js构建应用程序
- FT5316调试记录
- 【HomeAssistant接入的设备实现天猫精灵】
- 关于单片机对三极管B值测量的硬件电路和软件思路分享
- Android UUID主键生成器
- AIDA64烤机温度正常是多少 AIDA64烤机结果怎么看
- Excel技巧——快捷键的使用
- Camera镜像上下左右颠倒问题的解决办法