Getting Started with Embedded Linux 1- Summary Notes on Instruction Usage

Linux common commands

directory operations

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

file operation

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

compression and decompression

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 可以指定进行压缩或解压操作时要切换到的工作目录,理解为压缩文件生成目录或要解压到的目录

Other common commands

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

text editor vi

different modes of vi

cursor movement

  • When in normal mode, use HJKL to be responsible for the ←↓↑→ of the cursor respectively
  • Quickly locate a certain line (both are operated in normal mode)
    <n>gg quickly locate to the beginning of line <n>, gg locate to the first line of the file, G locate to the end of the file
    0 move to the beginning of the current line , $ Move to the end of the current line
    f<c> Jump to the position where the next character <c> appears in the current line

text manipulation

  • yy copy the current line, <n>yy copy n lines from the line where the cursor is
  • dd deletes the current line, <n>dd deletes n lines from the line where the cursor is located, the deleted content will be saved in the clipboard, and can be pasted with p
  • p Paste the content to the next line of the line where the cursor is
  • u Undo the previous operation
  • /<word> searches for the first occurrence of <word> from the current position, n repeats the previous search down, N repeats the last search up
  • :%s/<str1>/<str2>/g globally search str1 string and replace all with str2 string, /g is global search, /gc asks before searching

Other commands (valid in normal mode)

  • :set number show line number, :set nonumber hide line number
  • :help <cmd> Find the help information of the command <cmd>

FHS File System Hierarchy Standard

To understand what FHS can do until the system directory in linux, refer to the link:

diff and patch

The diff and patch commands are often used in development to generate patches or apply patches, refer to the link:

Guess you like

Origin blog.csdn.net/lczdk/article/details/123435735