#### shell 的定义

shell 是作为用户与unix系统之间的操作接口的程序

#### 在linux系统中mount DOS软盘

$ mount -t msdos /dev/fd0 /mmt/floppy

$ cp * /mmt/floppy

$ umount /dev/fd0

$ls -p  在目录后面加上/

#### file 和 ls (list) 命令

常用选项(man ls)

$ls -a   列出所有文件包括隐藏文件

$ls -l  列表方式列出

$ls -R  列出目录下的内容

$ls -t  以文件最近被修改的时间排序

$ls -r  旧的文件在前

#### cat filename  查看文件

$cat -n filename

#### wc filename 统计文件行数,单词数,字符数

$wc -l filename

$wc -w filename

$wc -c filename

#### cp source destination

$cp -i source destination   交互式复制

$cp -r source destination  递归复制

$cp -f source destination  强制复制

$cp -p source destination  复制保留权限

#### mv source destination

$mv -i source destination

#### rm filename

$rm -irf filename

nohup /usr/local/mine/message_receive_test/bin/start.sh 5 > stdout.log 2>&1 &

#### mkdir

$mkdir -p /temp/directory/test

#### 使用cd(change directory)、pwd、ls、mkdir、cp

$cd /home/denise/krsort.dir.old

$pwd

$ls -l

$mkdir ../krsort.dir.new

$cp krsort ../krsort.dir.new

$ls -l ../krsort.dir.new

$mv krsort ../krsort.dir.new

$touch ../krsort.dir.new/.dotfile  (touch用来创建空文件或更新文件时间标记)

$rm -ifr ../krsort.dir.new/.dotfile

#### >、>> 重定向  >!、>>! 强制覆盖 (输出重定向)

0  标准输入

1  标准输出

2  标准错误输出

#### 参看文件内容:cat、more、head、tail

#### split、wc、 sort

$split -l line_count 把文件分成行为line_count的多个文件

$split -b n      把文件分成字节数为n的多个文件

$wc -l filename   文件行数

$wc -c filename  文件字符数

$wc -w filename  文件字数

$sort -t: -r -u -k4 filename 以:为分隔符,对第四个域进行反排序并删除重复的行。(sort默认的第一个域是0. -m是合并两个文件)

#### find

$find -atime +/-n  查找n天前访问的文件。+n 表示早于n天前访问的,-n 是表示晚于n天前

$find -ctime n   修改的文件

$find -empty

$find -exec command

$find -group name

$find -print

$find -type

$find -size +/-n

$find -name

$find . -user root -type f -perm 775 -print

$find . -size +5000c \( -name *.a -o -name *.c\) -print | wc -l

$find . -name "*.log" -mtime +10 -exec rm {} \;

$find . -name "*.log" | xargs rm

#### chmod   (u-user,g-group,o-other,a-all,operation:'+,-,=')

$chmod a=r *

$chmod go-w,a+x filename

$chmod 421 filename

#### chown change owner

$chown options user:group filename

$chown -R test: /home/test/fileone

#### chgrp change group

$chgrp options group filename

#### vi useage

command:

h left a char

l ringht a char

j up a line

k down a line

G end of the file line

nG move to the file n line

w move next word begin

W move next word begin and ignore punctuation(标点符号)

b move front word's begin

B move front word's begin and ignore punctuation

L move the screen last line

M move the screen middle line

H move the screen first line

e move the next word end

E move the next word end and ignore punctuation

( move the statement begin

) move the statemnet end

{ move the part begin

} move the part end

0 move the current line begin

r 替换当前文本

R 一直替换倒按下ESC

cw 更改至下一个字开始处

cc 替换当前行

cG

ctr-e 将屏幕上滚一行

ctr-y 将屏幕下滚一行

ctr-u 将屏幕上滚半页

ctr-d 将屏幕下滚半页

ctr-b 将屏幕上滚一页

ctr-f 将屏幕下滚一页

#### shell program

$ echo

$ date

$ read

$0   命令名     $1-$9 第1个参数倒第9个参数

$#    命令行参数的数目

$*   所有命令行参数

#### 变量、数组变量

$variable=one

$echo $variable

$array=(ma [3]=b [1]=cc)

$echo ${array[0]}  ma

$echo ${array[1]} cc

$array_variable=(one two three)

$echo ${array_variable[*]}

$echo ${array_variable[@]}

$array_variable[0]=one

$array_variable[1]=two

$array_variable[2]=three

$echo ${array_variable[*]}

$echo ${array_variable[@]}

$echo ${#array_variable[0]} 返回第一个元素的长度

$unset variable

#### 导出环境变量

$export variable

#### test

$string1=string2   如果两个字符串相同为真

$string1!=string2     不等则为真

$-b file    文件存在且是一个快特殊文件、则为真

$-c file    文件存在且是一个字符特殊文件、则为真

$-d file    文件存在且是一个目录、则为真

$-e file      文件存在则为真

$-f file    文件存在且是一个规则文件则为真

$-g file       文件存在且设置了SGID位的值、则位真

$-h file    文件存在且为一个符号连接、则位真

$-k file    文件存在且设置了“sticky”位的值、则位真

$-p file    文件存在且为一已命名管道、则位真

$-r file    文件存在且可读、则位真

$-s file    文件存在且大小大于零、则位真

$-u file    文件存在且设置了SUID的值、则位真

$-w file    文件存在且可写、则位真

$-x file    文件存在且可读、则位真

$-o file       文件存在且被有效用户ID所拥有、则位真

$-z string   若string长度为零则为真

$-n string   若string长度不为零则为真

$expression1 -eq expression2    =

$-ne         !=

$-gt         >

$-ge         >=

$lt         <

$le         =<

#### 特殊变量

$0   执行命令的名字

$n     执行命令所带参数对应

$#   参数个数

$*   列出说有参数

$@   用于有引号的参数

$?   前一个命令执行后的退出状态

$$   当前shell的进程号

$!   前一个后台命令的进程号

####  shift  移减参数

#### 文本过滤器

$head

$tail

$grep

$sort -rn -k 2,2 test.txt     ###对test的第二列进行排序安数字的大小顺序

$uniq -u d c   -u只显示不重复的行;-d 只显示有重复数据行,只显示一行; -c 打印每一重复行出现的次数

$join -o 1.1,2.2 test1.txt test2.txt  将test1的第一个域和test2的第二个域接一起

$cut -d: -f3 test.txt    以:为分隔符抽取第三个域

$cut -c 4-6 test.txt   抽取4-6之间的字符

$cut -f 3 -d :  test.txt   抽取第3个字段,以:为分隔符

$tr -s "[a-z]" < test.txt   去掉重复的字符

$tr -s "[\012]" < test.txt  去掉空行

$tr -s "[\n]" < test.txt

$tr -s "[\32]" < test.txt

$tr -s "[\r]" "[\n]" < test.txt  删除^M换成\n

$tr -s "[\015]" "[\n]" < test.txt   同上

exp:

$tr -s "[\n]" < test.txt   删除空行

$tr "[a-Z]" "[A-Z]" < test.txt  小写 -》大写

$tr "[:lower:]" "[:upper:]" < test.txt  同上(字符类)

$tr -cs "[a-z][A-Z]" "[\n*]" < test.txt  删除数字

$tr -s "[:]" "[\t]"  将:替换成\t

#### sed and awk

$sed /pattern/p 打印符合pattern的行

$sed /pattern/d 删除符合pattern的行

$sed 's/file/FIle/' 将file替换成FILE

$sed 's/file/FILE/g' 全局替换

$sed -n '2p' test.txt   打印文件第二行

$sed -n '1,3p' test.txt  打印1至3行

$sed -n '/file/'p test.txt  打印包含file的行

$sed -e '/file/=' test.txt  打印包含file的行号

$sed '/^$/d' file 删除空行

$sed -n '4,/the/'p test.txt

$sed '/company/ a\' test.txt

$sed -n '2,/install/s/$/***xg***/p' file 从第二行倒包含install的行的末尾加上***xg***

$sed '/anacon/r filetwo' file  从filetwo中读取匹配的行写入倒file中

$sed '4 i\' test.txt

$sed -n 's/\(inst\)all/\1xg/p' test.txt    模版inst被保存在1(tag1)中,all替换成xg,结果install替换成instxg

sed 's/\t//g' 27397_report.txt  替换\t为''

$awk -F:'command' inputf-ile  -F 指明input-file的分隔符为:默认为空格,$0 表示所有域

$awk -f awk-script-file input-file(s)  -f调用awk脚步文件

$awk '{printf "|The name is:%-10s ID is %8s|\n",$1,$4}' hold_file

$awk '$7 > 4{print $1 > "subdatafile"}' datafile   awk 重定向

$awk 'BEGIN{"date" | getline d; split(d,mon); print mon[2]}'

$awk 'BEGIN{while ("ls" | getline) print}'

$awk '{name[x++]=$2}; END{for(i=0; i < NR; i++)\

print i,name[i]}' datafile     数组

exp:

$awk '{print $0}' test.txt > now 把结果输出到now中

$awk '{print $0}' test.txt | tee -a now 把结果追加到now并输出结果

$awk 'GEGIN{print "start file\n---------------"} {print $2} END{print "end file"}' test-file

$awk '{if($4~/Brown/) print $0}' test.txt     打印包含Brown的记录($0 表示打印所有域; ~表示匹配正则表达式)

$awk '$3=="test" {print $0}' test.txt      精确匹配

$awk '$1 !~/Brown/ {print $0}' test.txt    打印不包含Brown的记录

$awk '{if($1 !~/Bronwn/) print{print $0}}' test.txt  同上

####### awk 内部变量

ARGC  命令行参数个数

ARGV  命令行参数排列

ENVIRON 支持队列中系统环境变量的使用

FILENAME  awk浏览的文件名

FNR  浏览文件的记录数

FS   设置输入域分隔符,等价与命令行-F

NF   浏览记录的域个数

NR   已读记录数

OFS  输出域分隔符

ORS  数据记录分隔符

RS   控制记录分隔符

IGNORECASE  忽略大写写(仅在gwak中有效)

SUBSEP  下标分隔符

exp:

$awk '{print NF,NR,$0} END{print FILENAME}' test.txt

$awk 'BEGIN { FLAG="file" } { if( $1==FLAG ) print $0 }' test.file

$awk '(count+=$2); END{print "the col count:"count}' test.file

$awk '{(count+=$2)} END{print "the col count:"count}' test.file

$ll | awk '/^[^d]/ {print $5,$9} {count+=$5} END{print "the file size-sum:"count}'

###### awk内置函数

gsub(r,s)    整个$0中用s替代r

gsub(r,s,t)   整个t中用s替代r

index(s,t)   返回s中字符串t的第一位置

length(s)    返回s长度

math(s,r)    测试s是否包含匹配r的字符串

split(s,a,fs)  在fs上将s分成序列a

sprint(fmt,exp) 返回经fmt格式化后的exp

sub(r,s)    用$0中最左边最长的字符串代替s

substr(s,p)   返回字符串s中从p开始的后缀部分

substr(s,p,n)  返回字符串s中从p开始长度位n的后缀部分

exp:

$awk 'gsub(/34/,3434) {print $0}' test.txt 将34替换成3434

$awk 'BEGIN {str-length=index("testin","in"); pirnt "str-length:"str-length}'

$awk 'BEGIN{print length("test")}'

$awk 'BEGIN{print match(test,/t/)}'

$awk 'BEGIN{print split("12#df#4545",array,"#")}'

$awk 'END{start=match("good os name", /[a-z]a/); print start}' datafile  输出na的位置9

$awk 'END{start=match("good os name", /[a-z]a/); print RSTART,RLENGTH}' datafile 输出na的位置9,和na的长度

$awk 'BEGIN{print toupper("linux"), tolower("MAN")}'

$awk 'BEGIN{now=strftime("%y-%m-%d"); print now}'

$awk 'BEGIN{now=strftime("%Y-%m-%d"); print now}'

$awk '{print(int(13/3))}' datafile 去掉小数,不舍入

$awk '{print rand()}' datafile  产生0-1之间的随即数

#### 正则表达式

$ /^$/  空行

$ /^.*$/  整行

$ / */  一个或多个空格

$ /][^>]×>/ html或xml标记

$ /[a-zA-Z][a-zA-Z]*:\/\/[a-zA-Z0-9][a-zA-Z0-9\.]*.*/  有效的URL

$ \$[0-9]*\.[0-9][0-9]/     美元数量格式

#### 信号处理

SIGHUP 1  检测控制终端的挂起或控制进程的死亡

SIGINT 2  键盘中断

SIGQUIT 3  从键盘退出

SIGKILL 9  杀死信号

SIGALRM 14 报警时钟信号

SIGTERM 15  终止信号

#### shell 调试

$/bin/sh -nv ./buggy1.sh   对buggy1.sh 进行语法检查

#### tee

$who | tee who.out

$who | tee -a who.out  追加到who.out后

#### 合并标准输入、输出

$grep "test.*" > grep.out 2>&1

#### 正则表达式

^           行首

$           行尾

^[the]         以the开头的行

[Ss]igna[lL]     匹配Signal、signal、signaL、SignaL

[Ss]ingal[lL]\.    同上,但加一句点

[mayMAY]       包含may大写或小写字母的行

^USER$        只包含USER的行

[tty]$        以tty结尾的行

\.          带句点的行

^d..x..x..x      对用户、用户组及其他用户组成员可执行权限的目录

^[^l]         排除关联目录的目录列表

[.*0]         0之前或之后加任意字符

[000*]        000或更多

[iI]         大写或小写i

[^$]         空行

[^.*$]        匹配行中任意字符

^......$       包含6个字符的行

[a-zA-Z]       任意单个字符

[^0-9\$]       非数字或美元标识

#### grep 的精确匹配

$grep -i "test\>" -c   匹配含有test的行

$grep -E '219|255' test.out  -E 使用扩展模式匹配 219或255

$ls -l | grep  '^d'

$ls -l | grep '^[^d]'

$ls -l | grep '^d.....x..x'

$grep -2 name file  打印包含name的上下各两行

$grep -A 2 name file  打印包含name的下两行

$grep -B 2 name file  打印包含name的上两行

$grep -e '-name' file 去掉-的意义

$grep -x -e '-name file' file 匹配整行且去掉-的意义

#### set 调试脚本

set -n 读命令但并不执行

set -v 显示读取的所有行

set -x 显示所有命令及其参数

#### << 一些是用技巧

$ cat >> myfile << NEWFILE    快速创建一个文件

$ lpr << QUICKDOC       快速创建打印文档

# trap 在脚本中捕获信号

$ trap "command" signals

# eval 扫描命令行进行置换

# 显示传给脚步的最后一个变量

$ #!/bin/sh

#evalit

echo "Total number of argumets passed is $#"

echo "The process ID is $$"

echo "Last argument is " $(eval echo \$$#)

# logger 命令

$ logger -p notice "This is a test message. Please Ignore $LOGNAME"

tail -f /var/log/messages

#### gcc的使用

$gcc -O2 -o hello hell.c       -O2 优化级别, -o 编译成可执行文件

$gcc -I /usr/local/include hello.c  -I 指定头文件的位置

$gcc -o hello hello.c /usr/lib/libm.a  指定库

$ar crv libfoo.a bill.o fred.o    归档函数库

$ranlib libfoo.a    为函数库建立一个内容表

$ldd hello      查看程序用的共享库

#### Linux 文件类型

-   普通文件

b  块专有设备文件

c  字符专有设备文件

d  目录

l  连接

n  网络专有文件

p  命名管道专有文件,也称为FIFO

s  套接字

####  Linux 下全新的问题

r read   4

w write   2

x excute  1

#### 通配符

*     匹配零个或多个字符

?     匹配任意单个字符

[test]  匹配列表中的任意字符

[1-9]   匹配范围中的字符

{tt,pp}  匹配tt或pp

#### execute command

$echo $(pwd)

$echo `pwd

#### exec 替换当前进程而不需要启动一个新的进程

$exec > temp  exec把当前shell的标准输出打开倒temp

$ls

$date

$exec > /dev/tty  标准输出显示在屏幕上

#### 参数扩展

${param:-default}   如果param是空,就把它设置为default的值

${#param}       给出param的长度

${param%word}     从param的尾部开始删除匹配word的最小部分返回声誉部分

${param%%word}    从param的尾部开始删除匹配word的最大部分返回剩余部分

${param#word}     从param的头部开始删除匹配word的最小部分返回剩余部分

${param##word}    从param的头部开始删除匹配word的最大部分返回剩余部分

#### jobs

$jobs -l  显示在后台运行的进程及pid

$jobs %%  显示最近执行的命令

$jobs -x echo %1  只显示进程的pid且是指定作业,1为作业号

$fg %1    把指定的作业放到前台执行

#### 参数顺序

$echo a b c

$echo !$  返回命令的最后一个参数

$echo !^   返回命令的第一个参数

$echo !*  返回命令的全部参数

#### declare

$declare -f   显示定义函数清单

#tar

1、*.tar 用 tar –xvf 解压

2、*.gz 用 gzip -d或者gunzip 解压

3、*.tar.gz和*.tgz 用 tar –xzf 解压

4、*.bz2 用 bzip2 -d或者用bunzip2 解压

5、*.tar.bz2用tar –xjf 解压

6、*.Z 用 uncompress 解压

7、*.tar.Z 用tar –xZf 解压

8、*.rar 用 unrar e解压

9、*.zip 用 unzip 解压

tar czvf test.tar.gz test/

tar xzvf test.tar.gz ./

#grep info

$free

$grep SwapTotal /proc/meminfo

$grep MemTotal /proc/meminfo

$grep "model name" /proc/cpuinfo

#operator system info

lsb_release -a

awk -F"|" -v OFS='|'  '{print $1,$2,$3}' GM0205201106131500025958-33288-20110613150006.log|grep '301004'>user.log

nohup /usr/local/mine/message_receive_test/bin/start.sh 5 > stdout.log 2>&1 &

linux开发板命令rx,linux 常用命令汇总相关推荐

  1. linux开发板显示百叶窗图片,03Linux命令操作2

    第一天 第一个小时嵌入式介绍,何为嵌入式,为什么学习嵌入式,嵌入式的发展前景,嵌入式的具体工作岗位以及薪资待遇如何. 第二个小时项目介绍 1.为什么需要项目的的沉淀,企业需要什么样的嵌入式开发人才 2 ...

  2. 兼容arduino的linux开发板,Arduino的各种常用开发板

    Arduino开发板大全,来看看你玩过哪些? 昨天认识了Arduino,今天来看看Arduino的各种常用开发板. 它有各种型号的,如Arduino Uno.Arduino Leonardo.Ardu ...

  3. linux 开发板传文件,Linux下用USB传输文件到开发板

    记录一下解决EZ6410的板子在Linux下用USB来传输文件问题的过程~ 前两天ARM11的开发板到了,需要先验证一下各项功能.以往用FS2410时用的是minicom+usb2ram,功能比win ...

  4. linux开发板汉字显示,Linux Qt 及Arm开发板汉字显示

    作为一个优秀的开发人员,我就不说废话了. 很多人在 使用Qt做嵌入式开发时,会遇到一个问题: 汉字显示,网上有好多方法,并且针对 Qt5 以前的版本和Qt5 的版本有不同的方法,同样,我也遇到了这个问 ...

  5. linux 开发板传文件,linux下使用minicom传送文件到开发板

    下载tar zxvf lrzsz-0.12.20.tar.gz 得到我们想要的解压包 进入到那个文件夹下.输入./configure –prefix=/usr/local/lrzsz 执行完之后,键入 ...

  6. Linux开发板显示字库,linux追加中文字库,解决imagemagick 中文乱码的问题。

    Windows下的字体丰富多样,而且显示的工整.漂亮. 所以自己想把windows上的字体移到Ubuntu下来.Windows下字体库的位置为C:Windowsfonts,这里面包含所有windows ...

  7. 你一定要知道的关于Linux文件目录操作的12个常用命令

    博客园 首页 新随笔 联系 管理 订阅 随笔- 26  文章- 1  评论- 18  你一定要知道的关于Linux文件目录操作的12个常用命令 转自:http://www.cnblogs.com/yo ...

  8. 【Linux】vi和vim编辑器——常用命令大全

    文章目录 8.1.vi 和 vim 8.1.1 VI 8.1.2 VIM 8.2 打开和新建文件 8.2.1 打开文件并且定位行 8.3 VI三种工作模式 8.4 常用命令 8.4.1 移动 8.4. ...

  9. linux系统中如何查看日志 (常用命令)

    linux系统中如何查看日志 (常用命令) cat  tail -f 日 志 文 件 说    明  /var/log/message 系统启动后的信息和错误日志,是Red Hat Linux中最常用 ...

  10. Linux学习笔记(二)|常用命令

    Linux学习笔记(二)常用命令 1.文件处理命令 1.1命令格式与目录处理 -ls 功能描述:显示目录文件 原意:list 所在路径:/bin/ls 语法: ls-a 显示所有文件,包括隐藏文件 l ...

最新文章

  1. 装有linux的硬盘装到不同主机,把ubuntu系统安装进移动硬盘,可在不同电脑上运行...
  2. Swift之高德地图自定义标注弹出气泡样式
  3. syslog记录history历史记录
  4. centos离线安装mysql8_CentOS7离线安装Mysql8.0
  5. ubuntu共享无线链接
  6. 挺住了这一波,微盟正在进化
  7. 对提高squid命中率的一些研究
  8. 点击回应、关闭确认以及另一种获取设备环境句柄的方法
  9. 使用sortable插件实现列表中表项的拖曳排序操作8-3
  10. CSDN,CNBLOGS博客文章一键转载插件 终于更新了!
  11. Pile 0009: Vim命令梳理
  12. node.js Websocket消息推送---GoEasy
  13. 第24周维生素市场最新动态
  14. 简易版Dubbo方法级性能监控(实现TP90、TP99)
  15. 虚拟机安装日志服务器,rsyslog日志服务器搭建
  16. GitHub 日收 12,000 星,微软新命令行工具引爆程序员圈!
  17. svn admin 详细介绍
  18. 反向传播思想及其优缺点
  19. 【架构设计】简单设计原则(Kent Beck)
  20. 计算机的桌面偏上怎么调整,电脑桌面软件太靠边怎么办

热门文章

  1. cocos2dx box2d使用(一)
  2. c# 小写金额转大写
  3. c语言如何交替打印大小写字母,C/C++语言实现两个线程交替打印奇偶数
  4. idea64.exe.vmoptions 参数意义
  5. JDK动态代理为什么必须要基于接口
  6. 一个出色的UI设计师需要具备哪些能力?
  7. mpvue学习笔记-之微信数据请求封装
  8. 企业网盘居然支持高速局域网文件传输工具(速度可达20M)
  9. Android UsageStatsService(应用使用统计服务)的学习与调研
  10. Java中迭代Map的方法