Open Draymonders opened 4 years ago
ls <file> | grep ".cpp" | wc -l
printf '#!/bin/bash\ngrep "processor\|model name" /proc/cpuinfo\n' > /tmp/1.sh
processor : 0
model name : Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz
processor : 1
model name : Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz
processor : 2
model name : Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz
processor : 3
model name : Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz
mv foo_bakup.txt foo_bakup_`date +%Y%m%d`.txt
seq 1 100 > /tmp/1.txt; seq 2 101 > /tmp/2.txt
查看1.txt和2.txt的不同
diff 1.txt 2.txt
<
后面文件比前面文件少了1行内容>
后面文件比前面文件多了1行内容
1d0
< 1
100a100
> 101
用ls -l /会得到根目录下的文件和目录信息。其中有文件的修改日期。请用cut / awk / sort / uniq中的一个或几个,统计一下这些日期出现的频率。
ll / | awk 'NR == 1 {next} { print $6" "$7 }' | sort | uniq -c
这里NR
指代的是行号
2 Apr 20
1 Apr 21
1 Apr 26
1 Apr 29
5 Aug 6
1 Feb 2
4 Feb 3
5 Jun 7
8 Mar 10
1 May 18
1 May 6
uname -a | sed 's# #\n#g'
sed命令 详见 https://github.com/Draymonders/Code-Life/issues/25
2
是标准错误流 1
是标准输出流
find /etc -name "gdb" 2>/tmp/find.stderr 1>/tmp/find.normal
diff
,不存在就给与提示
#!/bin/bash
num=$#
if [ $num == 0 ]; then echo "请输入1-2个参数,代表文件" elif [ $num == 1 ]; then if [ -f $1 ]; then cat $1 else echo "文件不存在" fi elif [ $num == 2 ]; then if [ -f $1 ] && [ -f $2 ]; then diff -u $1 $2 else echo "文件不存在" fi fi
刷一些题,巩固基础 学到的一些命令
diff -u a b
比较a和bNR
和FNR
代表的行号