Linux常用命令
Mac一般使用bash作为默认shell
Mac系统的环境变量,加载顺序为:
/etc/profile /etc/paths ~/.bash_profile ~/.bash_login ~/.profile ~/.bashrc
/etc/profile和/etc/paths是系统级别,系统启动就会加载
~/.bash_profile ~/.bash_login ~/.profile ~/.bashrc. 用户级环境变量
Mac系统的环境变量,加载顺序为:
/etc/profile /etc/paths ~/.bash_profile ~/.bash_login ~/.profile ~/.bashrc
/etc/profile和/etc/paths是系统级别,系统启动就会加载
~/.bash_profile ~/.bash_login ~/.profile ~/.bashrc. 用户级环境变量
删除文件夹
rm -rf folder_name
环境变量: cd /Users/wzh ls -a vi .bash_profile source .bash_profile
修改host
sudo vi /etc/hosts
写一个 bash 脚本以统计一个文本文件 words.txt 中每个单词出现的频率 cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -r -n -k 1 |awk '{print $2, $1}' tr -s: truncate the string with target string, but only remaining one instance (e.g. multiple whitespaces) sort: To make the same string successive so that uniq could count the same string fully and correctly uniq -c: uniq is used to filter out the repeated lines which are successive, -c means counting sort -r -n -k 1 to sort by number and specify the sort column is the first column with word frequncy of uniq -c awk '{ print $2, $1 }': To format the output
mysql远程连接 mysql -h127.0.0.1 -P3306 -u name -p
更改文件夹权限 chmod 777 a/b chmod -R 777 a/b
查看进程
ps axu | grep nginx
本地端口转发
ssh -fN -L(要绑定到的本地端口):(目标服务器的Host):(目标服务器上要访问的端口号) -p(中转服务器的端口,默认为22) (中转服务器的账户):(中转服务器的Host)
重启nginx sudo nginx -s reload 本地nginx地址 /usr/local/etc/nginx/servers
php -S localhost:8001
#include <unistd.h> #include <stdio.h> int main (void) { printf("_SC_ARG_MAX: %ld\n", sysconf(_SC_ARG_MAX)); printf("_SC_CHILD_MAX: %ld\n", sysconf(_SC_CHILD_MAX)); printf("_SC_CLK_TCK: %ld\n", sysconf(_SC_CLK_TCK)); printf("_SC_NGROUPS_MAX: %ld\n", sysconf(_SC_NGROUPS_MAX)); printf("_SC_OPEN_MAX: %ld\n", sysconf(_SC_OPEN_MAX)); printf("_SC_JOB_CONTROL: %ld\n", sysconf(_SC_JOB_CONTROL)); printf("_SC_SAVED_IDS: %ld\n", sysconf(_SC_SAVED_IDS)); printf("_SC_VERSION: %ld\n", sysconf(_SC_VERSION)); return 0; } 输出结果: _SC_ARG_MAX: 262144 _SC_CHILD_MAX: 709 _SC_CLK_TCK: 100 _SC_NGROUPS_MAX: 16 _SC_OPEN_MAX: 256 _SC_JOB_CONTROL: 200112 _SC_SAVED_IDS: 1 _SC_VERSION: 200112
查看端口:sudo lsof -i :8080
复制文件夹 cp -r dir1 dir2
先必须了解两个最基本的命令: tail -n 10 test.log 查询日志尾部最后10行的日志; tail -n +10 test.log 查询10行之后的所有日志; head -n 10 test.log 查询日志文件中的头10行日志; head -n -10 test.log 查询日志文件除了最后10行的其他所有日志; 场景1: 按行号查看---过滤出关键字附近的日志 因为通常时候我们用grep拿到的日志很少,我们需要查看附近的日志. 我是这样做的,首先: cat -n test.log |grep "地形" 得到关键日志的行号 <3>得到"地形"关键字所在的行号是102行. 此时如果我想查看这个关键字前10行和后10行的日志: cat -n test.log |tail -n +92|head -n 20 tail -n +92表示查询92行之后的日志 head -n 20 则表示在前面的查询结果里再查前20条记录 场景2:那么按日期怎么查呢? 通常我们非常需要查找指定时间端的日志 sed -n '/2014-12-17 16:17:20/,/2014-12-17 16:17:36/p' test.log 特别说明:上面的两个日期必须是日志中打印出来的日志,否则无效. 关于日期打印,可以先 grep '2014-12-17 16:17:20' test.log 来确定日志中是否有该时间点,以确保第4步可以拿到日志 这个根据时间段查询日志是非常有用的命令. 6 如果我们查找的日志很多,打印在屏幕上不方便查看, 有两个方法: (1)使用more和less命令, 如: cat -n test.log |grep "地形" |more 这样就分页打印了,通过点击空格键翻页 (2)使用 >xxx.txt 将其保存到文件中,到时可以拉下这个文件分析.如: cat -n test.log |grep "地形" >xxx.txt 这几个日志查看方法应该可以满足日常需求了.
posted on 2018-08-02 09:54 www_practice 阅读(168) 评论(0) 编辑 收藏 举报