查看Linux日志信息常用方法总结

时间:2024.4.27

查看Linux日志信息常用方法总结

日志对于安全来说,非常重要,他记录了系统每天发生的各种各样的事情,我们可以通过他来检查错误发生的原因,或者受到攻击时攻击者留下的痕迹。Linux系统会记录我们的每一步操作,这些文件通常保存在/var/log文件夹的文本文件里面,如果直接查看文本,那么想当的繁琐,看起来也不方便,好在linux为我们提供了很多的工具来查看这些文本文件。下面我提供以下几种方法供参考,相信会对我们有帮助的。

1.上下翻

当我们在命令行窗口里面输入了一条命令之后,Linux会记录下这条命令,那么我们也就可以通过方向键上下来获取以往的运行的命令,大大的节省了输入时间。

2.last命令

last命令显示出以往账户登录的信息,通过last user可以过滤某个用户登录的信息。

例如输入last root,显示结果如下

 

2.lastlog命令

lastlog文件在每次有用户登录时被查询。可以使用lastlog命令来检查某特定用户上次登录的时间,并格式化输出上次登录日志/var/log /lastlog的内容。它根据UID排序显示登录名、端口号(tty)和上次登录时间。如果一个用户从未登录过,lastlog显示\"**Never logged**。注意需要以root运行该命令,结果如下

3.who命令

who命令查询/var/log/utmp文件并报告当前登录的每个用户。who的默认输出包括用户名、终端类型、登录日期及远程主机。例如,键入who命令,然后按回车键,将显示如下内容:

4.w命令

w命令查询/var/log/utmp文件并显示当前系统中每个用户和它所运行的进程信息。例如,键入w命令,然后按回车键,将显示如下内容:

5.mutt命令

有一些执行了系统操作或者发生错误之后,系统会以邮件的形式保存起来,以便通知管理员处理,这时我们可以通过mutt查看系统执行的过程,如crontab运行的结果。例如我有这样一个执行每日编译的脚本,crontab设置为

具体运行的过程

5.结束

以上只是我平时查看日志的用到一些命令,大家还有什么技巧欢迎讨论


第二篇:Linux常用的命名总结


Unix (Linux)1. OS: Operating SystemWindows, Unix(Sun, HP, AIX), Linux(redhat), MAC(apple), etc.参考书: UNIX操作系统 (第五版)Jerry Peek, Grace Todino & John Strang 著 龚志翔 等译20xx年1月出版书号:7-111-10164-2页数: 188定价:26.00元----------------------------------------------------------------------------Course Objectives(Goal) : 课程目标*Log in and out of a Solaris/Linux system: 登录和退出*Navigate the file system: 文件系统导航*Create files and directories: 生成文件和目录*Change permissions of files and directories: 改文件和目录的权限 *Manipulate text files: 操作文本文件*Use the vi text editor: 使用文本编辑器vi*Use commands to search directories and files: 用命令搜索目录和文件*Use basic network commands: 用基本的网络命令*Identify and modify initialization files: 确定和修改初始化文件-----------------------------------------------------------------------------Unix (Linux)Unix: Solaris 5.9 telnet 222.128.6.23 远程连接网络中某台服务器userName: student1 给定用户名password: ascent 给定密码Linux: Redhattelnet 192.168.20.202 远程连接网络中某台服务器userName: ascent1 给定用户名... ...ascent200password: ascent 给定密码切换用户:通过su - 切换到root用户,使用root用户,可以添加普通用户:(也可以通过su user1切换到user1用户。)[root@localhost ~]# useradd user40 添加用户[root@localhost ~]# passwd user40 给新用户设置密码New UNIX password: 12345 输入密码Retype new UNIX password: 12345 输入确认密码* Kernel (内核)内核是系统的核心,是运行程序和管理像磁盘和打印机等硬件设备的核心程序。* Shell(壳)Shell是系统的用户界面,提供了用户与内核进行交互操作的一种接口。* File System: (文件系统) EXT2,EXT3, Directories(subdirectories), Filesroot: / 根Pathname: 路径名* Absolute Pathname绝对路径名: /myDir/yourDir* Relative Pathname相对路径名: myDir/yourDir /teacher/zhang/hello2.txt------------------------------------------------------------------------------------- * Command-Line Syntax 命令行语法$ Command [option(s)] [argument[s]]* Different from DOS: 与DOS不同 1> Case sensitive: 大小写敏感2> Different command prompt命令提示符: /!!!Unix(Linux) : slash (/) 左斜线!!!Window: \ 右斜线---------------------------------------------------------------------Basic Unix Commands: 基本语法1. Change password: 改密码$

passwd2. Clear the terminal screen: 清除终端屏幕$ clear3. Display the absolute pathname of the current directory (print working directory): 显示当前位置的绝对路径$ pwd4. Change Directories改路径名 改变目录: Accept both absolute 绝对路径 and relative pathnames相对路径$ cd directory_name$ cd /$ cd ~ "~"表示家目录,所谓家目录指系统管理员分配给你的目录.$ cd home/teacher$ cd /home/abc/test$ cd .. 退到上级目录$ cd ../..$ cd 直接cd回车,到主目录,和cd ~ 一样效果5. Displaying a Listing of Files and Directories: 显示文件和路径名 相当于List也相当于Dos下的Dir$ ls$ ls -a all的意思,把本目录下所有的文件,包括隐含的文件也列出来。$ ls -l long的意思,把文件的其他资料,如文件长度,上次修改的日期等等列出来。 $ ls -F 显示文件类型。"*"表示可执行文件,"/"表示目录,"@"表示连接。$ ls -t 依照文件最后修改时间的顺序,依序列出文件名。$ ls -R 显示出目录下,以及其所有子目录的文件名。$ ls -altR | more 内容很多一屏显示不完时,可用管道符连接more命令,每显示一屏暂停,按空格键继续.u: 拥有者-生成文件时登录的人,权限最高,u表示 : userg: 同组者-系统管理员分配的同组的一个或几个人,g表示: groupo: 其它人-除拥有者,同组者外的人,o表示 : othera: allrwx rwx rwx111 111 111 -> 777110 110 110 -> 666111 110 101 -> 765000 000 000 -> 000如: d rwx r-x r-x 4 user nobody 1024 Feb 22 09:20 myfile.txt-: 普通文件d: 目录rwx: 拥有者 111 -> 7r-x: 同组者 101 -> 5 r-x: 其它人 101 -> 54: 链接号user: 拥有者nobody:组名1024 : 大小Feb 22 09:20:最后一次修改时间myfile.txt:文件名 (蓝色的为目录)r 只读权限w 可写权限,对于目录来说,可生成文件与子目录或删除文件与子目录x 执行权限,对目录来说,可查找该目录下内容- 不可执行文件,不可读文件,不可写文件6. Change permissions修改许可权限,chmod 是chang mode的缩写。chmod - : + := : d --- --- --- 1 abc abc 1024 Feb 22 09:20 myfile.txt$ chmod u+rx,go+r myfile.txt -> 101 100 100$ chmod 744 myfile.txt -> 111 100 100$ chmod g-r myfile.txt -> 111 000 100$ chmod u+x,g-w myfile.txt -> 111 000 100$ chmod a=rw myfile.txt -> 110 110 1107. Create new

, empty files or update access and modification times建空的新文件, 或修改老文件日期$ touch HelloWorld.java8. Create directories : 创建目录mkdir [-p] directory_name!!!! note: / .. . ~$ mkdir games$ mkdir /games$ mkdir games/weekly $ mkdir ~/games$ mkdir ../games$ mkdir games/football$ mkdir -p games/football9. Copy files 拷贝文件,目录 copy a directory and its contents to another directory$ cp [-option] source_file destination_file$ cp [-option] source_file(s) destination_directory$ cp -r[i] source_directory(s) destination_directory//加i表示。若有同名的文件就提示一下。不加就不提示,直接覆盖。option:i -> interactive 交互式的r -> recursive 回归式的$ cp –r dir3 dir4 这条命令是将目录dir3完全地复制到目录/dir4里,在Dos里着条命令叫xcopy $ cp –r dir1 dir4 /tmp$ cp file1 file2 file3 dir_dest 这条命令把file1,file2,file3三个文件一起复制到/dir_dest里去。$ cp /tmp/file1 file2 将目录 /tmp 下的文件 file1 复制到现行目录下,文件名为 file2$ cp -r dir1 dir2 复制整个目录。若目录 dir2 已经存在,则将目录 dir1,及其所有文件和子目录,复制到目录 dir2 下,新目录名称为 dir1,即dir2/dir1。若目录 dir2 不存在,则将dir1,及其所有文件和子目录,复制为目录 dir2。10. Move or rename files and directories: 移动或重命名文件以及目录可以使用mv命令mv [-i] source target_file //加i删除时提示是不否确定删除mv [-i] source target_directory $ mv nuts brands$ mv /export/home/user2/dir1/brands ./$ mv dir5 dir611. Remove (delete) files or directory: 删除文件或目录 相当于deleterm [-i] filename(s): remove (delete) files: 删除文件rmdir directory_name(s): only remove (delete) empty directory 删除空目录rm -r directory_name(s): remove (delete) not empty directory 删除非空目录$ rmdir empty_dir$ rm –r dir6$ rm –ir /dir7$ rm -rf direname 删除一个目录和目录里所有的文件;12. !!!! help manual: man is your friend 帮助 是英语"manual"的缩写。格式:man -k 命令关键字$ man vi 显示vi命令的帮助信息 (输入!退出)* Scrolling in ManpagesSpacebar Scroll through a manual page one screen at a time 空格b Move back one screenf Move forward one screenq Quit the man command/string Search forward for informationn Find the next occurrence of string13. Enter multiple commands on a command line: 一行里输

入多个命令$ cd .. ; ls $ cd ; ls$ date ; cal ;pwd**** Metacharacters(元字符): Are keyboard characters with special meaning to the shell$ % > ! ~ * ? [ ] < > |$ ls d*$ ls dir?$ ls z?.txt$ ls [b-f]*$ ls [fF]k*abc?e.txt14. Angle Brackets (>, <, >>)* Use (>) to redirect the output of a command to a file rather than to the screen前一个命令的输出存到后面文件里* Use (<) to redirect the input to a command from a file rather than from the keyboard后面文件的内容作为前一个命令的输入* Use (>>) to append the output of a command to an existing file前一个命令的输出添加到后面文件里$ ls -l > myfile $ ls -l >> myfile15. Piping (|): 管道命令 Takes the output of one command and passes it as input into a following command前一个命令的输出作为后一个命令的输入$ ls -l | more16. Calender: 日历$ cal $ cal 7 2003Date:只输入date就显示当前的工作站时间,如果有root超级用户权限,加上参数可以修改工作站的时间。 格式:date mmddHHMM[cc]yy mm--月份,dd--日期,HH--小时,MM--分钟,cc--世纪(可选),yy--年份 例如: # date 1023153098 将把工作站系统时间改为19xx年10月23日15点30分$ dateangle Brackets(>,<,>>)$ mailx 使用该命令发送邮件$ cal 5 2003 > may.june$ cal 6 2003 >> may.june$ cal 7 2003 | lp$ ls –l /etc | more17. cat:Displays the contents of a text file on screen, often used to join two or more files into one large file cat是catenate的缩写,是把东西串起来的意思。显示文件内容在屏幕上, 或连接2个或多个文件成为一个大的文件$ cat filename(s) 串联显示把多个文件串到一起再输出$ cat 文件1> 文件2 就是把F1写到F2再输出,F2 信息被F1覆盖18. more: 分屏显示文件内容在屏幕上 Displays the contents of a text file one screen at a time$ more filename(s)19. head & tail: 显示文件内容(头, 或尾) Displays the first or last n lines of one or more filesDisplays first or last 10 lines by defaulthead [-n] filename(s)tail [-n] filename(s)$ tail -30 /usr/dict/words 显示文件的末尾30行信息---------------------------------------------------------------------------------------------------Text Editor : 文本编辑器1. emacs------------2. vi1>. Command mode(命令模式): can not input, the key you pressed is command2>. Entry mode(输入模式): can input, 3>. Last-line mode(最后行模式): save, or other operations转换模式:Command mode -> Entry mode (按键 i,I, a, A , o, O )i:"append"的

缩写,a:"append"的缩写,o:"open"的缩写Entry mode -> Command mode (按键 esc )Command mode -> Last-line mode (按键 : )Last-line mode -> Command mode (按键 return/enter)*Invoking vi (使用vi)vi filename (Open or create a file打开文件或建新文件)vi (Open a new file to be named later打开新文件,以后命名)view filename (Open a file as read-only打开只读文件)操作:向上:k向下:j向左:h向右:li :在光标当前位置插入a :在光标所在位置后插入I :在行头插入A :在行尾插入o :在光标所在行下插入一空行O :在光标所在行上插入一空行<Esc> 退出插入状态x :删除一个字符dw :删除当前词3dw :删除三个词dd :删除当前行5dd :删除五行:5,10d 删除从第5行到第十10行r :替换一个字符cw :替换一个单词c :替换一行C :替换从光标至行尾J :把当前行和下一行连起来u :废除刚才的编辑操作(即 undo)~ :改变大小写yy : 拷贝行(或Y)yw :拷贝词p :当前行下粘贴P :当前行上粘贴:1,2co3 拷贝行1,行2在行3之后:4,5m6 移动行4,行5在行6之后:w :存盘:w newfile :存成新文件:wq :存盘退出Vi(或ZZ,或:x):q! :强行退出不存盘:set nu :显示行代码:(number) :光标停在指定行G :到文件尾(1G到文件头):/串 :从当前行往下查找:?串 :从当前行往上查找n :查找继续:1,$s/旧串/新串/g : 替换全文(或:%s/旧串/新串/g):r《文件名》 : 在光标所在位置插入另一个文件----------------------------------------------------------------------------------------------------------20. which 显示命令的路径: Displays the pathname leading to an accessible command based on your search path$ which vi$ which man21. whereis 显示命令所有相关的路径: Displays all directories where desired command is located, including appropriate man page$ whereis vi22. whatis 命令的一行简介: Display a one-line summary about a keyword$ whatis vi23. id 用户ID: Displays the user name corresponding to the effective user ID (identifer)$ id24. who 所有登录用户: Displays information about all users currently logged on to the local system$ who25. who am i用户的信息: The who am i command displays information about your real user ID$ who am i 显示你的用户名和终端类型26. whoami 用户的登录名: The whoami command displays only the login name of the effective user$ whoami27. users显示登录用户列表: Display a compact list of users logged in$ users28. find 按条件查找文件: Find files base

d on specific criteria, then execute a command on the matching files$ find path expression [action] $ find / -name myfile.txt -print 从根目录开始寻找myfile.txt文件,并给出它的路径。29. grep 找到与字符串匹配的行: Searches a file for a specified text string and prints all lines that contain that pattern to the screen$ grep [option(s)] string filename -> case sensitive (lower case/ upper case)30. wc 显示文件的行数,单词数, 字符数: Displays a line, word, or character count of a file$ wc [options] filename(s)-l Counts lines-w Counts words-C Counts characters31. diff 比较文件: Finds differences between text files$ diff [option] file1 file232. df 显示磁盘空间: displays number of free disk blocks and files$ df -k 查看各文件系统剩余的空间,-k说明单位是千字节(kb)33. du磁盘空间总用量: summarize disk usage$ du34. ps 显示进程: list the processes currently running on the system$ ps35. kill 杀死进程: Terminate unwanted command processes that you cannot quit in the normal waykill [-signal] process-id一般先用ps命令先查看进程的ID号,再用kill。如果kill杀不掉,可再加参数-9,说明为强制杀掉。$ kill -9 16836. netstat 显示网络状态37. $ tar cvf RMS RMS.tar 把目录打包成一个文件$ tar xvf RMS.tar 把打包的文件展开。------------------------------------------------------------------------------------------------Client(客户端)Server(服务器)HostName (IP)localhost :本机127.0.0.1 :本机TCP/IP: TCP- Transport control protocol, IP- Internet protocol192.168.1.5Http: Naming Services 命名服务----------------------------------------------------------------------------------------------------------36. ping 192.168.1.5(hostname)37. telnet: The telnet server simulates a terminal to allow you to connect to and work on a remote systemtelnet hostname [port]38. ftp: Servers with sites set up for downloading files sometimes provide an anonymous ftp accountonly transport (download/ upload) filesftp://ftp 192.168.1.5get: get one file from remote system to localhost 从远程机器下载一个文件到本机put: put one file from localhost to remote system从本机上传一个文件到远程机器mget: get more files from remote system to localhost 从远程机器下载多个文件到本机mput: put more files from localhost to remote system从本机上传多个文件到远程机器Commands:cd 修改路径dir/ls 显示列文件bye 退出bin 以二进制方式传输文件,切记在传送可执行文件时要先执

行此命令。 -------------------------------------------------------------------------------------------Assignment: 作业1. vi : 编辑 XXX.java2. ftp: : 1> 从192.168.1.5 机器的目录/home/public 下载ws_ftple.exe 文件到你的机器2> 安装 cateftp.exe3> 使用 cateftp.exe 来传输文件 ----------------------------------------------------------------------------tail -f /opt/tomcat/tomcat5.5/logs/catalina.outcarl + z 组合健退出----------------------------------------------------------------------------# .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then. ~/.bashrcfi# User specific environment and startup programsJAVA_HOME=/usr/java/jdk1.5.0_15CLASSPATH=.CATALINA_HOME=/opt/tomcat/tomcat5.5PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:$CLASSPATH:$CATALINA_HOME/binexport PATH CLASSPATH JAVA_HOME CATALINA_HOMEunset USERNAME# source .bash_profile----------------------------------------------------------------------------Linux使用1: copy tomcat and xzvf ittelnet 192.168.1.251login: ascent10password: ascent进入 /tomcat输入 mkdir zy输入 cp /opt/tomcat/jakarta-tomcat-5.0.14.tar /tomcat/zy/jakarta-tomcat-5.0.14.tar进入 /tomcat/zy输入 tar xzvf jakarta-tomcat-5.0.14.tar2: config .bash_profile file(进入用户目录:输入pwd得到CATALINA_HOME)在当前用户目录下输入: cd输入 ls -a输入 vi (.bash_profile)配置 eNV(见图path配置)输入 :输入 wq(或zz 或 x) 存盘退出在当前用户目录下输入:source .bash_profile3: 修改server.xml文件进入tomcat目录输入 vi server输入 Connector port 8088输入 :输入 wq!4:测试重启cmd:telnettail -f /tomcat/ChenXiaoFei/tomcat目录/logs/ca.outcd /tomcat/zy/tomcat目录/bin5.登陆root用户可以使用 shutdown -r now 来重新启动服务器# /usr/sbin/shutdown -y -g0 -i0 执行关闭系统

更多相关推荐:
in的典型用法小结

in的典型用法小结in是最常用的介词之一其意义和用法不下二十余种由它构成的短语更是不计其数是高考试题中常出现的考点它还可用作副词和形容词作为副词的用法也有近十种下面我们一起总结一下in的几种典型用法一in用作介...

介词in的用法汇总

介词“in”的用法“in”是英语中最为活跃的介词之一,所以它给我们的学习带了很大的挑战。细分下来,它有如下用法年、月、年月、季节、周即在来年,在某月,在某年某月(但在某年某月某日则用on),在四季,在第几周等都…

in case用法小结

incase用法小结原题如下1JohnmayphonetonightIdon39twanttogoouthephonesNMET20xx春季AaslongasBinorderthatCincaseDsothat...

in,after.since.by.for用法小结

1inafterWe39llmeetagaintwoweeks两周后我们还会再见in时间段表示将来即在多长时间以后常用将来时且是非延续性动词after时间段表示过了段时间以后常指从过去某时算起的一段时间之后所以...

At on in的用法

Atonin时间用法总1At后加具体的时间小时分钟2on后加天日子3in后加较长的时间年月季习惯用法InIntheeveninginthemorningintheafternoonAt1Atdaybrestat...

in 的用法

1介词prep在里在中Thereisnocloudinthesky晴空万里无云GlasgowisinScotland格拉斯哥在苏格兰2介词prep进入Rayputhishandinthewater雷把手放进水中...

in的用法 - 副本

In的用法1介词prep在里在中Thereisnocloudinthesky晴空万里无云GlasgowisinScotland格拉斯哥在苏格兰2介词prep进入Rayputhishandinthewater雷把...

精华版 in, at, on表时间的用法

介词inon与at表时间的用法atlt天egnoondawnnightoneclockon天Monday30thJuneNewYearsDayMothersDayingt天20xxsummerApril还有早午...

介词in,on,at的用法和区别

教师MollyYan学生赵天时间5月1日8001000段龙文学校您值得信赖的专业个性化辅导学校咨询热线88737756龙文学校您值得信赖的专业个性化辅导学校咨询热线88737756教导主任签字龙文学校教务处

in 的用法

IN地方1atapointwithinanareaorspace在某一点某范围内或者空间内的ampacountryinAfrica在非洲的一个国家ampThekidswereplayinginthestreet...

at,in与on在时间方面的用法

atin与on在时间方面的用法at表示时间的一点in表示一个时期on表示特殊日子如Hegoestoschoolatsevenoclockinthemorning他早晨七点上学Canyoufinishthewor...

in_on_at的用法

一inon在方位名词前的区别1in表示A地在B地范围之内如TaiwanisinthesoutheastofChina表示方位的名词east东west西south南north北等前面都能用表示方位的介词inon和...

in的用法总结(32篇)