2019.9.14
$ fac() { (echo 1; seq $1) | paste -s -d\* | bc} $ fac 5 120
~/.bashrc
是 bash 的配置文件,所有的 shell 函数皆可在此定义,这样的好处是 shell 函数随时可用$ alias l = 'ls -1 --group-directories-first'
不带参数运行 alias
即可查看所有的参数的别名。一般 ubuntu 上的默认别名有以下几个,不得不说,不看一下还是真的不知道
$alias alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l='ls -cf' alias la='ls -a' alias ll='ls -alf' alias ls='ls --color=auto'
type -a
用法$ type -a cd cd is a shell builtin $type -a fac fac is a function fac () { ( echo 1; seq $1 ) | paste -s -d\* | bc }
$ seq 30 | grep 3 3 13 23 30 # 生成1-30的序列传给 grep,筛选出含有3的元素显示 # grep: 筛选元素 $ seq 30 | grep 3 | wc -l 4 # 在上一步的基础上统计行数 # wc: 计数功能;参数 -l 只输出行数量
# 我们在当下目录下新建文件 test $ seq 1 > test $ cat test 1 # 用序列1 覆盖test文件 $ seq 3 >> test $ cat test 1 1 2 3 # 在test文件末尾加上序列3 $ echo -n "hello" > test $ cat test hello$... # echo -n:就像上面的效果,hello 之后紧接着就是下一个 bash 语句 $ echo "hello" > test $ cat test hello $ ... # 没有参数 -n,hello后面相当于有个 \n; # 同样的,> 和 >> 的区别在于覆盖还是在末尾添加 $ echo "hello, world" >> test $ cat test hello hello, world $ cat test | wc -w 3 # 使用管道组合,wc -w 这个参数表示只统计单词数量 # 这条语句也有很多的等价写法: $ < test wc -w 3 $ wc -w test 3 test # 这些等价写法的好处在于不进行额外的进程
mkdir
除了 mkdir 都可以加 -i(interactive 交互),能让工具向你确认请求
$ man cat # 输出不止一页,所以我们可以控制页面宽度 $ man cat | head -n 20 # 只输出前20行,也可以用fold;将较长的行变为80字符长度 $ man cat | fold # 使用 help 可以查看 shell内置命令 $ help cat | head -n 20 # 第三方工具可以使用 -h 查看自带的帮助信息 $ java -h
如对本文有疑问, 点击进行留言回复!!
linux下文本编辑器vim的使用方法(复制、粘贴、替换、行号、撤销、多文件操作)
网友评论