您的位置:首页 > 运维架构 > Linux

linux常用命令

2015-04-13 09:06 337 查看
partprobe:强制让核心重新捉一次parttion tableman:查看帮助文档touch:新建文件[root@localhost ~]# touch test.txt[root@localhost ~]# lsanaconda-ks.cfg avira-rescue-system Desktop echo install.log install.log.syslog test.txt
ls -l 以长格式显示文件[root@localhost ~]# ls -l总计 120-rw------- 1 root root 1279 10-21 15:30 anaconda-ks.cfg-rw-r--r-- 1 root root 56686 10-31 17:07 avira-rescue-systemdrwxr-xr-x 2 root root 4096 10-21 15:37 Desktop-rw-r--r-- 1 root root 29 10-21 16:13 echo-rw-r--r-- 1 root root 27974 10-21 15:30 install.log-rw-r--r-- 1 root root 4379 10-21 15:29 install.log.syslog-rw-r--r-- 1 root root 0 11-03 10:30 test.txt
ls -ld 以长格式显示目录[root@localhost ~]# ls -lddrwxr-x--- 16 root root 4096 11-03 10:30 .
ls -a 显示包含的隐藏文件[root@localhost ~]# ls -a. .bash_profile echo .gnome2_private .lesshst test.txt.. .bashrc .eggcups .gstreamer-0.10 .metacity .Trashanaconda-ks.cfg .chewing .gconf .gtkrc-1.2-gnome2 .nautilus .viminfoavira-rescue-system .cshrc .gconfd .ICEauthority .redhat.bash_history Desktop .gnome install.log .scim.bash_logout .dmrc .gnome2 install.log.syslog .tcshrc以点(.)开头的为隐藏文件
mkdir:创建目录 make directory-m 直接设置文件的权限[root@localhost ~]# mkdir -m 711 test2-p 递归建立目录[root@localhost ~]# mkdir /data[root@localhost ~]# ls /backup boot dev home lost+found misc net proc sbin srv tftpboot usrbin data etc lib media mnt opt root selinux sys tmp var

cp:-p 连同档案的属性一起复制-d 若来源文件为链接文件的属性(link file),则复制链接文件属性而非档案本身-r 递归持续复制,用于目录的复制行为cp -a =cp -pdr 完整复制档案权限若想复制档案给其他使用者,必须用到档案的权限-u 在目标档案与来源档案有差异时,才会复制拷贝test.txt文件到/tmp/目录下[root@localhost ~]# cp test.txt /tmp/[root@localhost ~]# ls /tmp/mapping-root scim-panel-socket:0-root test.txt
cp 拷贝不出现提示的两个方法:\cp/bin/cp[root@localhost ~]# \cp /tmp/test.txt /mnt/test.txt[root@localhost ~]# /bin/cp /tmp/test.txt /mnt/test.txt
cd:切换目录cd . 切换到当前目录cd .. 切换到上级目录cd ~ 切换到用户主目录cd ~ 用户名 切换到指定用户的目录cd - 返回进入此目录之前所在的目录cd !$ 把上个命令的参数作为cd的参数
rm:删除文件[root@localhost ~]# rm test.txt rm:是否删除 一般文件 “test.txt”? y若test.txt文件中有内容,则会出现提示 mv:移动文件-f 强制覆盖-i 目标档案存在,询问是否覆盖-u 目标档案存在,且source比较新,就更新mv /data/test.txt /tmp/
echo:输入什么显示什么[root@localhost ~]# echo leyley[root@localhost ~]# echo jackjack
echo {a..d}或者{1..3}[root@localhost ~]# echo {1..3}1 2 3[root@localhost ~]# echo {a..d}a b c d
pwd:显示当前目录-P 显示出确实的路径,而非链接路径[root@localhost ~]# pwd/root[root@localhost ~]# cd /tmp/[root@localhost tmp]# pwd/tmp
cat:一次性输出-A 相当于-vET整合选项,可列出一些特殊字符而不是空白而已-b 列出行号,空白行不标行号-E 将结尾的断行字符$显示-n 打印行号,空白行也有行号-v 列出一些看不出来的特殊字符[root@localhost ~]# cat ett.txt 13333扩展:使用cat命令非交互编辑文件[root@localhost ~]# cat >>test<<EOF> i > am > you> EOF[root@localhost ~]# cat test i am you
cut命令:匹配特定字段cut[OPTION]...[FILE]-d 指定分隔域-f 匹配域/字段-c 显示字符[root@localhost ~]# head -4 /etc/passwd|cut -c1-5root: -->共有5个字段bin:xdaemoadm:x
[root@localhost ~]# head -4 /etc/passwd|cut -c1,5r: -->第1和第5个字段bxdoax
[root@localhost ~]# head -4 /etc/passwd|cut -d':' -f1,7root:/bin/bash --->指定分隔域为分号(:),匹配第1个和第7个字段bin:/sbin/nologindaemon:/sbin/nologinadm:/sbin/nologin

sort命令:对文本排序sort [OPTION]...[FILE]-r 反序-n 大小-k 指定排序列-t 指定分隔符-u268K /etc/selinux/targeted/contexts/files296K /etc/gconf344K /etc/sysconfig352K /etc/selinux/targeted/contexts[root@localhost date]# du -h /etc/|sort -n

alias:定义别名alias ley='cat /etc/sysconfig/network-scripts/ifcfg-eth0'[root@localhost ~]# alias ley='cat /etc/sysconfig/network-scripts/ifcfg-eth0'直接输入ley即可显示网卡配置信息[root@localhost ~]# ley# Intel Corporation 82540EM Gigabit Ethernet ControllerDEVICE=eth0BOOTPROTO=staticHWADDR=08:00:27:E7:8A:68ONBOOT=yesDHCP_HOSTNAME=localhost.localdomainIPADDR=192.168.1.125NETMASK=255.225.255.0
ulias:取消别名的定义ulias ley
head:从行首开始显示head -5 /etc/passwd显示/etc/passwd文件前5行[root@localhost ~]# head -5 /etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
tail:从行尾开始显示tail -5 /etc/passwd显示/etc/passwd文件后5行[root@localhost ~]# tail -5 /etc/passwdsquid:x:23:23::/var/spool/squid:/sbin/nologinxfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologingdm:x:42:42::/var/gdm:/sbin/nologinsabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologinley:x:500:500:liangenyu:/home/ley:/bin/bash
tree:显示树结构需安装:yum install -y tree[root@localhost ~]# yum install -y tree[root@localhost ~]# tree.|-- Desktop|-- anaconda-ks.cfg|-- avira-rescue-system|-- echo|-- install.log|-- install.log.syslog`-- test.txt
1 directory, 6 files
rmdir:删除空目录rmdir /data/[root@localhost ~]# rmdir /data/
xargs:用于把find/ls等命令输出交给后面处理find / -type f(文件或者目录d) -name "test.txt"|xargs rm -f[root@localhost ~]# find / -type f -name "test.txt"|xargs rm -f
find / -type f(文件或者目录d) -name "test.txt"|xargs cat(ls)[root@localhost ~]# find / -type f -name "test.txt"|xargs cat3
sed:取各种内容-n 取消默认输出 -s 替换g 全局sed -n 2,3p ett.txt 取出ett.txt中的第2到第3行[root@localhost ~]# cat ett.txt 123456[root@localhost ~]# sed -n 2,3p ett.txt 23
sed s/2/3/g ett.txt 在ett.txt中的2全局替换成3[root@localhost ~]# cat ett.txt 12222[root@localhost ~]# sed s/2/3/g ett.txt 13333
awk:比sed高级awk /^o/ oldboy.txt 取oldboy.txt中以o开头的行[root@localhost ~]# awk /^o/ test.txt oldbot
NR:行号&&:并且$0:打印整行awk '{if(NR>1 && NR<4) print $0}' ett.txt取出oldboy.txt文件中大于1并且小于4的行[root@localhost ~]# awk '{if(NR>1 && NR<4) print $0}' test.txt 23grep:过滤命令grep -Ei 过滤多个字符串(E)并且不区分大小写(i)[root@liangenyu ~]# echo A >>ett.txt[root@liangenyu ~]# echo b >>ett.txt[root@liangenyu ~]# echo C >>ett.txt[root@liangenyu ~]# cat ett.txt AbC[root@liangenyu ~]# grep -Ei "A|b" ett.txt Ab
grep -v 直接过滤 /etc/passwd 中含有root的文件root /etc/passwd [root@localhost ~]# cat test.txt rootjacktom[root@localhost ~]# grep -v root test.txt jacktom

vi:编辑器vim:比vi高级的编辑器seq:打印数字序列[root@liangenyu ~]# seq 212
chkconfig 查看设置开机自动软件的命令[root@liangenyu ~]# chkconfig --list|grep "3:on"
find-mitme n : n为数字,意义为在n天之前的被更改过的【内容数据】档案-mtime +n: 列出在n天之前(不含n天本身)被更改过的【内容数据】档案-ctime -n: 列出在n天之内(含n天本身)被更改过的【内容数据】档案-newer file: file为一个存在的档案,列出比file还要新的档案
范例一:将过去系统上面24小时内有变动过的内容(mtime)列出find / -mtime 00:代表目前的时间,从现在开始到24小时前find / -mtime 3 三天前的24小时内变动过的档案
范例二:寻找/etc底下的档案,如果档案日期比/etc/passwd新就列出[root@localhost ~]# find /etc/ -newer /etc/passwd
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux 新建 touch