Linux basic and common commands

The first week focused on knowledge summary

A. Computer Basics

1. Computer Organization

  The computer system hardware (Hardware) and software (Software) system composed of two parts
  von Neumann architecture: computer hardware five major operator, controller, memory, input devices and output devices composition

2. Server Category:

2.1 Classification by Size:

  Supercomputers, mainframes, minicomputers, microcomputers.

2.2 Application by functional classification:

  Web servers, database servers, file servers, middleware, application servers, log servers,
monitoring server, version control server, a virtual machine server, mail server, print server,
domain control server, media server, communications server, ERP servers, etc.

2.3 according to shape classification:

  Tower server, blade server, a rack server

2.4 According to CPU architecture Category:

  Non-x86 servers: using RISC (reduced instruction set) or EPIC (Parallel Instruction Code) processor
  x86 server: also known as CISC (complex instruction set) architecture servers, that often speak of PC servers

3. Server Hardware

3.1 Hardware Type:

  1. Motherboard: motherboard generally rectangular circuit board, above the main circuit composed of a computer system is installed, generally BIOS
chip, I / O control chip, a keyboard and a control switch panel connectors, LEDs, connectors, expansion slots, master
card board and other DC power supply connector element
  2. Memory: (1) CPU memory is directly addressable memory space, is made of a semiconductor device. Characterized by memory access speed
Rapidity (2) the external memory: difference hard disk, U disk, floppy disk, optical disc (3) memory and the external memory: memory data is lost after power failure, the external memory power data can be saved. (4) memory bandwidth, the memory bus frequency × = data bus bits / 8
  3. HDD: hard disk interface type: (1) IDE Interface: hard disk interface specification using ATA specification (2) SCSI Interface: applied Minicomputer High-speed data transmission technology (3) SATA interfaces:. Serial ATA, increase the transmission rate, hot swappable (4) SAS interfaces:. Serial Attached SCSI, compatible with the SATA.
  4. array card (RAID cards): improving disk subsystem performance and reliability
  5. Hot Swap: technology and swap hard disk together with RAID technology, the server can recover the data on the failed disk without shutdown state, and does not affect the use of the data network user.

3.2. Storage Networking

----- direct attached storage the DAS (Direct Attached the Storage)
the NAS ----- network attached storage (the Network Attached the Storage)
a SAN ----- storage area network (Storage Area Networks)

3.3. Space

1. User space: User space

  Users run the space program

2. Kernel space: Kernel space

  Space is running the Linux kernel
can execute arbitrary commands, system calls all the resources

4. The server operating system

4.1. Three Operating Systems

1.Windows:
2.Linux:GNU/Linux
3.Unix:1969年Ken Thompson
   System: Bell Lab
   AIX (IBM)
   Solaris (SUN)
   HP-UX (HP)

BSD: (BSRG)Berkeley System Distribution
   NetBSD
   OpenBSD
   FreeBSD

4.2.Linux system

1.起源:完整的类UNIX操作系统,Linux内核+ GNU工具,如:CentOS,Ubuntu,Android  
2.Linux的哲学思想   
一切都是一个文件(包括硬件)   
小型,单一用途的程序   
链接程序,共同完成复杂的任务   
避免令人困惑的用户界面    
配置数据存储在文本中  
3.虚拟机   
3.1.虚拟机:用软件(如:vmware,virtualbox等)模拟硬件   
3.2.使用vmware workstation:
CPU:默认
内存:1G以上,推荐2G
硬盘:一块硬盘,200G
网卡:桥接或仅主机模式
光盘:挂载对应版本的ISO文件   

Two .Linux foundation and help

1. The user logs

root用户:一个特殊的管理帐户,也被称为超级用root已接近完整的系统控制,对系统损害几乎有无限的能力
除非必要,不要登录为root     
普通( 非特权 )用户:权限有限,造成损害的能力比较有限.   

2. Terminal terminal

2.1. Terminal Equipment

键盘鼠标显示器

2.2. Physical terminal (/ dev / console)

控制台console   

2.3 Virtual Terminal. (Tty: teletypewriters, / dev / tty # # to [1-6])

2.4. Graphic terminal (/ dev / tty7)

startx,xwindows   

2.5. Serial terminal (/ dev / ttyS #)

ttyS     

2.6 the pseudo-terminal. (Pty: pseudo-tty, / dev / pts / #)

pty, SSH远程连接

2.7. View the current terminal equipment

tty    

3.shell

3.1 Definitions:
1.Shell是Linux系统的用户界面,提供了用户与内核进行交互操作的一种接口。它接收用户输入的命令并把它送入内核去执行。  
2.shell也被称为LINUX的命令解释器(command interpreter)   
3.shell是一种高级程序设计语言  
3.2.bash shell
1.GNU Bourne-Again Shell(bash)是GNU计划中重要的工具软件之一,目前也是 Linux标准的shell,与sh兼容   
2.显示当前使用的shell:echo ${SHELL}  
cat /etc/shells   
3.3 Command Category
1.内部命令:由shell自带的,而且通过某命令形式提供   
2.外部命令:在文件系统路径下有对应的可执行程序文件,查看路径:which -a |--skip-alias; whereis     
3.2. Common command
1.hash常见用法
hash 显示hash缓存
hash –l 显示hash缓存,可作为输入使用
hash –p path name 将命令全路径path起别名为name
hash –t name 打印缓存中name的路径
hash –d name 清除name缓存
hash –r 清除缓存  
2.alias  
alias NAME='VALUE'   
source /path/to/config_file=./path/to/config_file   
alias rm='mkdir /data/`date +%s` ; mv -t /data/`date +%s`'> /boot/f1  
3.date   
date +%s  
date -d  
hwclock,clock: 显示硬件时钟   
-s, --hctosys 以硬件时钟为准,校正系统时钟
-w, --systohc 以系统时钟为准,校正硬件时钟   
时区:/etc/localtime
显示日历:cal –y   
4.关机:halt, poweroff   
重启:reboot
-f: 强制,不调用shutdown
-p: 切断电源   
关机或重启:shutdown
shutdown [OPTION]... [TIME] [MESSAGE]
-r: reboot
-h: halt
-c:cancel    
TIME:无指定,默认相当于+1(CentOS7)
    now: 立刻,相当于+0
    +m: 相对时间表示法,几分钟之后;例如 +3
    hh:mm: 绝对时间表示,指明具体时间    
4.用户登录信息查看命令   
whoami: 显示当前登录有效用户
who: 系统当前所有的登录会话
w: 系统当前所有的登录会话及所做的操作    
5.screen命令   
创建新screen会话:screen –S [SESSION]
加入screen会话:screen –x [SESSION]
退出并关闭screen会话:exit
剥离当前screen会话:Ctrl+a,d
显示所有已经打开的screen会话:screen -ls
恢复某screen会话:screen -r [SESSION]   
6.echo命令  
语法:echo [-neE][字符串]
选项:-E (默认)不支持 \ 解释功能
-n 不自动换行
-e 启用 \ 字符的解释功能
显示变量   
echo "$VAR_NAM” 变量会替换,弱引用
echo '$VAR_NAME’ 变量不会替换,强引用
三个符号的区别:“ ”‘ ’` `
1.echo “echo $PATH”,输出 echo /etc/passwd:双引号只能识别变量,不能识别命令
2.echo ‘echo $PATH’,输出echo $PATH:变量和命令都不能识别
3.echo `echo $PATH`,输出/etc/passwd:反行单引号变量和命令都能识别   
echo ‘---’ > /sys/class/scsi_host/host0/scan  扫描硬件  
7.history命令  
history [-c] [-d offset] [n] 
history -anrw [filename] 
history -ps arg [arg...]
-c: 清空命令历史
-d offset: 删除历史中指定的第offset个命令
n: 显示最近的n条历史
-a: 追加本次会话新执行的命令历史列表至历史文件
-r: 读历史文件附加到历史列表
-w: 保存历史列表到指定的历史文件
-n: 读历史文件中未读过的行到历史列表
-p: 展开历史参数成多行,但不存在历史列表中
-s: 展开历史参数成一行,附加在历史列表后
环境变量
HISTSIZE:命令历史记录的条数
HISTFILESIZE:命令历史文件记录历史的条数
HISTTIMEFORMAT=“%F %T “ 显示时间  
HISTIGNORE=“str1:str2*:… “ 忽略str1命令,str2开头的历史   
存放在 /etc/profile 或 ~/.bash_profile   
8.帮助命令   
8.1.whatis
显示命令的简短描述
使用数据库
makewhatis | mandb制作数据库
8.2.command --help
COMMAND -h 查看man手册页
man [章节] keyword 搜索man手册 
man –a keyword 列出所有帮助
man -k keyword 列出所有匹配的页面
man -f keyword 相当于whatis  
man –w [章节] keyword 打印man帮助文件的路径
8.3.man帮助info
man COMMAND:使用手册(manual)
8.4.info
info COMMAND:信息页  

III. File Management

1. File System Structure

/boot:引导文件存放目录,内核文件(vmlinuz)、引导加载器(bootloader, grub)
都存放于此目录
/bin:所有用户使用的基本命令;不能关联至独立分区,OS启动即会用到的程序
/sbin:管理类的基本命令;不能关联至独立分区,OS启动即会用到的程序
/lib:启动时程序依赖的基本共享库文件以及内核模块文件(/lib/modules)
/lib64:专用于x86_64系统上的辅助共享库文件存放位置
/etc:配置文件目录
/home/USERNAME:普通用户家目录
/root:管理员的家目录 
/usr: universal shared, read-only data
bin: 保证系统拥有完整功能而提供的应用程序
sbin:
lib:32位使用
lib64:只存在64位系统
include: C程序的头文件(header files)
share:结构化独立的数据,例如doc, man等
local:第三方应用程序的安装位置
bin, sbin, lib, lib64, etc, share  

2. The application part

二进制程序:/bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin
库文件:/lib, /lib64, /usr/lib, /usr/lib64, /usr/local/lib, /usr/local/lib64
配置文件:/etc, /etc/DIRECTORY, /usr/local/etc
帮助文件:/usr/share/man, /usr/share/doc, /usr/local/share/man, 
/usr/local/share/doc     

3. Type

- 普通文件
d 目录文件
b 块设备
c 字符设备
l 符号链接文件
p 管道文件pipe
s 套接字文件socket   

4. common commands

1.cd 改变目录  
切换至父目录: cd ..
切换至当前用户主目录: cd
切换至以前的工作目录: cd -
环境变量:   
PWD:当前目录路径
OLDPWD:上一次目录路径   
2.ls 列出当前目录的内容或指定目录  
ls -a 包含隐藏文件
ls -l 显示额外的信息
ls -R 目录递归通过
ls -ld 目录和符号链接信息
ls -1 文件分行显示
ls –S 按从大到小排序
ls –t 按mtime排序
ls –u 配合-t选项,显示并按atime从新到旧排序
ls –U 按目录存放顺序显示
ls –X 按文件后缀排序   
4.touch命令  
touch [OPTION]... FILE...
-a 仅改变 atime和ctime
-m 仅改变 mtime和ctime
-t [[CC]YY]MMDDhhmm[.ss] 指定atime和mtime的时间戳
-c 如果文件不存在,则不予创建   
5.cp 复制文件和目录   
5.1.cp SRC DEST
SRC是文件:
如果目标不存在:新建DEST,并将SRC中内容填充至DEST中
如果目标存在:
如果DEST是文件:将SRC中的内容覆盖至DEST中
基于安全,建议为cp命令使用-i选项
如果DEST是目录:在DEST下新建与原文件同名的文件,并将SRC中内容
填充至新文件中  
5.2.cp SRC... DEST
SRC... 多个文件
DEST 必须存在,且为目录,其它情形均会出错  
5.3.cp SRC DEST
SRC是目录:此时使用选项:-r
如果DEST不存在:则创建指定目录,复制SRC目录中所有文件至DEST中
如果DEST存在:
如果DEST是文件:报错
如果DEST是目录:  ![](https://s1.51cto.com/images/blog/201907/28/43f791a7edc0c7de27772a667af0f1d0.jpg?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk
5.4.cp常用选项   
-i 覆盖前提示
-n 不覆盖,注意两者顺序
-r, -R 递归复制目录及内部的所有内容
-a 归档,相当于-dR --preserv=all
-d --no-dereference --preserv=links 不复制原文件,只复制链接名
--preserv[=ATTR_LIST]
    mode: 权限
    ownership: 属主属组
    timestamp: 
    links
    xattr
    context
    all   

Guess you like

Origin blog.51cto.com/14451166/2424361