linux 基础命令应用

Linux操作系统
====================
desktop模式
#配置ip,网关#
setup
网络配置--设备配置--DHCP--【*】按空格键改为【 】--在下面配置ip、子网掩码、网关、DNS
=====记得要保存再退出哦!
启动网卡配置文件 ifup eth0
ifconfig 查看ip地址是否配置成功
重启reboot后需要再次启动配置文件 ifup eth0
===============================================================
Linux下删除yunjisuan目录所有文件,但只保留一个“7”不删 【3种方法】
find
find yunjisuan - type "f" !- name "7" | xargs rm -rf
grep
ls | grep -v "7" | xargs rm -rf
嵌套
rm -rf ` ls | grep -v "7"`
===============================================================
已知test文件, 去掉第五行内容后,输出结果 【4种方法】
head/tail
head -4 test && tail -45 test
grep
cat test | grep -v "5"
sed
sed '/5/d' test
awk
awk '!/5/' test
==============================================================
已知yunjisuan目录下已经存在test文件,如何执行命令才能把/yunjisuan/test 复制到/tmp下覆盖掉/yun 155/test ,而让系统不提示是否覆盖
which cp
/bin/cp
/bin/cp /yunjisuan/test /yun155/test
=================================================================
只查看test文件(共100行)内第20行到第30行内容 【3种方法】
head/tail
head -30 test | tail -11 test
sed
sed -n '20,30p' test
awk
awk 'NR>19 && NR<31' test
==================================================================
把www目录及子目录下所有以扩展名.sh结尾的文件,文件中包含yunjisuan的字符串全部替换为welcome
find . -type f -name "*.sh" | xargs sed -i 's#yunjisuan#welcome#g'
==================================================================
########命令考核题#########
mkdir /data
touch /data/yunjisuan.txt
cd yunjisuan
echo "I am studying linux" >> yunjisuan.txt
cp yunjisuan.txt /tmp
mv /data /root
touch yunjisuan{01..04}.txt
cd ~
rm -rf `ls | grep -v "yunjisuan03"`
find . -type f ! -name "yunjisuan03" | xargs rm -rf
ls | grep -v "yunjisuan03" | xargs rm -rf
rm -rf /data
find -type f -name "*.sh" | xargs rm -rf
find -type f -name "*.sh" -exec rm -rf {} \;
find -type d -name "chen*" | xargs -i mv {} /tmp
find -type d -name "chen*" -exec mv {} /tmp \;
find -type f -name "*LOL*" | xargs -i cp {} /mnt
find -type f -name "*LOL*" -exec cp {} /mnt \;
cat yunjisuan.txt | grep -v "I am benet"
head -4 test && tail -6 test
sed '/5/d' yunjisuan.txt
awk '!/5/' yunjisuan.txt
mkdir -p /yunjisuan/test/
head -30 test && tail -11 test
sed -n '20,30p' ett.txt
awk 'NR>19 && NR<30' ett.txt
find /yunjisuan - type f -name "*.sh" | xargs sed -i 's#yunjisuan#welcome#g'
=======================================================================
帮助命令
help
xxxx --help
help xxxx
man
man xxxx
=====================
ls命令
ls 参数
-l 以列表的形式显示
-d 显示目录本身属性
-a显示所有子目录和文件信息
-R以递归的方式显示目录及其子目录中的所有内容
================================
touch命令
touch 文件名
================================
mkdir命令
-p 一次性创建嵌套的多层目录
==================================
cp命令
-f 强制覆盖同名目录,强制复制
-i 提醒用户确认
-p 保持源文件权限属性,不做任何改动
-r 递归复制,针对目录
=============================
rm命令
-f 强制删除
-r 递归
-i 提醒用户确认
=============================
mv命令
==========================
which命令
==========================
find命令
-type
-name
-user
-size G/M/K====+1M 大于1兆
======================
查看文件内容(7种看)
cat
tac
nl
more
less
======================
head
tail
tail -f 看动态更新尾部的信息
===========================
wc
-l 行数
-w单词数
-c字节数
===============================
grep、egrep
-i 查找时忽略大小写
-v 取反
-n 显示行号
-w精确匹配(精确到输入单词无误才显示匹配内容)
-l 过滤时不显示内容,只显示文件
-E 转换成egrep
-o 只显示匹配的内容,其他不匹配的内容不输出
===================================
gzip、bzip2
压缩
gzip 文件名
bzip2 文件名
-------------------------
解压缩
gzip -d 文件名
bzip2 -d 文件名
====================================
tar命令
-cf 打包
-xf 解压
-j(z)表示压缩成解压两种不同的打包格式
-v 显示打包或解压的过程
-C 解压时指定释放的目标目录
=========================================

du  -sh (固定搭配)查看文件或目录大小

posted @ 2018-10-29 17:38  zhoulang6  阅读(155)  评论(0编辑  收藏  举报