[Learning] Embedded Linux Linux basics (summary version)

Installation package

sudo dpkg -i ×××

View all installed software

dpkg --list

Uninstall a software

sudo apt-get --purge remove ×××

After installing half, then install termination

sudo apt-get install --reinstall ×××

The basic idea of ​​two Linux

  • Everything is a file
    • Directory, block device, process, thread, pipes, etc. can be seen as a file
  • Each software has identified uses

Common Commands

  • -rLayer by layer traversal, -ndisplay line numbers

  • man ××Check the manual can help one command

  • ls -l ×××Details of xxx (a representation Show hidden) [display. If not specified ×××, displays all! ]

    • Add parameters athat ls -l ...can show hidden files information!
    • It may also be used in conjunction with wildcard characters, such as ls -al h*, more information at the beginning of the file display h.
  • fdisk -l[Display] Disk Information

  • ifconfig > test2.logThe output of the network configuration file is written to test2.loga file

  • /dev/nullEquivalent to the Recycle Bin

  • tree -L 22 displays the tree layer

  • jobsView background processes

  • At the command plus &, directly in the background. Such as,gedit log2.txt &

  • pipeline

    • ××× | grep -i "×××"[Used to find a string variable containing]
    • ps -ef | more[Space] to turn pages
    • ps -ef | lessPage flipping up and down keys [] [enter or space /×××can be used to find a character]
  • pwdDisplays the current absolute path, if the current path is a link, use the pwd -pshow the actual path

  • mkdir -p 路径名, With the -pparameters, even though the latter path in some folder does not exist, it is created automatically.

  • rm - rf ×××Delete a file

  • cp

    • cp log1 dir2, Log1 file, dir2 is a folder
    • cp ../dir3/log2 .The current directory is dir2, achieve log2 copy files to the current directory dir3 dir2 directory.
    • cp log2 /home/clay/log1Log2 copy files to / home / directory under the clay, and to achieve copy and rename .
    • If the source file is a directory, you must add -rparameters. cp -r /etc .Copy all files in the current directory to the directory tec
      • -aParameters and -rparameters are the same
    • cp -s log1 log.linkCopy log1 into a soft link [shortcut] .
    • cp -u ~/.bashrc .bashrcIt occurs when two files are not the same, will be copied.
  • mv

    • mv dir3 dir2Move all the files in the directory to the dir2 directory dir3
  • touch

    • Create a new file
      • cat > fileThis can also be done to create a new file operations
    • Change timestamps of existing files
    • touch log1Create a file log1
    • touch file(1..5).txtCreate a file file1 ~ file5
  • stat log1It can be used to create log1 view, modification, and last access time

  • file[Identify the file type, file encoding format discriminating]

  • lnlink

    • ln -s log log_linkCreate a soft link to the log of
    • ln log log_linkCreate a hard link to the log of
  • Find command

    • Find command name which
      • which ls
    • Find the file name whereis locate find[whereis locate and use database lookups, fast. find the use of the hard disk for slow! ]
      • whereis bash
      • Just create or rename files locate just can not be found, we need to execute updatedbthe command
    • find
      • Search by file name
        • find / -name pam.conf, From the root directory of exact match search and pam.conf file
        • find / -name “pam.conf*”From the root directory containing the search pam.conf file
      • Search by file size
        • find / -size 389c, The search from the root directory file containing 389 bytes in size
        • find / -size -1k, The search from the root directory contains a file size less than 1k bytes
        • find / -size +1k, The search from the root directory contains a file size greater than 1k bytes
      • Search by file modification time
        • find ./ -mtime 7, Modify the search from 7-8 days the root directory of the file that day
        • find ./ -mtime -7Search from the root directory, 7 days a modified file
        • find ./ -mtime +7Search from the root directory, 7 days before the modified file
    • Search by file type
      • find / type dSearch from the root directory, type the directory ( -) file
    • Search by file permissions
      • find / -perm 777Search from the root directory permissions to 777 files
  • ps -efAll processes used to view the full format

  • grep

    • grep -n “author” ls.txtSearch author string ls.txt, where -n denotes a display of line numbers!
    • grep -n [td]o ls.txtSearch to and do in ls.txt in. [] Represents t or d, which satisfy a.
    • grep -n ^ls ls.txtIn ls.txt to begin with ls
    • grep -n 'gr..p' ls.txtFind out the string contains "gr ×× p" of
    • grep -n 'o\{3,5\}' ls.txtSearch contains 3 to 5 o string
  • chmod

    • Here Insert Picture Description
  • ps -aux= ps -efView all processes currently static display

    • ps | more
  • top The current dynamic display of all processes

  • Terminate the process

    • ctrl + z
    • kill -9 进程号
  • Network-related

  • netstat

    • Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description
    • Here Insert Picture Description
  • ifconfig 【和windows下的ipconfig一样】

    • Here Insert Picture Description
    • Here Insert Picture Description
  • route

    • Here Insert Picture Description

常用文件系统

  • ext2
    • Linux标准文件系统
  • vfat
    • 与Windows兼容的文件系统【FAT16、FAT32】,可作为windows和Linux交换文件分区
  • NFS
    • 网络文件系统
  • swap【类似windows的虚拟内存】
    • 专用交换分区

文件类型

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

  • 普通文件【 通常是流式文件】
    • 文件类型用-表示
    • 可分为:纯文本文件、二进制文件、数据文件
  • 目录文件【 用于表示和管理系统中的全部文件】
    • 文件类型用d表示
  • 设备文件【包括块设备文件(硬盘、U盘等)和字符设备文件(键盘)】
    • 块设备文件类型用b表示,/dev/sda是块设备所在,
    • 字符设备文件类型用c表示,/dev/tty通常是字符设备所在。
  • 管道文件(fifo)【提供进程间通信的一种方式】
    • 文件类型用p表示
    • 解决多个程序同时存取一个文件造成的错误问题
  • 链接文件【 用于不同目录下文件的共享】
    • 文件类型用l表示
  • 套接字文件【该文件类型与网络通信有关】
    • 文件类型用s表示
    • 同在/var/lib目录

目录

  • /【Linux只有一个根目录】
    • /bin【系统下最基础的命令,如“ls、cp、del”。该目录下的文件是可执行的,普通用户都可以使用的命令。】
    • /boot【引导加载程序相关的文件,内核映像文件也常放于此处!】
    • /etc【系统的各种配置文件,如用户账号密码配置文件、系统初始化文件,安装的各种应用软件、服务的配置文件等】
    • /usr【用到的应用程序、文件等】
      • /bin【集中了所有用户命令,是系统的软件库】
      • /include【包含C语言头文件,用来描述C语言中用到的数据结构、函数和常量】
      • /lib【程序库文件,系统不变的数据文件】
      • /sbin【根文件系统不必要的系统管理命令,如多数服务程序】
    • /var【经常变化的文件,如日志、数据库等】
    • /sbin【系统管理员使用的管理程序】
    • /tmp【系统临时文件】
    • /dev【设备文件,设备驱动程序】
    • /home【用户工作目录,个人配置文件】
    • /root【超级管理员文件夹】
    • /lib【根文件系统上的程序所需的共享库】
    • /mnt【系统管理员临时挂载系统的挂载点,】

Here Insert Picture Description

分区

  • 硬盘(硬盘必须分区才能使用)
    • 磁盘分区:主分区(数量1~3个)
      • 包括操作系统文件启动的硬盘分区
    • 磁盘分区:扩展分区(需要分为逻辑分区才能使用。扩展分区数量可以0~1个,而逻辑分区无数量限制)
/dev/sda1 ...
/dev/sda2 ...
/dev/sda5 ...

上例中,sd表示硬盘种类,a表示计算机上的第一块硬盘,1、2、5表示分区号。【扩展分区从5开始,故sda5为扩展分区,sda1和sda2为主分区】

  • 挂载:将目录和分区对应起来,通过访问该目录来访问该分区!

shell【命令解析器】

内核的外层保护,完成用户与内核的交互。将用户命令解析为操作系统所能理解的指令,实现操作系统与用户之间的交互。

  • Tab键自动补齐,或列出满足已打出字母的全部文件
  • 历史命令
    • 输入history即可查看历史命令【默认保存可达1000个】,所有的这些命令是保存在~/.bash_history
    • 上下方向键可查看之前运行过的命令
    • !+历史命令标号即可运行对应的历史命令
    • !!即可运行上一条命令
    • !+字符串运行历史命令中与之相对应的命令,或列出满足已打出字母的历史命令
    • history -c清除历史命令
    • ctrl+r即可进入向后增量搜索模式,输入想要查找的命令相关字母,即可搜索出相关命令!
  • 快捷键
    • 控制命令
      • ctrl + l 清屏
      • ctrl + c终止当前正在执行的命令
      • ctrl + z挂起命令,停止当前命令运行,使用fg进行命令恢复
      • ctrl + s阻止屏幕输出,当前正在执行的命令不再打印信息!
      • ctrl + q允许屏幕输出,与ctrl + s配套使用
      • ctrl + d退出当前的shell
      • ctrl + o执行当前命令,并选择上一条命令
    • 编辑命令
      • 光标移动
        • ctrl + a移动到命令行首
        • ctrl + e移动到命令行尾
        • ctrl + f向右移动一个字符
        • ctrl + b向左移动一个字符
        • alt + f向右移动一个单词
        • alt + b向左移动一个单词
      • 删除
        • ctrl + u从光标删除至命令行首
        • ctrl + k从光标删除至命令行尾
        • ctrl + w从光标删除至字首
        • alt + d从光标删除至字尾
        • ctrl + d删除光标处(后)的字符
        • ctrl + h删除光标前的字符(同backspace)
        • alt + backspacectrl + w,分隔符有些差别
        • ctrl + y粘贴至光标后

重定向

  • 输出重定向
    • 【基本用法】
      • 命令 > 文件,该方式是覆盖的方式。如,ifconfig > test1.log - 将网络配置信息写入到test1.log文件
      • 命令 >> 文件,该方式是追加的方式。
    • 【高级用法】
      • 命令 >> 文件1 2 >> 文件2,正确追加到文件1,错误追加到文件2
      • 命令 &>> 文件,无论正确与否都追加到文件 = 命令 >文件 2>&1 如,ifconfig eth0 > test1.log 2>&1 - 将错误信息保存到了test1.log文件!

命令执行顺序

  • ;多个命令并列,顺序执行
  • &&前一个命令执行完毕才可以执行后一个命令
  • ||前一个命令执行失败才执行后一个命令

环境变量

  • 常用环境变量
    • PATH【决定了shell在哪些目录去寻找命令和程序】
      • echo $PATH 显示当前系统的PATH变量【变量是路径;变量之间用冒号分割】
      • export PATH=$PATH:/home,设置临时的环境变量。【退出当前shell该环境变量不生效】【注意export新建变量时,等号左右不要加空格】
      • 修改用户主目录下的~/.profile文件或者~/.bashrc中使用export,启用后【用source启用或者重启启用】永久生效。 【通常修改.bashrc
      • 修改系统目录下的profile 文件,也会永久生效【要慎重设置,尤其是ROOT用户登录】
    • HOME【当前用户组目录】
    • USER【查看当前的用户】
    • LOGNAME【当前用户登录名】
    • UID【当前用户的识别字】
    • SHELL【当前用户使用的shell类型】
    • TERM
    • PWD【绝对路径】
    • MAIL【用户邮件存放目录】
    • HISTSIZE【保存历史命令的条数】
    • HOSTNAME【主机名】
  • 系统全局配置文件 /etc/profile【该文件是在登录到shell才会读取的文件】
    • 利用用户标识符(UID)来确定很多重要变量
  • 用户配置文件~/.bash_profile~表示 /home目录】
    • ~/.bashrc 专用于当前用户的配置信息
  • 如何让保存的环境变量配置立即生效呢?
    • source ×××
      • source .bash_profile
      • source ~/.bashrc
  • 常用命令
    • env显示所有的环境变量
      • 通常会很多,我们使用管道进行筛选出想要的:env | grep -i "×××"【"××ד是想要的字符串,-i表示忽略大小写】
    • set显示所有本地定义的shell变量【这个显示的全】
    • unset删除环境变量
      • unset -f:仅删除函数
      • unset -v:仅删除变量
  • readonly【修改变量或函数的属性为只读,即既不能修改,也不能删除。】
    • readyonly ×××即可设置环境变量

路径

  • 绝对路径
    • 完整路径
  • 相对路径
    • ..上一个目录
      • 如从目录usr/share/doc 到 /usr/share/man可直接使用../man
    • .当前目录
    • ~home目录
    • -上一个工作目录

当前用户主目录 ≠ 系统根目录

  • 用户是指当前用户所在目录。如/home/clay,此时等同于cd ~命令。
    • 若使用root用户,则在/root目录下
  • 根目录是/,等同于cd /

链接

  • 硬链接
    • 两个或多个文件名与相同的i结点相关联,可以为单个文件创建一个或多个硬链接
    • 以文件的副本的形式存在【大小跟源文件一样大】
    • 源文件删除之后,对硬链接没有影响;源文件内容改变,硬链接内容不改变。
    • 不能对目录文件做硬链接
    • 不能再不同的文件系统之间做硬链接
  • 软链接(符号链接)【类似windows 的快捷方式】
    • 软连接是一个新文件,具有不同的i结点号
    • 以路径的形式存在
    • 删除源文件,只删除了数据不会删除链接;源文件内容改变,软链接内容改变。
    • 软连接可以跨文件系统
    • 软链接可以对目录进行链接

正则表达式

  • ^开头,以$结尾
  • [0-9]匹配单个数字
  • +匹配一个多个字符串

用户

用户可分为超级用户root、系统用户和普通用户。

  • 文件拥有者owner
  • 用户组group
  • 其他用户others
  • User configuration file stored in the /etc/passwdfile
    • User profile is divided into seven fields
    • Such asclay:x:1000:1000:CLAY,,,:/home/clay:/bin/bash
    • Here Insert Picture Description
  • User passwords are stored in a /etc/shadowfile
  • Creating a simple userrain
    • adduser rainCreate a user
      • Delete usersuserdel rain
    • passwd rainset password

user group

  • User group information stored in /etc/groupthe directory,
  • groupadd ourgroupCreate a group ourgroup
  • usermod -a -G ourgroup clayAdding clay to ourgroup group
  • cat /etc/group | grep ourgroupThe group included members to view, verify whether to join the group success

Compression and Archive

  • List item
  • Here Insert Picture Description
  • Common gzipand bzip2the -9expressed compress, -drepresents decompression
  • gzip *All files are compressed
  • gunzip *Unzip all files
  • tar zcvf ls.tar.gz ls.txt The ls.txt with gzip file compression package and pay attention to suffix specification.tar.gz
    • Decompression withzxvf
  • tar jcvf ls.tar.gz ls.txt The ls.txt file with bzip2 compression package and pay attention to suffix specification.tar.bz2
    • Decompression withjxvf

vi Tool tips

Here Insert Picture Description

  • Under normal mode
    • Here Insert Picture Description
    • Here Insert Picture Description
    • Input 12gjumps to line 12.
    • dd delete a row
    • yy copy a row
    • attached to a line p
    • Search: Under normal input mode /要搜索的词, press the npage
    • Alternatively: [In the command mode by :entering input Command mode. For example, :50,100s/m/M/gthe lines 50 to 100 m is replaced lowercase to uppercase M
    • Revoked:
      • Here Insert Picture Description
  • Save as::w 文件名
  • Here Insert Picture Description
Published 653 original articles · won praise 1016 · Views 730,000 +

Guess you like

Origin blog.csdn.net/ReCclay/article/details/102086121
Recommended