01Linux基本命令和概述

目录

目录结构 

工具

清屏  clear

查看历史命令  history

退出 exit 

文档查看 man

使用说明  --help

关机

关机  shotdown

同步数据

同步数据 sync

重启

重启 reboot

目录管理

列出目录 ls 

切换目录 cd

显示当前目录 pwd

创建目录 mkdir

删除目录 rmdir

文件管理

复制文件或目录  cp

删除文件或目录 rm

移动文件或者目录 mv  (重命名)

创建文件  touch /vim

编辑文件  echo / vim

文件内容查看(重) 

cat  正向查看

tac  反向查看

nl 看行号

more 翻页查看 (空格翻页,enter向下看一行,:f行号)

less 翻页 (空格翻页,上下键翻动页面, q退出,/查找)

head 显示头部几行 -n控制行数

tail 显示尾部几行  -n控制行数

链接

拓展 Linux链接(了解) 硬链接 ln   软链接 ln-s  

基本属性 

修改文件属性

1. chgrp:更改文件属组 (一般不用)

2.chown:更改文件属主,也可以同时更改文件属组 (一般不用)

3. chmod:更改文件9个属性 (必须掌握)

网络配置目录   CentOS7

查看网络配置 ifconfig


😹 作者: gh-xiaohe
😻 gh-xiaohe的博客
😽 觉得博主文章写的不错的话,希望大家三连(✌关注,✌点赞,✌评论),多多支持一下!!!

Linux中一切皆文件(文件:读写执行(查看,创建,移动,删除,复制,编辑))
Linux多用户操作,权限(用户、用户组)
Linux是一个系统(磁盘,进程)

Liunx继承Unix以网络为核心的设计思想,是一个性能稳定的多用户网络操作系统

关机之前必须做操作  sync 同步数据

系统的目录结构:

        1.一切皆文件

        2.根目录 / 所拥的目录都挂载在这个节点下

Linux中没有错误就代表操作成功

LInux系统是典型的多用户管理系统

 通常服务器使用LAMP(Linux+Apache+MySQL+pHP)或LNMP(Linux+Nginx+MySQL+PHP)组合。

安全组:

目录结构 

 Linux 的一切资源都挂载在 / 节点下。

  • /bin:Binary(二进制)的缩写,该目录存放着最经常使用的命令。
  • /boot: 启动 Linux 时使用的一些核心文件,包括一些连接文件以及镜像文件。(不要动)
  • /dev : Device(设备)的缩写, 存放的是外部设备(访问设备的方式和访问文件的方式是相同的)。
  • /etc: 用来存放所有的系统管理所需要的配置文件和子目录。
  • /home:用户的主目录。每个用户都有一个自己的目录,一般该目录名是以用户的账号命名的。
  • /lib:系统最基本的动态连接共享库。其作用类似于 Windows 里的 DLL 文件。(不要动)
  • /lost+found:一般情况下是空的,当系统非法关机后,这里就存放了一些文件。(存放突然关机的一些文件)
  • /media:系统会自动识别一些设备,例如U盘、光驱等等,当识别后,会把识别的设备挂载到这个目录下。
  • /mnt:供用户临时挂载别的文件系统,我们可以将光驱挂载在该目录上,然后进入该目录就可以查看光驱里的内容了。  (把一些本地的文件挂载在这个文件下)
  • /opt:主机额外安装软件所摆放的目录。比如安装一个 Oracle 数据库就可以放到这个目录下。默认是空的。
  • /proc:虚拟的目录,它是系统内存的映射,可以通过直接访问这个目录来获取系统信息。(不用管)
  • /root:系统管理员,也称作超级权限者的用户主目录。
  • /sbin:s 就是 super user 的意思,这里存放的是系统管理员使用的系统管理程序。
  • /srv:服务启动之后需要提取的数据。
  • /sys:这是 Linux2.6 内核的一个很大的变化。该目录下安装了 2.6 内核中新出现的一个文件系统 sysfs。
  • /tmp:用来存放临时文件。
  • /usr:用户的应用程序和文件都放在这个目录下,类似于 Windows 下的 program files 目录。
    • /bin: 系统用户使用的应用程序。
    • /sbin: 超级用户使用的比较高级的管理程序和系统守护程序。
    • /src: 内核源代码默认的放置目录。
  • /var:存放着在不断扩充着的东西,一般将那些经常被修改的目录放在这个目录下。包括各种日志文件。
  • /run:一个临时文件系统,存储系统启动以来的信息。当系统重启时,这个目录下的文件应该被删掉或清除。
  • /www: 存放服务器网站相关的资源,环境,网站的项目

 

工具

清屏  clear

这里只是将之前的内容全部滚到最上面隐藏起来,向上滚动滚轮是可以看到之前的内容的。

查看历史命令  history

退出 exit 

退出命令行输入终端,并不是退出系统,对系统没有影响 

文档查看 man

 Linux 系统可以使用 man 命令 来查看各个命令的使用文档。

[root@sail ~]# man ls
LS(1)                                                                                           User Commands                                                                                           LS(1)
NAME
       ls - list directory contents
SYNOPSIS
       ls [OPTION]... [FILE]...
DESCRIPTION
       List information about the FILEs (the current directory by default).  Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
       Mandatory arguments to long options are mandatory for short options too.
       -a, --all
              do not ignore entries starting with .
       -A, --almost-all
              do not list implied . and ..
       --author
              with -l, print the author of each file
       -b, --escape
              print C-style escapes for nongraphic characters
       --block-size=SIZE
              scale sizes by SIZE before printing them; e.g., '--block-size=M' prints sizes in units of 1,048,576 bytes; see SIZE format below
       -B, --ignore-backups
              do not list implied entries ending with ~
       -c     with -lt: sort by, and show, ctime (time of last modification of file status information); with -l: show ctime and sort by name; otherwise: sort by ctime, newest first
       -C     list entries by columns
       --color[=WHEN]
              colorize the output; WHEN can be 'never', 'auto', or 'always' (the default); more info below
       -d, --directory
              list directories themselves, not their contents
       -D, --dired
              generate output designed for Emacs' dired mode
       -f     do not sort, enable -aU, disable -ls --color
       -F, --classify
              append indicator (one of */=>@|) to entries
       --file-type
              likewise, except do not append '*'

使用说明  --help

[root@sail ~]# ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..
      --author               with -l, print the author of each file
  -b, --escape               print C-style escapes for nongraphic characters
      --block-size=SIZE      scale sizes by SIZE before printing them; e.g.,
                               '--block-size=M' prints sizes in units of
                               1,048,576 bytes; see SIZE format below
  -B, --ignore-backups       do not list implied entries ending with ~
  -c                         with -lt: sort by, and show, ctime (time of last
                               modification of file status information);
                               with -l: show ctime and sort by name;
                               otherwise: sort by ctime, newest first
  -C                         list entries by columns
      --color[=WHEN]         colorize the output; WHEN can be 'never', 'auto',
                               or 'always' (the default); more info below
  -d, --directory            list directories themselves, not their contents
  -D, --dired                generate output designed for Emacs' dired mode
  -f                         do not sort, enable -aU, disable -ls --color
  -F, --classify             append indicator (one of */=>@|) to entries
      --file-type            likewise, except do not append '*'
      --format=WORD          across -x, commas -m, horizontal -x, long -l,
                               single-column -1, verbose -l, vertical -C
      --full-time            like -l --time-style=full-iso
  -g                         like -l, but do not list owner
      --group-directories-first
                             group directories before files;
                               can be augmented with a --sort option, but any
                               use of --sort=none (-U) disables grouping
  -G, --no-group             in a long listing, don't print group names
  -h, --human-readable       with -l, print sizes in human readable format
                               (e.g., 1K 234M 2G)
      --si                   likewise, but use powers of 1000 not 1024
  -H, --dereference-command-line
                             follow symbolic links listed on the command line
      --dereference-command-line-symlink-to-dir
                             follow each command line symbolic link
                               that points to a directory
      --hide=PATTERN         do not list implied entries matching shell PATTERN
                               (overridden by -a or -A)
      --indicator-style=WORD  append indicator with style WORD to entry names:
                               none (default), slash (-p),
                               file-type (--file-type), classify (-F)
  -i, --inode                print the index number of each file
  -I, --ignore=PATTERN       do not list implied entries matching shell PATTERN
  -k, --kibibytes            default to 1024-byte blocks for disk usage
  -l                         use a long listing format
  -L, --dereference          when showing file information for a symbolic
                               link, show information for the file the link
                               references rather than for the link itself
  -m                         fill width with a comma separated list of entries
  -n, --numeric-uid-gid      like -l, but list numeric user and group IDs
  -N, --literal              print raw entry names (don't treat e.g. control
                               characters specially)
  -o                         like -l, but do not list group information
  -p, --indicator-style=slash
                             append / indicator to directories
  -q, --hide-control-chars   print ? instead of nongraphic characters
      --show-control-chars   show nongraphic characters as-is (the default,
                               unless program is 'ls' and output is a terminal)
  -Q, --quote-name           enclose entry names in double quotes
      --quoting-style=WORD   use quoting style WORD for entry names:
                               literal, locale, shell, shell-always, c, escape
  -r, --reverse              reverse order while sorting
  -R, --recursive            list subdirectories recursively
  -s, --size                 print the allocated size of each file, in blocks
  -S                         sort by file size
      --sort=WORD            sort by WORD instead of name: none (-U), size (-S),
                               time (-t), version (-v), extension (-X)
      --time=WORD            with -l, show time as WORD instead of default
                               modification time: atime or access or use (-u)
                               ctime or status (-c); also use specified time
                               as sort key if --sort=time
      --time-style=STYLE     with -l, show times using style STYLE:
                               full-iso, long-iso, iso, locale, or +FORMAT;
                               FORMAT is interpreted like in 'date'; if FORMAT
                               is FORMAT1<newline>FORMAT2, then FORMAT1 applies
                               to non-recent files and FORMAT2 to recent files;
                               if STYLE is prefixed with 'posix-', STYLE
                               takes effect only outside the POSIX locale
  -t                         sort by modification time, newest first
  -T, --tabsize=COLS         assume tab stops at each COLS instead of 8
  -u                         with -lt: sort by, and show, access time;
                               with -l: show access time and sort by name;
                               otherwise: sort by access time
  -U                         do not sort; list entries in directory order
  -v                         natural sort of (version) numbers within text
  -w, --width=COLS           assume screen width instead of current value
  -x                         list entries by lines instead of by columns
  -X                         sort alphabetically by entry extension
  -1                         list one file per line
SELinux options:
  --lcontext                 Display security context.   Enable -l. Lines
                             will probably be too wide for most displays.
  -Z, --context              Display security context so it fits on most
                             displays.  Displays only mode, user, group,
                             security context and file name.
  --scontext                 Display only security context and file name.
      --help     display this help and exit
      --version  output version information and exit
SIZE is an integer and optional unit (example: 10M is 10*1024*1024).  Units
are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).
Using color to distinguish file types is disabled both by default and
with --color=never.  With --color=auto, ls emits color codes only when
standard output is connected to a terminal.  The LS_COLORS environment
variable can change the settings.  Use the dircolors command to set it.
Exit status:
 0  if OK,
 1  if minor problems (e.g., cannot access subdirectory),
 2  if serious trouble (e.g., cannot access command-line argument).
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'ls invocation'

关机

关机  shotdown

开机会启动许多程序。在 Windows 叫做服务(service),在 Linux 叫做守护进程(daemon) 

关机命令:showdown

关机之前必须做操作  sync 同步数据

sync # 将数据由内存同步到硬盘中。
 
shutdown # 关机指令,你可以man shutdown 来看一下帮助文档。例如你可以运行如下命令关机:
 
shutdown –h 10 # 这个命令告诉大家,计算机将在10分钟后关机
 
shutdown –h now # 立马关机
 
shutdown –h 20:25 # 系统会在今天20:25关机
 
shutdown –h +10 # 十分钟后关机
 
shutdown –r now # 系统立马重启
 
shutdown –r +10 # 系统十分钟后重启
 
reboot # 就是重启,等同于 shutdown –r now
 
halt # 关闭系统,等同于shutdown –h now 和 poweroff

同步数据

同步数据 sync

将数据有内存同步到硬盘中 

重启

重启 reboot

目录管理

列出目录 ls 

  • -a:全部的文件,连同隐藏文件(开头为 . 的文件) 一起列出来(常用)。
  • -l:长数据串列出,包含文件的属性与权限等等数据(常用)。
  • -i:显示文件的 inode 节点信息。 

切换目录 cd

cd 目录名 (绝对路径都是以 / 开头,相对路径,对于当前目录改如何寻找  ../../)

[root@gh ~]# cd /     当前目录
[root@gh /]# cd ..    返回上一级目录

显示当前目录 pwd

 单纯显示出目前的工作目录

[root@sail ~]# pwd
/root

如果是链接,要显示真实地址,可以使用 -P 参数

[root@sail ~]# cd /bin
[root@sail bin]# pwd
/bin
[root@sail bin]# pwd -P
/usr/bin

创建目录 mkdir

 mkdir [-mp] 目录名称

  • -m :配置文件的权限。直接配置,不需要考虑默认权限(umask)。
  • -p :帮助你直接将所需要的目录(包含上一级目录)递归创建起来。
# 进入我们用户目录下
[root@kuangshen /]# cd /home
 
# 创建一个 test 文件夹
[root@kuangshen home]# mkdir test
 
# 创建多层级目录
[root@kuangshen home]# mkdir test1/test2/test3/test4
mkdir: cannot create directory ‘test1/test2/test3/test4’:
No such file or directory  # <== 没办法直接创建此目录啊!
 
# 加了这个 -p 的选项,可以自行帮你创建多层目录!
[root@kuangshen home]# mkdir -p test1/test2/test3/test4

删除目录 rmdir

# 可直接删除掉,没问题
[root@kuangshen home]# rmdir test
 
# 因为尚有内容,所以无法删除!
[root@kuangshen home]# rmdir test1
rmdir: failed to remove ‘test1’: Directory not empty
 
# 利用 -p 这个选项,立刻就可以将 test1/test2/test3/test4 依次删除。
[root@kuangshen home]# rmdir -p test1/test2/test3/test4

 注意:这个 rmdir 仅能删除空的目录,如果下面存在文件,需要先删除文件,递归删除多个目录-p参数即可

文件管理

复制文件或目录  cp

cp [-adfilprsu] 来源(source) 目标(destination)

 

删除文件或目录 rm

  • -f :就是 force 的意思,忽略不存在的文件,不会出现警告信息;  强制删除
  • -i :互动模式,在删除前会询问使用者是否动作
  • -r :递归删除啊!最常用在目录的删除了!这是非常危险的选项!!!

移动文件或者目录 mv  (重命名)

-f 强制

-u 只替换已经更新过的文件 

创建文件  touch /vim

编辑文件  echo / vim

文件内容查看(重) 

Linux系统中使用以下命令来查看文件的内容:

  • cat 由第一行开始显示文件内容   用来读取文章,或者读取配置文件
  • tac 从最后一行开始显示,可以看出 tac 是 cat 的倒着写!
  • nl 显示的时候,顺道输出行号!     看代码
  • more 一页一页的显示文件内容(空格翻页,enter向下看一行,:f显示行号)
  • less 与 more 类似,但是比 more 更好的是,他可以往前翻页!                       (空格翻页,上下键翻页,退出 q命令,查找字符串 / 向下查询的字符 ?向上查询 n搜寻下一个 N像上)
  • head 只看头几行  -n控制行数
  • tail 只看尾巴几行  -n控制行数

cat  正向查看

tac  反向查看

nl 看行号

more 翻页查看 (空格翻页,enter向下看一行,:f行号)

less 翻页 (空格翻页,上下键翻动页面, q退出,/查找)

 

 

head 显示头部几行 -n控制行数

tail 显示尾部几行  -n控制行数

链接

拓展 Linux链接(了解) 硬链接 ln   软链接 ln-s  

Linux 链接分两种,硬链接软链接 

硬链接:A---B,假设B是A的硬链接,那么他们两个指向了同一个文件!允许一个文件拥有多个路径,用户可以通过这种机制建立硬链接到一些重要文件上,防止误删!

软链接:类似Window下的快捷方式,删除的源文件,快捷方式也访问不了!

创建连接In命令!

touch命令创建文件!

echo输入字符串

基本属性 

在Linux中我们可以使用ll或者ls –l命令来显示一个文件的属性以及文件所属的用户和组,如:

在Linux中第一个字符代表这个文件是目录、文件或链接文件等等:

  • 当为[ d ]则是目录

  • 当为[ - ]则是文件;

  • 若是[ l ]则表示为链接文档 ( link file );

  • 若是[ b ]则表示为装置文件里面的可供储存的接口设备 ( 可随机存取装置 );

  • 若是[ c ]则表示为装置文件里面的串行端口设备,例如键盘、鼠标 ( 一次性读取装置 )。

接下来的字符中,以三个为一组,且均为『rwx』 的三个参数的组合。

其中,[ r ]代表可读(read)、[ w ]代表可写(write)、[ x ]代表可执行(execute)。

要注意的是,这三个权限的位置不会改变,如果没有权限,就会出现减号[ - ]而已。

每个文件的属性由左边第一部分的10个字符来确定(如下图):

从左至右用0-9这些数字来表示。

第0位确定文件类型,第1-3位确定属主(该文件的所有者)拥有该文件的权限。第4-6位确定属组(所有者的同组用户)拥有该文件的权限,第7-9位确定其他用户拥有该文件的权限。

其中:

第1、4、7位表示读权限,如果用"r"字符表示,则有读权限,如果用"-"字符表示,则没有读权限;

第2、5、8位表示写权限,如果用"w"字符表示,则有写权限,如果用"-"字符表示没有写权限;

第3、6、9位表示可执行权限,如果用"x"字符表示,则有执行权限,如果用"-"字符表示,则没有执行权限。

 

修改文件属性

1. chgrp:更改文件属组 (一般不用)

chgrp [-R] 属组名 文件名

-R:递归更改文件属组,就是在更改某个目录文件的属组时,如果加上-R的参数,那么该目录下的所有文件的属组都会更改。

2.chown:更改文件属主,也可以同时更改文件属组 (一般不用)

chown [–R] 属主名 文件名
chown [-R] 属主名:属组名 文件名

3. chmod:更改文件9个属性 (必须掌握)

chmod [-R] xyz 文件或目录

Linux文件属性有两种设置方法,一种是数字(常用),一种是符号。

Linux文件的基本权限就有九个,分别是owner/group/others三种身份各有自己的read/write/execute权限。

文件的权限字符为:『-rwxrwxrwx』, 这九个权限是三个三个一组的!其中,我们可以使用数字来代表各个权限,各权限的分数对照表如下:

数字 

r:4      w:2         x:1
可读可写不可执行  rw- 6
可读可写可执行    rw- 7

chmod 777  文件赋予所有用户可读可写可执行

每种身份(owner/group/others)各自的三个权限(r/w/x)分数是需要累加的,例如当权限为:[-rwxrwx—] 分数则是:

  • owner = rwx = 4+2+1 = 7

  • group = rwx = 4+2+1 = 7

  • others= — = 0+0+0 = 0

网络配置目录   CentOS7

                cd /etc/sysconfig/network-scripts/

查看网络配置 ifconfig

 Window   是 ipconfig 不一样 有区别

  • 16
    点赞
  • 76
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gh-xiaohe

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值