最基本的是cat、more和less。
1. 如果你只想看文件的前5行,可以使用head命令,如:
head -5 /etc/passwd
2. 如果你想查看文件的后10行,可以使用tail命令,如:
tail -10 /etc/passwd 或 tail -n 10 /etc/passwd
tail -f /var/log/messages
参数-f使tail不停地去读最新的内容,这样有实时监视的效果
用Ctrl+c来终止
3. 查看文件中间一段,你可以使用sed命令,如:
sed -n '5,10p' /etc/passwd
这样你就可以只查看文件的第5行到第10行。
grep -c '^..*$' a.txt 或 grep -v '^$' a.txt | wc -l
文件b.txt,每行以“:”符分成5列,如“1:apple:3:2012-10-25:very good”,如何得到所有行第三列的总合值
awk 'BEGIN {FS=":"; s=0} {s+=$3} END {print s}' b.txt
截取文件c.txt的第60至480行记录,忽略大小写,统计出重复次数最多的那条记录,及重复次数
sed -n '60,480'p c.txt | sort | uniq -i -c | sort -rn | head -n 1
find -type f -size 0 -exec rm -rf {} \;
2.查看进程
按内存从大到小排列
ps -e -o "%C : %p : %z : %a"|sort -k5 -nr
3.按cpu利用率从大到小排列
ps -e -o "%C : %p : %z : %a"|sort -nr
4.打印说cache里的URL
grep -r -a jpg /data/cache/* | strings | grep "http:" | awk -F'http:' '{print "http:"$2;}'
复制代码
5.查看http的并发请求数及其TCP连接状态:
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
复制代码
6.sed -i '/Root/s/no/yes/' /etc/ssh/sshd_config sed在这个文里Root的一行,匹配Root一行,将no替换成yes.
7.1.如何杀掉mysql进程:
ps aux|grep mysql|grep -v grep|awk '{print $2}'|xargs kill -9
复制代码
(从中了解到awk的用途)
pgrep mysql |xargs kill -9
killall -TERM mysqld
kill -9 `cat /usr/local/apache2/logs/httpd.pid`
试试查杀进程PID
8.显示运行3级别开启的服务 :
ls /etc/rc3.d/S* |cut -c 15-
(从中了解到cut的用途,截取数据 )
9.如何在编写SHELL显示多个信息,用EOF
cat << EOF
+--------------------------------------------------------------+
| === Welcome to Tunoff services === |
+--------------------------------------------------------------+
EOF
10. for 的巧用(如给mysql建软链接)
cd /usr/local/mysql/bin
for i in *
do ln /usr/local/mysql/bin/$i /usr/bin/$i
done
11. 取IP地址:
ifconfig eth0|sed -n '2p'|awk '{print $2}'|cut -c 6-30
或者:
ifconfig eth0 |grep "inet addr:" |awk '{print $2}'|cut -c 6-
或者
ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'
或者:
ifconfig eth0 | sed -n '/inet /{s/.*addr://;s/ .*//;p}'
Perl实现获取IP的方法:
ifconfig -a | perl -ne 'if ( m/^\s*inet (?ddr?([\d.]+).*?cast/ ) { print qq($1\n); exit 0; }'
12.内存的大小:
free -m |grep "Mem" | awk '{print $2}'
13.
netstat -an -t | grep ":80" | grep ESTABLISHED | awk '{printf "%s %s\n",$5,$6}' | sort
14.查看Apache的并发请求数及其TCP连接状态:
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
find / -name *.jpg -exec wc -c {} \;|awk '{print $1}'|awk '{a+=$1}END{print a}'
CPU的数量越多,系统 负载越低,每秒能处理的请求数也越多。
//查询deb包的详细信息,没有指定包则显示全部已安装包
dpkg –l
dpkg -l |grep vim
//查看已经安装的指定软件包的详细信息
dpkg -s vim
//列出一个包安装的所有文件清单
dpkg -L vim
//查看系统中的某个文件属于那个软件包
dpkg -S vimrc
//所有deb文件的安装
dpkg -i
//所有deb文件的卸载
dpkg -r
//彻底的卸载,包括软件的配置文件
dpkg -P
//查询deb包文件中所包含的文件
dpkg -c
//查看系统中安装包的的详细清单,同时执行 -c
dpkg -L
相关推荐
Linux Commands
Practical Guide to Linux Commands, Editors, and Shell Programming, A, 4th Edition By Mark G. Sobell, Matthew Helmke Published Nov 9, 2017 by Addison-Wesley Professional. The Most Useful Tutorial and...
Operating System Concepts and Basic Linux Commands 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,...
• Students taking a class in which they use Linux or macOS • Power users who want to explore the power of Linux or macOS from the command line • Professionals who use Linux or macOS at work • ...
一本关于Linux环境下Shell编程的经典书籍
Linux Commands, Editors and Shell Programming Linux Commands, Editors and Shell Programming
A Practical Guide to Linux Commands Editors and Shell Programming 2nd Edition
Practical Guide to Linux Commands, Editors and Shell Programming (2013) “This book is a very useful tool for anyone who wants to ‘look under the hood’ so to speak, and really start putting the ...
Introduction to Linux Commands, such as find,grep, xargs, tar and so on
A Practical Guide to Linux Commands, Editors, and Shell Programming(4th) 英文无水印原版pdf 第4版 pdf所有页面使用FoxitReader、PDF-XChangeViewer、SumatraPDF和Firefox测试都可以打开 本资源转载自网络,...
linux命令行以及shell编程必备书籍,英文通俗易懂,内容翔实
A Practical Guide to Linux Commands, Editors and Shell Programming 4th Edition
为了真正掌握linux必须全面理解shell和命令行。以前,读者必须购买两本书才能掌握这些知识:一本介绍linux基本概念和技术的指南,再加一本参考手册。现在,著名linux专家mark sobell通过《linux命令、编辑器与shell...
整理的非常好,2008年1月6号更新,极力推荐。
前两天在网上找学习Linux命令行的书,突然发现这本,随便看了下介绍觉得不错,就全部打印出来了,一本看下来,觉得真的是收益不少,全英文版,但是难度不大,无论从语言还是从内容来说。可以当做工具书来用。
PRENTICE_HALL-A_Practical_Guide_To_Linux_Commands_Editors_And_Shell_Programming
Linux命令、编辑器和shell编程实用指南,第四版。英文版 Linux命令、编辑器和shell编程实用指南,第四版。英文版 Linux命令、编辑器和shell编程实用指南,第四版。英文版
CHAPTER 1: WELCOME TO LINUX AND MACOS PART I: THE LINUX AND MACOS OPERATING SYSTEMS CHAPTER 2: GETTING STARTED CHAPTER 3: THE UTILITIES CHAPTER 4: THE FILESYSTEM CHAPTER 5: THE SHELL PART II: THE ...