Linux的简单介绍和基础命令(上)

一、Linux简要介绍

  1. Linux命令基础

  2. Linux命令帮助

  3. 目录与文件基本操作

Linux家族

  1. Redhat 红帽 三个认证 (开源但是不免费)---》社区(系统开发者)---》Centos(服务器端)
  2. Ubuntu 最好的客户端系统,开源纯免费(软件开发人群)
  3. Debian ---》kali Linux(专用工具资源占用很少) 树莓派
  4. suse Linux---》ISP(电信,移动,联通) 定制版

shell——Linux系统的一种特殊程序——“翻译官”

用户登录Linux系统时就自动加载一个shell程序,Bash是Linux系统中默认使用的shell程序

Linux的内核是由C语言开发出来的(面向过程的语言),应用程序是用c++开发

编译器—— gcc gcc-c++ jdk(Java的编译器)Python的编译器就是Python2/3

源码文件———》(编译器)——》执行文件

Linux命令的分类

  1. 内部命令

  2. 外部命令

通用的命令行使用格式:

命令字 [选项] [参数] (对应于操作、功能、操作对象)

  1. -单个字符的组合
  2. -- 单词

对root@localhost ~]# 的介绍

  1. root ——当前用户
  2. @ ——分隔符
  3. localhost ——主机名字
  4. ~ ——当前目录位置
  5. #——管理员
  6. $ ——普通用户

路径简介

绝对路径:例如——/etc/sysconfig/network-scripts/

相对路径(以当前所在位置的路径):例如——sysconfig/

家目录:管理员(/root) 普通用户(/home)

根目录: /

二、Linux命令集(结合实例)

cd:切换工作目录

pwd:查看当前所在的绝对目录路径

[root@lokott ~]# cd /etc/sysconfig/network-scripts/  //进入绝对路径下的文件夹
[root@lokott network-scripts]# pwd      //显示当前所在的目录的绝对路径
/etc/sysconfig/network-scripts
[root@lokott network-scripts]# cd - //返回上次进入的目录命令,即cd /etc/sysconfig/network-scripts/
/root
[root@lokott ~]# cd -
/etc/sysconfig/network-scripts
[root@lokott network-scripts]# cd ..    //返回上层目录 
[root@lokott sysconfig]# cd ../../    //返回上两层目录 
[root@lokott /]# 

ls:显示当前目录的内容

  1. -l 显示文件详细信息
  2. -a 查看隐藏文件
  3. -A 查看除了. .. 的隐藏文件
  4. -d 显示本目录的信息
  5. -h 友好形式显示带有单位的信息
  6. -R 递归显示
  7. -- color 以颜色区分文件类型
    1. 黑色(数据文件)
    2. 蓝色(目录)
    3. 红色(压缩包)
    4. 绿色(执行文件/命令文件/脚本)
    5. 天蓝色(链接文件)
    6. 黄的(设备文件/磁盘文件)
[root@lokott ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  note  shell  公共  模板  视频  图片  文档  下载  音乐  桌面
[root@lokott ~]# cd shell/
[root@lokott shell]# ls 
1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  hello
[root@lokott shell]# ls -a
.  ..  1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  hello
[root@lokott shell]# ls -A
1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  hello
[root@lokott shell]# ls -l
总用量 24
-rwxr-xr-x. 1 root root 111 10月 25 19:10 1.sh
-rwxr-xr-x. 1 root root 124 10月 25 19:12 2.sh
-rwxr-xr-x. 1 root root 192 10月 25 19:25 3.sh
-rwxr-xr-x. 1 root root 104 10月 25 19:33 4.sh
-rwxr-xr-x. 1 root root 147 10月 25 19:36 5.sh
-rwxr-xr-x. 1 root root  26 10月 25 19:37 6.sh
drwxr-xr-x. 2 root root  18 10月 30 13:53 hello
[root@lokott shell]# ls -R
.:
1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  hello

./hello:
0.sh
[root@lokott shell]# ls -d
.
[root@lokott shell]# ls -ah
.  ..  1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  hello

[root@lokott shell]# ls -lR
.:
总用量 24
-rwxr-xr-x. 1 root root 111 10月 25 19:10 1.sh
-rwxr-xr-x. 1 root root 124 10月 25 19:12 2.sh
-rwxr-xr-x. 1 root root 192 10月 25 19:25 3.sh
-rwxr-xr-x. 1 root root 104 10月 25 19:33 4.sh
-rwxr-xr-x. 1 root root 147 10月 25 19:36 5.sh
-rwxr-xr-x. 1 root root  26 10月 25 19:37 6.sh
drwxr-xr-x. 2 root root  18 10月 30 13:53 hello

./hello:
总用量 0
-rwxrwxrwx. 1 root root 0 10月 30 13:53 0.sh
[root@lokott shell]# 

alias:给命令取一个别名

du:统计目录及文件空间占用情况

  1. -a
  2. -h 友好显示
  3. -s

which: 查找命令存放目录

  1. 搜索范围由环境变量PATH决定

mkdir:创建目录

  1. -p递归嵌套创建

touch:创建文件

[root@lokott shell]# alias c='clear'   //clear是表示清屏相当于Ctrl+l的操作
[root@lokott shell]# which c   
alias c='clear'
    /usr/bin/clear
[root@lokott shell]# which clear
/usr/bin/clear
[root@lokott shell]# mkdir linux
[root@lokott shell]# ls
1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  hello  linux
[root@lokott shell]# touch 0.sh
[root@lokott shell]# ls
0.sh  1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  hello  linux
[root@lokott shell]# du -ah
4.0K    ./1.sh
4.0K    ./2.sh
4.0K    ./3.sh
4.0K    ./4.sh
4.0K    ./5.sh
4.0K    ./6.sh
0   ./hello/0.sh
0   ./hello
0   ./linux
0   ./0.sh
24K .
[root@lokott shell]# du -sh
24K .
[root@lokott shell]# du -as             //不可以设置选项为-as(h)
du: 不能既显示总用量,同时又显示每个项目
Try 'du --help' for more information.
[root@lokott shell]# 
[root@lokott shell]# mkdir -p  /2019/2018/2017   //连续创建文件夹
[root@lokott shell]# cd /2019/2018/2017/
[root@lokott 2017]# touch {1..10}.txt  //..表示创建连续10个名为1-10的txt文件
[root@lokott 2017]# ls
10.txt  1.txt  2.txt  3.txt  4.txt  5.txt  6.txt  7.txt  8.txt  9.txt

下面的操作过程中会出现文件节点(inode值):文件在磁盘中存储的标识序列
ln:创建链接文件(类似于Windows系统的快捷方式)

  1. 软链接:相当于快捷方式 -s
  2. 硬链接:给文件取别名(无法创建硬链接文件夹)
[root@lokott shell]# ln -s 1.sh 8.sh
[root@lokott shell]# ln 1.sh 10.sh
[root@lokott shell]# ls -l
总用量 28
-rwxrwxrwx. 1 root root   0 10月 30 13:59 0.sh
-rwxr-xr-x. 2 root root 111 10月 25 19:10 10.sh  //硬链接
-rwxr-xr-x. 2 root root 111 10月 25 19:10 1.sh
-rwxr-xr-x. 1 root root 124 10月 25 19:12 2.sh
-rwxr-xr-x. 1 root root 192 10月 25 19:25 3.sh
-rwxr-xr-x. 1 root root 104 10月 25 19:33 4.sh
-rwxr-xr-x. 1 root root 147 10月 25 19:36 5.sh
-rwxr-xr-x. 1 root root  26 10月 25 19:37 6.sh
lrwxrwxrwx. 1 root root   4 10月 30 14:07 8.sh -> 1.sh  //软链接
drwxr-xr-x. 2 root root  18 10月 30 13:53 hello
drwxr-xr-x. 2 root root   6 10月 30 13:59 linux
[root@lokott shell]# ls -ih   //显示文件节点值的大小
19397655 0.sh  20564913 10.sh  20564913 1.sh  20564915 2.sh  20564917 3.sh  20564916 4.sh  20564918 5.sh  20564919 6.sh  19134334 8.sh  20565286 hello  35183604 linux
//上面文件左边的就是该文件的文件节点(inode值)软链接与源文件的文件节点是非一致的,而硬链接的文件节点与源文件是一致的 

cp :复制文件或目录 源|目标

  1. -f 不询问
  2. -i 询问是否覆盖原有
  3. -p 保持源文件的用户权限不变,权限高用户使用
  4. -r 递归复制

rm:删除

  1. -i:默认提醒
  2. -rf :强制递归删除

mv:移动文件或目录

[root@lokott shell]# cd hello/
[root@lokott hello]# ls
0.sh
[root@lokott hello]# cp ../5.sh .
[root@lokott hello]# ls
0.sh  5.sh
[root@lokott hello]# cp -i ../5.sh .
cp:是否覆盖"./5.sh"? yes
[root@lokott hello]# cp -f ../5.sh .    //猜测被alias了
cp:是否覆盖"./5.sh"? y
[root@lokott hello]# 
[root@lokott hello]# which cp     //查看cp命令果然是被alias更改了
alias cp='cp -i'
    /usr/bin/cp
[root@lokott hello]# cp -r ../linux/ .   //递归复制上层路径linux文件夹的所有内容到当前路径(目前无内容)
[root@lokott hello]# ls
0.sh  5.sh  linux
[root@lokott hello]# cd linux/
[root@lokott linux]# ls
[root@lokott linux]# mkdir 2020         //创建文件夹
[root@lokott linux]# ls
2020
[root@lokott linux]# cd 2020/
[root@lokott 2020]# touch 2.txt         //创建文件
[root@lokott 2020]# cd ../../
[root@lokott hello]# ls
0.sh  5.sh  linux
[root@lokott hello]# mv linux/ ../          //移动文件夹
mv:是否覆盖"../linux"? y
[root@lokott hello]# cd ..
[root@lokott shell]# ls
0.sh  10.sh  1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  8.sh  hello  linux
[root@lokott shell]# ls -l linux/
总用量 0
drwxr-xr-x. 2 root root 19 10月 30 14:15 2020
[root@lokott shell]# cp -r linux/  hello/   //递归复制linux文件夹的所有内容到hello文件夹中
[root@lokott shell]# cd hello/
[root@lokott hello]# ls
0.sh  5.sh  linux
[root@lokott hello]# ls -l linux/
总用量 0
drwxr-xr-x. 2 root root 19 10月 30 14:16 2020
[root@lokott hello]# ls -lR linux/          //递归查看拷贝过来的文件夹的信息
linux/:
总用量 0
drwxr-xr-x. 2 root root 19 10月 30 14:16 2020

linux/2020:
总用量 0
-rw-r--r--. 1 root root 0 10月 30 14:16 2.txt

通配符

  1. ?表示一个

  2. *表示多个

find:查找文件或目录

​ find 【查找范围】【选项】[表达式]

  1. -name:根据目标名字查找
  2. -type:根据文件类型查找
  3. -size:根据大小查找
  4. -user:根据文件的用户所有者查找
[root@lokott hello]# find . -name "*.sh"  //*号表示通配符
./0.sh
./5.sh
[root@lokott hello]# find . -type f
./0.sh
./5.sh
./linux/2020/2.txt
[root@lokott hello]# find . -size -10k
.
./0.sh
./5.sh
./linux
./linux/2020
./linux/2020/2.txt
./ifcfg-ens33
[root@lokott hello]# find . -size -10k | du -ah
0   ./0.sh
4.0K    ./5.sh
0   ./linux/2020/2.txt
0   ./linux/2020
0   ./linux
4.0K    ./ifcfg-ens33
8.0K    .

centos7系统启动的命令清单

1. init 0 关机
2. init 1 单用户模式(系统维护,破解密码)
3. init 2 多用户模式无网络
4. init 3 多用户模式有网络  *
5. init 4 保留
6. init 5多用户模式图形化界面有网络
7. init 6 重启 (reboot)

下篇链接:https://blog.51cto.com/14557673/2446516

猜你喜欢

转载自blog.51cto.com/14557673/2446511