1. Shell
Shell是系统的用户界面,提供了用户与内核进行交互操作的一种接口。它接收用户输入的命令并把它送入内核去执行 [1] 。
实际上Shell是一个命令解释器,它解释由用户输入的命令并且把它们送到内核。不仅如此,Shell有自己的编程语言用于对命令的编辑,它允许用户编写由shell命令组成的程序。Shell编程语言具有普通编程语言的很多特点,比如它也有循环结构和分支控制结构等,用这种编程语言编写的Shell程序与其他应用程序具有同样的效果。 (引自百度百科Linux Shell 词条)
Bourne Again shell (bash),参考链接:https://www.cnblogs.com/hihtml5/p/9272751.html
prompt:命令行提示符, 如图.prompt。通常包括user name(root)、machine name (local host)或ip address、current woking directory(~)、#或$, 其中#代表super user,$代表common user。切换命令为:su(common user切换到super user),su xxx(super user切换到common user,其中xxx为用户名)
2. Linux常用命令(主要基于CentOS 8)
2.1 (通用)
使用键盘的上箭头和下箭头查看上一条命令或下一条命令。使用tab键补全文件路径。
2. 2 Working with directories
pwd: print working directory
cd: change woking directory
cd /absolute path
cd .. :current directory‘s parent directory
cd~ : change to home directory. Different user has different home directory.
注意区分文件类型,如图.file type。蓝色为directory(文件名前有前缀d),白色为common file。
cd relativepath/
cd - :go back to previous directory
ls : list the content of the current directory
ls -a : list all the files and directories of the current directory
ls -l : can show the detail of the file
ll : 等于命令ls -l
ls -al : can show the hidden file
ls -h : can show time of the file
mkdir : create directory
mkdir -p : create directory with multiple hierarchy
rmdir : delete directory
rmdir -p : delete directory with multiple hierarchy
rm -r : 和 rmdir 不同, rm -r 可以在文件夹中有文件的情况下删除这个文件夹. 比如我的 folder1 里有 file1 和 file2 两个文件, 就可以执行指令 rm -r folder1
2.3.file
EVERYTHING is file. All the files in Linux are case sensitive.
file : 查看file类型
touch :创建一个空的file
touch -t : 创建一个空的file并设置时间
rm : delete file
rm -rf : delete directory
rm -i 、 rm -rfi : 删除前询问是否确认删除
cp : copy file
cp -r : copy directory
mv : move file or directory
其他命令:
mv -i : 默认选项,当目标文件存在时,提示是否覆盖
[root@localhost test]# mv -b a/aa b/
mv: overwrite `b/aa'? y
[root@localhost test]# ls b
aa aa~ bb
mv -b :当目标文件存在时,先进行备份再覆盖
[root@localhost test]# mv -b a/aa b/
mv: overwrite `b/aa'? y
[root@localhost test]# ls b
aa aa~ bb
mv -f :当目标文件存在时,强制覆盖
[root@localhost test]# mv -f a/aa b/
[root@localhost test]# ls b
aa bb
mv -t :先指定目标,在制定源
[root@localhost test]# mv -t b/ a/aa
mv: overwrite `b/aa'? y
[root@localhost test]# ls a b
a:
bb
b:
aa bb
mv -v:显示过程
[root@localhost test]# mv -fv a/aa b/
`a/aa' -> `b/aa'
2.4 file contents
head : 展示file的前十行
head -x :展示file的前x行
tail :展示file的后十行
tail -x :展示file的后x行
cat :concatenate 连接展示多个文件的内容
cat > filename : 创建文件并写入文件内容
补充:echo (参考http://www.zsythink.net/archives/96/)
more 、 less : more功能类似 cat ,cat命令是整个文件的内容从上到下显示在屏幕上。 more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会往回(back)一页显示,而且还有搜寻字串的功能 。more命令从前向后读取文件,因此在启动时就加载整个文件。less 工具也是对文件或其它输出进行分页显示的工具,应该说是linux正统查看文件内容的工具,功能极其强大。less 的用法比起 more 更加的有弹性。 在 more 的时候,我们并没有办法向前面翻, 只能往后面看,但若使用了 less 时,就可以使用 [pageup] [pagedown] 等按 键的功能来往前往后翻看文件,更容易用来查看一个文件的内容!除此之外,在 less 里头可以拥有更多的搜索功能,不止可以向下搜,也可以向上搜。
strings : print the strings of printable characters in files
3. FHS(Filesystem Hierarchy Standard)
root directory: /
binary directories: /bin /sbin they share the same library located in /lib /lib64
/opt: store optional software
/boot: contains all the files needed to boot the computer
/ect: contains all the machine configuration files
/home: user can store personal or project data in this directory
/root: default location for personal data and profile of root user
/media: serves as a mount point for removable media devices, such as digital disk
/mnt: should be empty, and should only be used fo temporary mount points
/tmp: application and user should use this directory to store temporary data when needed
/dev: device files in the device library appears to be ordinary files
/proc: is a process filesystem, is a mean of interact with directory
/usr: unix system resources, contains shareable readonly data
/var: variable data, unpredictable in size, (like log, cache...)
4. Shall expansion
bash: Bourne again shell
echo 命令: echo the input it receives
也可以实现其他一些功能,比如
type命令:使用type+命令来查询某个命令的类型(buildin,external)比如:type cd
which命令:will search for binaries in the $PATH
$PATH变量: 当执行一个命令时,linux会在$PATH变量中寻找这个命令
env命令: get all the information of your environment, display a list of exported variable
pipelines命令:| send standard input and output it.
filters:pipelines are often used to perform complex operations on data, it's possible to put several commands into one pipeline, and these commands called filters. (A very important filter :grep,other filters:uniq,sort...)
5. Permission
id命令:get user information
文件名称分group,例如-rw-r--r--有三个group,不同的group代表的含义:
rw- : owner
第一个r-- :group
第二个r-- :world
r : read
w : write
x : execute
-rwx------ : a regular file, which is readable, writable, excutable only by the file owner.
Octal Binary Mode
0 000 ---
1 001 --x
2 010 -w-
3 011 -wx
4 100 r--
5 101 r-x
6 110 rw-
7 111 rwx
chmod命令: change file mode(permission)
chmod u+x(第一组) chmod u-x chmod g-x(第二组) chmod o+x (第三组)
chmod a+x(所有组) chmod 777 chmod 641 chmod go=rw
6. user and group
三种user: super user, virtual user, common user
useradd 命令:创建新的用户
userdel命令:删除用户
passwd命令:设置用户密码
两种group:private group,standard group
groupadd:创建新的group
groupdel:删除group
7. vi/vim
vim == vi improved, for many linux system they are the same.
i:进入insert模式,可以插入文件内容,可以使用esc键退出insert模式。
:q : 退出但不保存
:q! :强制退出
:wq : 退出并保存
:wq! :退出并强制保存
:w !sudo tee % :在vim中保存正在编辑的文件而不需要必要的权限
x(退出insert模式后): delete the characters after the cursor
X(退出insert模式后) : delete the characters before the cursor
r(退出insert模式后) : replace
p(退出insert模式后) : paste
xp(退出insert模式后) : swish two characters
8. user operations
whomi命令:display current user name
who命令:get information about who is logged on the system
who am i命令:get user information of current session
w命令:who is logged on and what they're doing
su命令:切换到其他用户进行操作,但是环境不会改变,$PATN变量仍然为当前登录用户的$PATH变量值,exit切换回当前登录用户
su - 命令:切换到其他用户进行操作,环境改变,$PATN变量变为切换后的用户的$PATH变量值。
sudo命令:尽管 sudo 命令是以目标用户(默认情况下是 root 用户)的身份执行命令,但是它们会使用 sudoer 所配置的用户名来记录是谁执行命令。而 su 命令是无法直接跟踪记录用户切换到 root 用户之后执行了什么操作。
9. Process
区分process和thread:参考链接https://blog.csdn.net/honglin_ren/article/details/35839979
init.init ect/ daemon process
ps命令,如ps x等
TTY:teletype
top命令: show a lot of process information
jobs命令:list jobs
kill -l xxx命令(kill -INT xxx命令):kill a process,其中xxx为PID
10. Package Management
Package management is a method to maintain software installment. Different distributions use different package systems.
Package management system usually contains two types of tools: low-level, high-level.
low-level high-level
ubantu/Debian dpkg apt-get, aptitude
redhat/centos rpm yum
update package命令: dpkg --install
centos:rpm -U
package search命令: ubantu为apt-get update
readhet为yum search
remove package命令:ubantu为apt-get remove
readhet为 yam erase
11. Archiving and backup
gzip和gunzip 命令:compress or expend files
gzip -c :write to standard output and keep original files
gzip -t : test the integrity of the file
gzip -v : give a message
bzip2和bunzip2 : a block sorting file compressor
tar : tape archiving utility
tar -c : create archive from a list of files or directories
tar -x : extract an archive
tar -r : appen a specified path names to the end of an archive
tar -t : list the content of archive
tar -f : file name type of the archive
tar -v : verbose information
zip : pack and compress files
12. The environment
printenv命令:get information of the configuration item
set命令:display both shell and environment variables and any defined functions
variables : HOME PATH DISPLAY EDITOR SHELL USER PS1(means prompt string 1)
/etc/profile : a global configuration script that applies to all users
~/ .bash_profile : a user personal startup file
~/ .bash_login : can add initial login information to this file,if ~/ .bash_profile is not found, linux will read this file instead
~/ .profile: if ~/ .bash_profile and ~/ .bash_login are both not found, linux will read this file
/etc/bash.bashrc : global configuration script that applied to all users
~/ .bashrc : users' personal startup file
13. 软件安装
详见安装文章。
14. apache
apache 安装指令:
yum install -y httpd
启动指令:
systemctl start httpd
查看运行状态:
systemctl status httpd
自动启动apache指令:
systemctl enable httpd.service
现在可以输入网址localhost访问apache首页了。
编写html并访问。首先,cd /var/www/html 然后vi home.htm 编写html
保存并退出后在虚拟机中访问网址localhost/home.html
如果要在本地访问,需要在linux虚拟机终端中依次执行以下指令配置防火墙:
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
然后在本地浏览器输入网址 http://linux主机ip/home.html就可以访问了。