70条常用Linux基础命令总结

[root@ping~]#tree-L1/

#使用tree命令查看根目录下的一层的目录结构

ls–listdirectorycontents

[root@ping~]#ls-l/

以长格式显示文件和目录的信息

[root@ping~]#ls-d/

显示目录和文件

[root@ping~]#ls-d/*

根目录下的所有的目录和文件

cd–Changetheshellworkingdirectory

[root@ping~]#cd–

上次一次所在的目录

[root@ping/]#cd.

当前目录

[root@ping~]#cd..

这个目录的上一次目录

[root@ping/]#cd~

当前用户的家目录

pwd–  Printthenameofthecurrentworkingdirectory.

[root@ping~]#pwd

查看当前所处的目录

cp–copyfilesanddirectories

[root@ping~]#cp

拷贝文件或目录

alias–Defineordisplayaliases

[root@ping~]#aliasrm=”mv”

定义别名alies为mv命令

unalias–RemoveeachNAMEfromthelistofdefinedaliases

[root@ping~]#alias

alias-rf=’youwantremvoefilesordirectoriestomv’

aliascp=’cp-i’

aliasl.=’ls-d.*–color=auto’

aliasll=’ls-l–color=auto’

aliasls=’ls–color=auto’

aliasmv=’mv-i’

[root@ping~]#unaliasmv

取消mv这个别名

cat–concatenatefilesandprintonthestandardoutput

[root@ping~]#cat-n/root/.bashrc

查看文件内容并列出行号

find–searchforfilesinadirectoryhierarchy

option:!取反、-a(and)并且、-o(or)

[root@ping~]#find/-typef-name“useradd”

查找根目录下文件类型为文本文件并且包含名字是”useradd”的文件路径

head–outputthefirstpartoffiles

[root@ping~]#head/etc/services

默认查看文件前十行内容

tail–outputthelastpartoffiles

[root@ping~]#tail/etc/passwd

默认查看文件后十行内容

[root@ping~]#tail-f/var/log/messages

查看文件动态更新的内容

rpm–RPMPackageManager

[root@ping~]#rpm-ivh/mnt/Packages/elinks.el6_3.x86_64.rpm

安装显示输出rpm软件包情况

[root@ping~]#rpm-qa|grepmysql

查看当前系统安装关于”mysql”的rpm包名

yum–YellowdogUpdaterModified

[root@ping~]#yum-yinstallftp

用yum安装ftp管理工具

[root@ping~]#yumgrouplist

查看当前系统已经安装和可以安装的包组

[root@ping~]#yum-ygroupinstallPostgreSQL数据库服务器

向当前系统中安装一组软件包

[root@ping~]#yuminfo

显示关于软件包或组的详细信息

[root@ping~]#yumgroupinfo

查看yum和各个参数的详细信息

[root@ping~]#yumseracheall

在软件包详细信息中搜索指定字符串

seq–printasequenceofnumbers

[root@ping~]#seq5

生成序列从1到5的数字

[root@ping~]#seq35

生成序列从3到5的数字

[root@ping~]#seq3310

生成序列3到10中间隔多少个数字

[root@ping~]#seq-s“”5

12345

-s指定分隔符为空

[root@ping~]#seq-w10

生成两位数的数字并对齐

hostname–showorsetthesystem’shostname

[root@ping~]#hostname

ping

显示系统主机名

uname–printsysteminformation

[root@ping~]#uname-r

2.6.32-573.el6.x86_64

显示当前系统的内核版本和操作系统位数

[root@ping~]#uname-a

Linuxping2.6.32-573.el6.x86_64#1SMPWedJul118:23:37EDT2015x86_64x86_64x86_64GNU/Linux

显示当前系统的所有版本信息

[root@ping~]#uname-m

x86_64

显示当前系统的操作系统位数

whoami–printeffectiveuserid

[root@ping~]#whoami

root

查看当前登录系统的用户名

su–runashellwithsubstituteuserandgroupIDs

[root@ping~]#su–ping

切换普通用户为ping

logout– Exitaloginshell

[root@ping~]#logout

退出当前登录shell

history–Displayormanipulatethehistorylist

[root@ping~]#history

查看当前用户输入命令的历史记录

[root@ping~]#history-d122

指定122行的命令历史记录清除

[root@ping~]#history-c

清除当前用户输入命令所有历史记录

runlevel–outputpreviousandcurrentrunlevel

[root@ping~]#runlevel

N3

查看当前系统的运行级别

init–Upstartprocessmanagementdaemon

[root@ping~]#init5

切换当前系统的运行级别

chkconfig – updates andqueriesrunlevelinformationforsystemservices

[root@ping~]#chkconfigsshdon

使ssh服务开机自启动

[root@ping~]#chkconfig–listsshd

查看ssh服务在每一个运行级别是否为开机自启动

which–showsthefullpathof(shell)commands

[root@ping~]#whichps

搜索ps命令的绝对路径

whereis – locatethebinary,source,andmanualpagefilesforacom-mand

[root@ping~]#whereisjobs

搜索命令的文件所在的绝对路径

[root@ping~]#whereis-bping

只搜索命令的二进制文件的绝对路径

开户网卡和重新读取配置文件

[root@ping~]#ifdowneth0&&ifupeth0 ==》 [root@ping~]#/etc/init.d/networkreload

blkid–command-lineutilitytolocate/printblockdeviceattributes

[root@ping~]#blkid

查看当前系统块设备的UUID号

BASH_BUILTINS(1)

alias,bg,bind,break,builtin,caller,cd,command,

compgen,complete,compopt, continue, declare, dirs, disown, echo,enable, eval, exec,exit,export,false,fc,fg,getopts,hash,help,history,jobs,kill,let,local,logout,mapfile,popd,printf, pushd,pwd, read,readonly,return,set,shift,shopt,source,suspend,test,times,trap,true,type,typeset,ulimit,umask,unalias,unset,wait

#Linux中所有的内置命令,我们说which只能在PATH变量中搜索命令的绝对路径,内置命令是内置在bash中的,所以我们找不到

[root@ping~]#cat/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0#《==物理设备名,eth1表示第2块网卡

ONBOOT=yes     #《==控制网卡是否为开机自启动

NM_CONTROLLED=yes #《==是一个可以让networkmanage管理的工具

BOOTPROTO=none    #《==其中,proto取下列值这一:none,引导时不使用           协议;static静态分配地址;bootp,使用bootp协议

使用dhcp协议

IPADDR=192.168.114.5#《==ipaddress是IP地址

netmask=255.255.255.0 #《==子网掩码,划分网络位和主机位。

resolv.conf –resolverconfigurationfile

[root@ping~]#cat/etc/resolv.conf

#DNS的客户端文件,DNS在网卡的文件中也可以配置

[root@ping~]#cat/etc/resolv.conf

nameserver8.8.8.8

nameserver202.106.0.20

#一般最好配置两个DNS,一个主,一个备

#不要配置网卡里设置DNS优先于/etc/resolv.conf

小结:

1、客户端DNS可以在网卡配置文件里设置(ifcfg-eth0)

2、客户端DNS也可以在/etc/resolv.conf里设置

3、网卡里的设置DNS优先于/etc/resolv.conf

hosts–Thestatictablelookupforhostnames

[root@ping~]#cat/etc/hosts

#设定用户IP与名字(或域名)的对应解析表,相当于本地LAN局域网内的DNS

对应windows的文件路径:C:WindowsSystem32driversetchosts

/etc/hosts:局域网主机名和ip地址的解析,相当于DNS工具

hosts企业里的作用:

1.开发、产品、测试等人员,用于通过正式的域名测试产品

2.服务器之间的调用可以用域名(内部DNS),方便迁移

[root@ping~]#cat/etc/sysconfig/network

#配置主机的主机名的配置文件

fstab–staticinformationaboutthefilesystems

[root@ping~]#cat/etc/fstab

设置文件系统挂载信息的文件,使得开机自动挂载磁盘分区

Thethirdfield:suchasadfs,affs,autofs,coda,coherent,cramfs,devpts,efs,ext2,ext3, hfs, hpfs, iso9660,jfs, minix, msdos, ncpfs, nfs, ntfs, proc,qnx4,reiserfs,romfs,smbfs,sysv,tmpfs,udf,ufs,umsdos,vfat,xenix, xfs, and possiblyothers.

包含了所有的Linux文件系统类型

df–reportfilesystemdiskspaceusage

[root@ping~]#df-h

#以人类可读的信息查看磁盘挂载信息

mount–mountafilesystem

[root@ping~]#mount

查看当前系统中所使用的文件系统类型

[root@ping~]#mount-text4-oloop,noatime,noexec/dev/sdb1/mnt

-o参数:noatime,noexec不改变时间戳,不改变命令

手动挂载一个文件系统

挂载:

1.命令

[root@ping~]#mount-text4-onoexec/dev/sdb1/mnt

2.文件

[root@ping~]#vim/etc/fstab

dd–convertandcopyafile

[root@ping~]#ddif=/dev/zeroof=/dev/sdb1bs=4096count=10

生成一个文件系统

mke2fs–createanext2/ext3/ext4filesystem

[root@ping~]#mkfs.ext4/dev/sdb1

格式化文件系统/dev/sdb1

测试手动挂载:

1.创建一个虚拟的块设备

ddif=/dev/zeroof=/dev/sdb1bs=4906count=100

2.格式化

mkfs.ext4/dev/sdb1

3.挂载

mount-text4-oloop,noatime,noexec/dev/sda1/mnt

fsck–checkandrepairaLinuxfilesystem

[root@ping~]#fsck-A/dev/sda

磁盘检查(不要检查好磁盘),卸载的状态检查

本站所发布的一切资源仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如果侵犯你的利益,请发送邮箱到 [email protected],我们会很快的为您处理。
超哥软件库 » 70条常用Linux基础命令总结