当前位置:操作系统 > Unix/Linux >>

linux基础知识数则

一.日志文件及命令显示:

  1. /var/log/wtmp shell>who

  shell>who /var/log/wtmp 报告自从wtmp文件创建或删改以来的每一次登录

  2. /var/run/utmp shell>w

  3. shell>users 用单独的一行打印出当前登录的用户,每个显示的用户名对应一个登录会话

  4. shell>last 往回搜索wtmp来显示自从文件第一次创建以来登录过的用户

  5. shell>last weiqiong 只报告该用户的近期活动

  6. shell>ac 根据当前的/var/log/wtmp文件中的登录进入和退出来报告用户连结的时间(小时)

  如果不使用标志,则报告总的时间

  ac -d 显示每天的总的连结时间

  ac -p 显示每个用户的总的连接时间

  7. shell>lastlog 检查某特定用户上次登录的时间,并格式化输出上次登录日志/var/log/lastlog

  的内容,它根据UID排序显示登录名、端口号(tty)和上次登录时间

  二.linux和window互相发消息

  1. linux给window发消息:

  shell>echo "hello"|smbclient -M weiqiong

  2. 若希望在shell中也敲入net send实现window上同样的功能,在/usr/local/bin下创建文件net为可执行

  内容如下:

  #!/bin/bash

  #/usr/local/bin/net

  case "$1" in

  send)

  echo "$3"|smbclient -I "$2" -M `nmblookup -A "$2"|sed -e '1d'

  -e '3,/*/d'|cut -f2|cut -d' ' -f1`

  ;;

  *)

  echo "Usage:net send <IPaddr.> <message>"

  exit 1

  esac

  3. linux接受消息:

  安装并运行samba,然后修改smb.conf 一般位于/etc/samba/smb.conf

  在[global]段加如下内容:

  a. 如果你想把消息发到邮箱

  message command = cat %s |mail root -s "PopMsg from:%f-%m";rm %s;

  b. 如果你想再加点效果

  message command = cat %s |mail root -s "PopMsg form:%f-%m";

  /usr/local/bin/beep -f800 -l100 -D100 -n -f800 -l100 -D100 -n -f800 -l100;rm %s;

  (说明:写成一行,beep是一个小工具,用于发出一定频率的叫声.这样,有人发消息给你,就会

  听到三声"嘟嘟嘟"的叫声,然后你打入mail,是不是有标题"PopMsg from:xxx"的邮件)

  c. 如果你安装了LinPopUp,那么再让我们完善点

  message command = cat %s |mail root -s "PopMsg form:%f-%m";/

  usr/local/bin/beep -f800 -l100 -D100 -n -f800 -l100 -D100 -n -f800 -l100;

  /usr/local/bin/LinPopUp "%f" "%m" %s; rm %s

  (注意,还是要写成一行,好了,听到"嘟嘟嘟" mail察看.或者打开LinPopUp察看,它有历史功能,

  可以察看前面的信息,可以直接回复..桌面上做个LinPopUp的快捷方式,太方便了)

  三.ps的用法:

  1. -e可以参看所有进程

  2. -ef可以看见进程ID

  3. -aux可以看见进程的详细情况,包括父进程号,其中-u指只看本用户启动的进程

  四.改了.bash_profile可以不用重启动使其生效:

  source .bash_profile

  五.linux中查找命令:

  find / -name http.conf

  find / -name '*strm*' # 用通配符的时候需要用引号

  find / -size +1500c # 查找文件大小大于1500bytes的文件

  find / -amin -10 # 查找在系统中最后10分钟访问的文件

  find / -atime -2 # 查找在系统中最后48小时访问的文件

  find / -mmin -5 # 查找在系统中最后5分钟里修改过的文件

  find / -mtime -1 # 查找在系统中最后24小时里修改过的文件

  find / -cmin n # 查找系统中最后N分钟被改变状态的文件

  find / -ctime n # 查找系统中最后n*24小时被改变状态的文件

  find / -nouser # 查找在系统中属于作废用户的文件

  find / -user fred # 查找在系统中属于fred这个用户的文件

  find / -empty # 查找在系统中为空的文件或者文件夹

  find / -groupcat # 查找在系统中属于 groupcat的文件

  find /tmp ! -user panda # 找所有不属于panda的文件

  find / -user fred -or -user george #找到用户fred或者george的文件

  查找当前目录中所有以main开头的文件,并显示这些文件的内容

  $ find . -name ‘main*’ -exec more {} \;

  六.删除文件名开头为-的文件,如删除文件-a

  rm ./-a

  七.各种压缩文件的解压

  文件扩展名 解压(安装方法)

  .a ar xv file.a

  .Z uncompress file.Z

  .gz gunzip file.gz

  .bz2 bunzip2 file.bz2

  .tar.Z tar xvZf file.tar.Z

  compress -dc file.tar.Z | tar xvf -

  .tar.gz/.tgz tar xvzf file.tar.gz

  gzip -dc file.tar.gz | tar xvf -

  .tar.bz2 tar xvIf file.tar.bz2

  bzip2 -dc file.tar.bz2 | xvf -

  .cpio.gz/.cgz gzip -dc file.cgz | cpio -div

  .cpio/cpio cpio -div file.cpio

  cpio -divc file.cpio

  .rpm/install rpm -i file.rpm

  .rpm/extract rpm2cpio file.rpm | cpio -div

  .deb/install dpkg -i file.deb

  .deb/exrtact dpkg-deb --fsys-tarfile file.deb | tar xvf -

  ar p file.deb data.tar.gz | tar xvzf -

  .zip unzip file.zip

  八.保存man和info的结果

  shell> man touch | col -b > touch.txt

  shell> info touch -o touch.txt -s

  九.利用现存两个文件,生成一个新的文件

  1. 如何取出两个文件的并集(重复的行只保留一份)?

  cat test1 test2 | sort | uniq > test.txt

  2. 如何取出两个文件的交集(只留下同时存在于两个文件中的文件)?

  cat test1 test2 | sort | uniq -d > test.txt

  3. 如何删除交集,留下其他的行?

  cat test1 test2 | sort | uniq -u > test.txt

  十.mount各种分区

  1. fat32的分区 mount -o codepage=936,iocharset=cp936 /dev/hda7 /mnt/cdrom

  2. iso文件 mount -o loop /abc.iso /mnt/cdrom

  3. 软盘 mount /dev/fd0 /mnt/floppy

  4. USB闪存 mount /dev/sda1 /mnt/cdrom
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,