Views:
122TheHuPost newsletter上线了, 欢迎大家订阅!
对C++, Java,JavaScript,Python等编程语言有兴趣的,也可以看看编程语言。
也欢迎大家来论坛与我讨论
本文总结自己在实际工作中使用比较频繁的linux 命令,主要的环境是 SuSE linux EnterPrise 11 ,加一部分redhat 6.5
Linux 常用命令
远程使用lilnux
ssh ip (使用putty 或者xshell 等工具远程使用linux )
telnet ip ( 使用telnet 方式远程连接linux)
系统信息查看
查看系统cpu 信息
cat /proc/cpuinfo
查询系统内存信息
cat /proc/meminfo
查看系统分区,挂载与磁盘使用情况
df -h
查看硬盘的具体使用情况(分区,格式化,文件系统等)
fdisk -l
查看某个目录下文件目录的大小
du -h
ll 或ls
// 显示当前目录下的文件和子目录,windows下命令为dir
查看ip 和网卡信息
ifconfig
检查和某个ip 网络是否相通
ping ip
目录切换
改变工作目录
cd path // change director ,改变工作目录
显示当前工作目录
pwd //present word director 显示当前工作目录,
返回上级目录
cd .. //.. 表示当前目录的上一级目录
文件查看
静态查看文本文件内容(.xml,.word,.txt,.properties …..)
vi filename // 打开filename 文件
使用vi 查看文件时:
gg 跳到文件最前
GG跳到文件最后
i 进入编辑模式
/ 搜索
ESC : q 退出vi
ESC :wq 保存修改,退出vi
ESC :q! 不保存修改,退出vi
动态查看文件
tail -f filename 将文件刷新的内容实时打印在控制台,windows 下为more
运行监控
CPU, memory 使用情况查询
top //top命令会显示系统的内存,swap 和cpu 的使用情况,和各进程的cpu 占用情况
查询某个进程详细情况
ps -ef|grep key //key 可以是用户,或者是进程名或者是进程名的一部分
查看和某个ip,port 的通信情况
netstat -ano | grep port // 过滤port 相关的通信内容
netstat -ano |grep ip
ln 命令
ln 命令用来建立两个文件之间的链接关系,建立连接之后,一处文件修改,处处都会被修改
eg.
/root/test.xml
/home/test.xml
/opt/test.xml
三个路径都有同样的文件,想做到一个地方修改,其他地方同步修改,则可以建议软链接:
先将/home 和/opt 下的test.xml 删除:
rm /home/test.xml;
rm /opt/test.xml
建立链接:
ln -s /root/test.xml /home/test.xml;
ln -s /root/test.xml /opt/test.xml;
这样建立连接后,可以做到一处修改吗,处处都修改
注:建立软链接时,源文件和目的文件都必须使用绝对路径
which 命令
当我们在linux 下输入命令,bash 提示command not found 时, 需要which 命令来排查
which 命令主要用来检查环境变量中是否有加入相应的命令路径:
which ifconfig
which gcc
which g++
whereis确定linux 系统是否有安装相应软件
whereis ifconfig
whereis gcc
whereis g++
检查系统是否有安装jdk 或者jre
java -version
检查系统是否有安装gcc ,g++
gcc -v
使用gcc 编译c程序
gcc a.c -o a.exe
编译C++ 程序:
g++ a.cpp -o a.exe
运行该程序 ./a.exe
linux上C++可执行文件可以为任何后缀,默认为.exe
g++ 启用C++11:
g++ std=c++11 a.c -o a
过滤命令grep
eg. 从某个文件1.txt中过滤关键词test
grep test 1.txt;
ps -ef|grep test;
tail -f 1.txt |grep test;
挂载和挂载
linux中物理存储和路径是通过挂载(mount) 对应
将/home/test 路径挂载到 sda
mount /dev/sda /home/test
去挂载: umount /home/test
将/home/test 通过NFS挂载到某一网络位置
mount -t nfs 10.10.10.10:/FileSystem /home/test
10.10.10.10:/FileSystem 是一个NFS服务器的共享位置
Original content here is published under these license terms:X
License Type:Read Only
License Abstract:You may read the original content in the context in which it is published (at this web address). No other copying or use is permitted without written agreement from the author.