Linux中常用操作命令

Miracle 2017年9月19日19:56:29IT相关Linux中常用操作命令已关闭评论2,01133171字阅读10分34秒阅读模式

转自网页文章源自联网快讯-https://x1995.cn/1455.html

常用指令文章源自联网快讯-https://x1995.cn/1455.html

ls          显示文件或目录文章源自联网快讯-https://x1995.cn/1455.html

-l           列出文件详细信息l(list)文章源自联网快讯-https://x1995.cn/1455.html

-a          列出当前目录下所有文件及目录,包括隐藏的a(all)文章源自联网快讯-https://x1995.cn/1455.html

mkdir         创建目录文章源自联网快讯-https://x1995.cn/1455.html

-p           创建目录,若无父目录,则创建p(parent)文章源自联网快讯-https://x1995.cn/1455.html

cd               切换目录文章源自联网快讯-https://x1995.cn/1455.html

touch          创建空文件文章源自联网快讯-https://x1995.cn/1455.html

echo            创建带有内容的文件。文章源自联网快讯-https://x1995.cn/1455.html

cat              查看文件内容文章源自联网快讯-https://x1995.cn/1455.html

cp                拷贝文章源自联网快讯-https://x1995.cn/1455.html

mv               移动或重命名文章源自联网快讯-https://x1995.cn/1455.html

rm               删除文件文章源自联网快讯-https://x1995.cn/1455.html

-r            递归删除,可删除子目录及文件文章源自联网快讯-https://x1995.cn/1455.html

-f            强制删除文章源自联网快讯-https://x1995.cn/1455.html

find              在文件系统中搜索某文件文章源自联网快讯-https://x1995.cn/1455.html

wc                统计文本中行数、字数、字符数文章源自联网快讯-https://x1995.cn/1455.html

grep             在文本文件中查找某个字符串文章源自联网快讯-https://x1995.cn/1455.html

rmdir           删除空目录文章源自联网快讯-https://x1995.cn/1455.html

tree             树形结构显示目录,需要安装tree包文章源自联网快讯-https://x1995.cn/1455.html

pwd              显示当前目录文章源自联网快讯-https://x1995.cn/1455.html

ln                  创建链接文件文章源自联网快讯-https://x1995.cn/1455.html

more、less  分页显示文本文件内容文章源自联网快讯-https://x1995.cn/1455.html

head、tail    显示文件头、尾内容文章源自联网快讯-https://x1995.cn/1455.html

ctrl+alt+F1  命令行全屏模式文章源自联网快讯-https://x1995.cn/1455.html

 文章源自联网快讯-https://x1995.cn/1455.html

系统管理命令文章源自联网快讯-https://x1995.cn/1455.html

stat              显示指定文件的详细信息,比ls更详细文章源自联网快讯-https://x1995.cn/1455.html

who               显示在线登陆用户文章源自联网快讯-https://x1995.cn/1455.html

whoami          显示当前操作用户文章源自联网快讯-https://x1995.cn/1455.html

hostname      显示主机名文章源自联网快讯-https://x1995.cn/1455.html

uname           显示系统信息文章源自联网快讯-https://x1995.cn/1455.html

top                动态显示当前耗费资源最多进程信息文章源自联网快讯-https://x1995.cn/1455.html

ps                  显示瞬间进程状态 ps -aux文章源自联网快讯-https://x1995.cn/1455.html

du                  查看目录大小 du -h /home带有单位显示目录信息文章源自联网快讯-https://x1995.cn/1455.html

df                  查看磁盘大小 df -h 带有单位显示磁盘信息文章源自联网快讯-https://x1995.cn/1455.html

ifconfig          查看网络情况文章源自联网快讯-https://x1995.cn/1455.html

ping                测试网络连通文章源自联网快讯-https://x1995.cn/1455.html

netstat          显示网络状态信息文章源自联网快讯-https://x1995.cn/1455.html

man                命令不会用了,找男人  如:man ls文章源自联网快讯-https://x1995.cn/1455.html

clear              清屏文章源自联网快讯-https://x1995.cn/1455.html

alias               对命令重命名 如:alias showmeit="ps -aux" ,另外解除使用unaliax showmeit文章源自联网快讯-https://x1995.cn/1455.html

kill                 杀死进程,可以先用ps 或 top命令查看进程的id,然后再用kill命令杀死进程。文章源自联网快讯-https://x1995.cn/1455.html

 文章源自联网快讯-https://x1995.cn/1455.html

打包压缩相关命令文章源自联网快讯-https://x1995.cn/1455.html

gzip文章源自联网快讯-https://x1995.cn/1455.html

bzip2:文章源自联网快讯-https://x1995.cn/1455.html

tar:                打包压缩文章源自联网快讯-https://x1995.cn/1455.html

-c              归档文件文章源自联网快讯-https://x1995.cn/1455.html

-x              压缩文件文章源自联网快讯-https://x1995.cn/1455.html

-z              gzip压缩文件文章源自联网快讯-https://x1995.cn/1455.html

-j              bzip2压缩文件文章源自联网快讯-https://x1995.cn/1455.html

-v              显示压缩或解压缩过程 v(view)文章源自联网快讯-https://x1995.cn/1455.html

-f              使用档名文章源自联网快讯-https://x1995.cn/1455.html

例:文章源自联网快讯-https://x1995.cn/1455.html

tar -cvf /home/abc.tar /home/abc              只打包,不压缩文章源自联网快讯-https://x1995.cn/1455.html

tar -zcvf /home/abc.tar.gz /home/abc        打包,并用gzip压缩文章源自联网快讯-https://x1995.cn/1455.html

tar -jcvf /home/abc.tar.bz2 /home/abc      打包,并用bzip2压缩文章源自联网快讯-https://x1995.cn/1455.html

当然,如果想解压缩,就直接替换上面的命令  tar -cvf  / tar -zcvf  / tar -jcvf 中的“c” 换成“x” 就可以了。文章源自联网快讯-https://x1995.cn/1455.html

 文章源自联网快讯-https://x1995.cn/1455.html

关机/重启机器文章源自联网快讯-https://x1995.cn/1455.html

shutdown文章源自联网快讯-https://x1995.cn/1455.html

-r             关机重启文章源自联网快讯-https://x1995.cn/1455.html

-h             关机不重启文章源自联网快讯-https://x1995.cn/1455.html

now          立刻关机文章源自联网快讯-https://x1995.cn/1455.html

halt               关机文章源自联网快讯-https://x1995.cn/1455.html

reboot          重启文章源自联网快讯-https://x1995.cn/1455.html

 文章源自联网快讯-https://x1995.cn/1455.html

Linux管道文章源自联网快讯-https://x1995.cn/1455.html

将一个命令的标准输出作为另一个命令的标准输入。也就是把几个命令组合起来使用,后一个命令除以前一个命令的结果。文章源自联网快讯-https://x1995.cn/1455.html

例:grep -r "close" /home/* | more       在home目录下所有文件中查找,包括close的文件,并分页输出。文章源自联网快讯-https://x1995.cn/1455.html

 文章源自联网快讯-https://x1995.cn/1455.html

Linux软件包管理文章源自联网快讯-https://x1995.cn/1455.html

dpkg (Debian Package)管理工具,软件包名以.deb后缀。这种方法适合系统不能联网的情况下。文章源自联网快讯-https://x1995.cn/1455.html

比如安装tree命令的安装包,先将tree.deb传到Linux系统中。再使用如下命令安装。文章源自联网快讯-https://x1995.cn/1455.html

sudo dpkg -i tree_1.5.3-1_i386.deb         安装软件文章源自联网快讯-https://x1995.cn/1455.html

sudo dpkg -r tree                                     卸载软件文章源自联网快讯-https://x1995.cn/1455.html

 文章源自联网快讯-https://x1995.cn/1455.html

注:将tree.deb传到Linux系统中,有多种方式。VMwareTool,使用挂载方式;使用winSCP工具等;文章源自联网快讯-https://x1995.cn/1455.html

APT(Advanced Packaging Tool)高级软件工具。这种方法适合系统能够连接互联网的情况。文章源自联网快讯-https://x1995.cn/1455.html

依然以tree为例文章源自联网快讯-https://x1995.cn/1455.html

sudo apt-get install tree                         安装tree文章源自联网快讯-https://x1995.cn/1455.html

sudo apt-get remove tree                       卸载tree文章源自联网快讯-https://x1995.cn/1455.html

sudo apt-get update                                 更新软件文章源自联网快讯-https://x1995.cn/1455.html

sudo apt-get upgrade文章源自联网快讯-https://x1995.cn/1455.html

 文章源自联网快讯-https://x1995.cn/1455.html

将.rpm文件转为.deb文件文章源自联网快讯-https://x1995.cn/1455.html

.rpm为RedHat使用的软件格式。在Ubuntu下不能直接使用,所以需要转换一下。文章源自联网快讯-https://x1995.cn/1455.html

sudo alien abc.rpm文章源自联网快讯-https://x1995.cn/1455.html

 文章源自联网快讯-https://x1995.cn/1455.html

vim使用文章源自联网快讯-https://x1995.cn/1455.html

vim三种模式:命令模式、插入模式、编辑模式。使用ESC或i或:来切换模式。文章源自联网快讯-https://x1995.cn/1455.html

命令模式下:文章源自联网快讯-https://x1995.cn/1455.html

:q                      退出文章源自联网快讯-https://x1995.cn/1455.html

:q!                     强制退出文章源自联网快讯-https://x1995.cn/1455.html

:wq                   保存并退出文章源自联网快讯-https://x1995.cn/1455.html

:set number     显示行号文章源自联网快讯-https://x1995.cn/1455.html

:set nonumber  隐藏行号文章源自联网快讯-https://x1995.cn/1455.html

/apache            在文档中查找apache 按n跳到下一个,shift+n上一个文章源自联网快讯-https://x1995.cn/1455.html

yyp                   复制光标所在行,并粘贴文章源自联网快讯-https://x1995.cn/1455.html

h(左移一个字符←)、j(下一行↓)、k(上一行↑)、l(右移一个字符→)文章源自联网快讯-https://x1995.cn/1455.html

 文章源自联网快讯-https://x1995.cn/1455.html

用户及用户组管理文章源自联网快讯-https://x1995.cn/1455.html

/etc/passwd    存储用户账号文章源自联网快讯-https://x1995.cn/1455.html

/etc/group       存储组账号文章源自联网快讯-https://x1995.cn/1455.html

/etc/shadow    存储用户账号的密码文章源自联网快讯-https://x1995.cn/1455.html

/etc/gshadow  存储用户组账号的密码文章源自联网快讯-https://x1995.cn/1455.html

useradd 用户名文章源自联网快讯-https://x1995.cn/1455.html

userdel 用户名文章源自联网快讯-https://x1995.cn/1455.html

adduser 用户名文章源自联网快讯-https://x1995.cn/1455.html

groupadd 组名文章源自联网快讯-https://x1995.cn/1455.html

groupdel 组名文章源自联网快讯-https://x1995.cn/1455.html

passwd root     给root设置密码文章源自联网快讯-https://x1995.cn/1455.html

su root文章源自联网快讯-https://x1995.cn/1455.html

su - root文章源自联网快讯-https://x1995.cn/1455.html

/etc/profile     系统环境变量文章源自联网快讯-https://x1995.cn/1455.html

bash_profile     用户环境变量文章源自联网快讯-https://x1995.cn/1455.html

.bashrc              用户环境变量文章源自联网快讯-https://x1995.cn/1455.html

su user              切换用户,加载配置文件.bashrc文章源自联网快讯-https://x1995.cn/1455.html

su - user            切换用户,加载配置文件/etc/profile ,加载bash_profile文章源自联网快讯-https://x1995.cn/1455.html

更改文件的用户及用户组文章源自联网快讯-https://x1995.cn/1455.html

sudo chown [-R] owner[:group] {File|Directory}文章源自联网快讯-https://x1995.cn/1455.html

例如:还以jdk-7u21-linux-i586.tar.gz为例。属于用户hadoop,组hadoop文章源自联网快讯-https://x1995.cn/1455.html

要想切换此文件所属的用户及组。可以使用命令。文章源自联网快讯-https://x1995.cn/1455.html

sudo chown root:root jdk-7u21-linux-i586.tar.gz文章源自联网快讯-https://x1995.cn/1455.html

 文章源自联网快讯-https://x1995.cn/1455.html

文件权限管理文章源自联网快讯-https://x1995.cn/1455.html

三种基本权限文章源自联网快讯-https://x1995.cn/1455.html

R           读         数值表示为4文章源自联网快讯-https://x1995.cn/1455.html

W          写         数值表示为2文章源自联网快讯-https://x1995.cn/1455.html

X           可执行  数值表示为1文章源自联网快讯-https://x1995.cn/1455.html

Linux中常用操作命令文章源自联网快讯-https://x1995.cn/1455.html

如图所示,jdk-7u21-linux-i586.tar.gz文件的权限为-rw-rw-r--文章源自联网快讯-https://x1995.cn/1455.html

-rw-rw-r--一共十个字符,分成四段。文章源自联网快讯-https://x1995.cn/1455.html

第一个字符“-”表示普通文件;这个位置还可能会出现“l”链接;“d”表示目录文章源自联网快讯-https://x1995.cn/1455.html

第二三四个字符“rw-”表示当前所属用户的权限。   所以用数值表示为4+2=6文章源自联网快讯-https://x1995.cn/1455.html

第五六七个字符“rw-”表示当前所属组的权限。      所以用数值表示为4+2=6文章源自联网快讯-https://x1995.cn/1455.html

第八九十个字符“r--”表示其他用户权限。              所以用数值表示为2文章源自联网快讯-https://x1995.cn/1455.html

所以操作此文件的权限用数值表示为662文章源自联网快讯-https://x1995.cn/1455.html

更改权限文章源自联网快讯-https://x1995.cn/1455.html

sudo chmod [u所属用户  g所属组  o其他用户  a所有用户]  [+增加权限  -减少权限]  [r  w  x]   目录名文章源自联网快讯-https://x1995.cn/1455.html

例如:有一个文件filename,权限为“-rw-r----x” ,将权限值改为"-rwxrw-r-x",用数值表示为765文章源自联网快讯-https://x1995.cn/1455.html

sudo chmod u+x g+w o+r  filename文章源自联网快讯-https://x1995.cn/1455.html

上面的例子可以用数值表示文章源自联网快讯-https://x1995.cn/1455.html

sudo chmod 765 filename文章源自联网快讯-https://x1995.cn/1455.html

继续阅读
Miracle
  • 本文由 发表于 2017年9月19日19:56:29