嵌入式linux入门1-指令使用总结笔记

Linux常用命令

目录操作

pwd # print working directory
cd # change directory
cd /home/water/ # change to directory direction /home/water/
cd ~ # change to home directory of current user
cd . # change to current directory
cd .. # change to parent directory
cd ../.. # change to parant's parent directory
cd - # change to last directory
# Linux的文件系统结构可以参考FHS标准(Filesystem Hierarchy Standard,文件系统层次标准)
ls # list
ls # list current directory contents
ls -l # list current directory contents using a long listing format
ls -a # do not ignore entries starting with .
ls -lh # print sizes like 1k 234M 2G, -h = --human-readable
mkdir # make directory
mkdir a # make directory a
makdir -p a/b # make directory b and b's parent directory a as needed
rmdir # remove directory if they are empty
rmdir a # remove directory a

文件操作

touch # create file
touch file1 # create file1
mv # move file/directory
mv dir1 ../dir1 # move dir1 to it's last directory
mv dir1 dir2 # rename dir1 to dir2
cp # copy file/directory
cp file1 file2 # copy file1 to file2
cp -r dir1 dir2 # copy dir1 to dir2 recursively
rm # remove file/dir
rm file1 # remove file1
rm -r dir1 # remove dir1 recursively
rm -i file1 # remove file1 and prompt before remove
find # search for files in a directory hierarchy
find [<dir>] <pattern> # search file match <pattern> in directory [<dir>]
find *.txt # find all files with suffix ".txt" in current directory
find -mtime -2 # find files which was modified last n*24 hours ago
grep # print lines that match patterns
grep -rn <pattern> <file> # print lines that match <pattern> in <file> with line numbers, -r recursive, -n show line numbers
man find | grep -n "-r" * # print lines with "-r" in std output of cmd "man find"
file # determine file type
file <file> # determine <file> type
file * # determine all files type in current directory
cat # concatenate files and print on the standard output
cat file1 # print file1
cat -n file1 # print file1 with line numbers
cat file1 file2 # concatenate file1 and file2, then print them to standard output
which <file> # return the pathnames of <file> which would be executed
whereis <cmd> # locate the binary, source, and manual page files for a command

压缩与解压

gzip # compress or expand files
gzip -l <gzip_file> # list information of <gzip_file>
gzip -kd <gzip_file> # expand <gzip_file> and keep original file
gzip -k <file> # compress <file> and keep original file

# 注意
# 一般用于小文件
# 相同的文件内容,文件名不同,压缩文件大小也不同
# gzip不能压缩目录
# 压缩文件后缀为.gz
bzip2 # compress or expand files

# 注意
# 用法同gzip,但是使用了更好的压缩算法以得到更高的压缩比,用于压缩大文件
# bzip2不能压缩目录
# 压缩文件后缀为.bz2
tar # an archiving utility
tar -cvf c.tar file1 file2 dir1 # archive file1 file2 dir1 to c.tar
tar -czvf c.tar.gz file1 file2 dir1 # compress file1 file2 dir1 to c.tar.gz
tar -cjvf c.tar.bz2 file1 file2 dir1 # compress file1 file2 dir1 to c.tar.bz2
tar -tvf c.tar # list contents of archive c.tar
tar -tzvf c.tar.gz # list contents of archive c.tar.gz which compress by gzip
tar -tjvf c.tar.bz2 # list contents of archive c.tar.gz which compress by bzip2
tar -xvf c.tar # expand archive c.tar
tar -xzvf c.tar.gz # expand archive c.tar.gz which compress by gzip
tar -xjvf c.tar.bz2 # expand archive c.tar.gz which compress by bzip2
tar -xjvf c.tar.bz2 -C /home/ # expand archive c.tar.gz which compress by bzip2 to directory /home/

# 注意
# tar用于对多个文件与目录进行打包生成一个文件,之后可以用gzip和bzip2对归档文件进行压缩
# 选项-z -j 分别调用gzip和bzip2对归档后的文件进行压缩
# 选项 -f 用于指定归档文件名
# 选项 -C 可以指定进行压缩或解压操作时要切换到的工作目录,理解为压缩文件生成目录或要解压到的目录

其他常用命令

clear # clear screen
reset # reset terminal
man # show system reference manuals
man man # show system reference information about cmd 'man'
info ls # show information documents of cmd 'ls'
ls --help # using option '--help' can show cmd help information

文本编辑器vi

vi的不同模式

光标移动

  • 当处于一般模式下,使用HJKL分别负责光标的←↓↑→
  • 快速定位到某一行(一下均为一般模式下操作)
    <n>gg 快速定位到第<n>行的行首,gg 定位到文件首行,G 定位到文件末行
    0 移动到当前行行首,$ 移动到当前行行末
    f<c> 跳转到当前行中下一个字符<c>出现的位置

文本操作

  • yy 复制当前行,<n>yy 从光标所在行开始往后复制n行
  • dd 删除当前行,<n>dd从光标所在行开始往后删除n行,删除的内容会留存在剪切板中,可以用p粘贴
  • p 粘贴内容到光标所处行的下一行
  • u 撤销上一步操作
  • /<word> 从当前位置搜索<word>第一次出现的位置,n 向下重复上一次搜索,N 向上重复上一次搜索
  • :%s/<str1>/<str2>/g 全局查找str1字符串并全部替换为str2字符串,/g为全局搜索,/gc搜索前询问

其他命令(一般模式有效)

  • :set number 显示行号、:set nonumber 隐藏行号
  • :help <cmd> 查找命令<cmd>的帮助信息

FHS文件系统层次化标准

了解FHS可以直到linux内的系统目录都是干什么的,参考链接:

diff与patch

diff和patch命令在开发中经常用到,用来生成补丁或打补丁,参考链接:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值