linux常用命令2

来源:互联网 发布:手机吉他录音软件 编辑:程序博客网 时间:2024/06/02 06:46

grep 

 查找指定字符
 grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权限是所有用户。
 grep asdf 4.txt
 就是在4.txt里找,哪一行包含了asdf这个字符串。有多少行打印多少行。
 例如
 [root@localhost bjsxt]# more hello.javapublic class hello       {    public static void main(String[] args)    { System.out.println("Hello,World!"); return;     }       [root@localhost bjsxt]# grep hell hello.javapublic class hello[root@localhost bjsxt]# grep ello, hello.java System.out.println("Hello,World!");[root@localhost bjsxt]# grep a hello.javapublic class hello    public static void main(String[] args)

cat  file |  grep -v '^800'
显示某个文件中 不以800开头的行
-v 就是非
^ 就是以什么开头

fdisk 

是显示磁盘的信息

[root@localhost bjsxt]# fdisk -lDisk /dev/hda: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes   Device Boot      Start         End      Blocks   Id  System/dev/hda1   *           1          13      104391   83  Linux/dev/hda2              14        1305    10377990   8e  Linux LVM
共有255个磁头--------255个磁头 说明就大概有128个光盘,每个光盘的两面都能存数据
每个磁道有63个扇区
一共有1305个磁道(也就是1305个柱面)
每个柱面有16065个扇区,每个扇区有512个字节,所以一个柱面有8225280个字节
1305*8225280=10737418240
63*255=16065


hda1+hda2共有10377990+104391=10482381个boocks
10737418240/10482381=1024
所以在linux中 一个bolcks就是1k字节
http://baike.baidu.com/link?url=mEEZO0lIhu35HSTUoXlzudZz4SOsYmEX_1bc2H3jJCVpHxglB14kHhsMw9BLUL4BY508wy4i4HevBxCKg-UA6_




管道




wall

是warn all
它是干什么的?
输入这个wall  abd之后
所有的linux用户都会显示 abd
另外wall `date`  (这个`就是键盘上1旁边那个键) 这就是传说中的命令替换
会把date当做一个命令去执行



重定向

[root@localhost henang]# lszhengzhou[root@localhost henang]# ls >/bjsxt/command.txt[root@localhost henang]# cd /bjsxt/[root@localhost bjsxt]# ls3.txt  4  command.txt  hello.java  shandong[root@localhost bjsxt]# more command.txtzhengzhou[root@localhost bjsxt]# 
> 是定向输出到文件,如果文件不存在,就创建文件;如果文件存在,就将其清空;一般我们备份清理日志文件的时候,就是这种方法:先备份日志,再用`>`,将日志文件清空(文件大小变成0字节);
>>
这个是将输出内容追加到目标文件中。如果文件不存在,就创建文件;如果文件存在,则将新的内容追加到那个文件的末尾,该文件中的原有内容不受影响。


错误重定向

[root@localhost bjsxt]# ls 2>/bjsxt/command.txt3.txt  4  command.txt  hello.java  shandong[root@localhost bjsxt]# more command.txt[root@localhost bjsxt]# lasdfs 2>/bjsxt/command.txt[root@localhost bjsxt]# more command.txtbash: lasdfs: command not found[root@localhost bjsxt]# lsdf >/bjsxt/command.txtbash: lsdf: command not found[root@localhost bjsxt]# 
*******************************
command > otherPath 
如果命令本身是错误的,>就不能重定向了
如果要重定向错误命令
errorcommand 2> otherPath 
确实够2的


重定向输入

[root@localhost bjsxt]# vi advice.txt[root@localhost bjsxt]# wall <advice.txtBroadcast message from root (Sat Jan  9 21:56:40 2016):aaabbd[root@localhost bjsxt]# more advice.txt aaabbd[root@localhost bjsxt]# 

修改linux的默认启动级别

我们知道linux 有7个启动级别
3级就是命令行
5级就是图形界面
怎么修改默认级别呢?
查看 /etc/inittab文件

里面那个
id:3:initdefault:
3就是按第三级别启动

怎么修改懂了么?


界面转换

从命令行进入到图形界面 startx或者alt+f7
从图形界面进入命令行 
Alt+Ctrl+Fn(n=1~6)”就可以进入Console字符操作界面。
这就意味着你可以同时拥有X-Window加上6个Console字符操作界面。
0 :停机(记住不要把initdefault 设置为0,因为这样会使Linux无法启动 ) 
1:单用户模式,就像Win9X下的安全模式。 
2:多用户,但是没有 NFS 。 
3:完全多用户模式,标准的运行级。 
4:一般不用,在一些特殊情况下可以用它来做一些事情。 
5:X11,即进到 X-Window 系统。 
6:重新启动 (记住不要把initdefault 设置为6,因为这样会使Linux不断地重新启动)。
所有我们最经常用的是Alt+Ctrl+F3(从图形界面转到第三级的命令行)
在虚拟机下Alt+Ctrl被占用,我们得用Alt+Ctrl+shift


根据我从网上得到的信息,按Alt+Ctrl+shift+f(1-6)的效果应该是一样的#
可是我发现Alt+Ctrl+shift+F3可以进入命令行而Alt+Ctrl+shift+f1进入的命令行是乱码的#


Fatal server error:
Server is already active for display0
if this server is no longer running,remve /tmp/.X0 - lock and start again.
此时换alt+f7来切换到图形界面
第一次的时候alt+f7不行 又得用startx



0 0
原创粉丝点击