吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1322|回复: 3
收起左侧

[Java 转载] linux教程文件查看方式,软硬连接,vim及账号管理

[复制链接]
黑白客 发表于 2021-3-17 15:19

linux教程
多种文件查看方式学习
软链接和硬链接
vim编译器
账号管理

linux教程

多种文件查看方式学习

  • cat 由第一行开始显示文件内容

  • tac 从最后一行开始显示,可以看出cat 和tac是倒着写的

  • nl 显示的时候,顺便输出行号(常用)

  • more 一页一页的显示文件内容(空格表示翻页,回车表示向下翻一页.   :f 可以显示当前行号)

  • less与more类似,但是比more更好的是,它可以向前翻页
    (在more的基础上添加了 上下键翻行.  

    /if   就是在当前文件中向下查找if这个字符.是输入查看命令之后再里面输入)

    ?if    就是在当前文件中向上查找if这个字符.是输入查看命令之后再里面输入)**

    n就是寻找下一个. N就是寻找上一个

  • head 只看头几行 通过一个  -n  参数. head -n 20 xxx   只看前20行

  • tail 只看尾巴几行 通过一个  -n  参数.  tail -n 20 xxx   只看后20行

cd /etc/sysconfig/network-scripts   就是网络配置文件.ifcfg-eth0就是默认的配置文件

两种查看方式,比如文件过长,我们想倒着查看就可以用tac.下面演示各个查看方式

[root@iZ8vb5yl5m390bo5rw0r8cZ network-scripts]# cat ifcfg-eth0
# Created by cloud-init on instance boot automatically, do not edit.
# If you don't want cloud-init genrated automatically,you can disable it in /etc/cloud/cloud.cfg
# For more information, please refer to: https://help.aliyun.com/document_detail/57803.html
#
BOOTPROTO=dhcp
DEVICE=eth0
ONBOOT=yes
STARTMODE=auto
TYPE=Ethernet
USERCTL=no

[root@iZ8vb5yl5m390bo5rw0r8cZ network-scripts]# tac ifcfg-eth0
USERCTL=no
TYPE=Ethernet
STARTMODE=auto
ONBOOT=yes
DEVICE=eth0
BOOTPROTO=dhcp
#
# For more information, please refer to: https://help.aliyun.com/document_de
# If you don't want cloud-init genrated automatically,you can disable it in 
# Created by cloud-init on instance boot automatically, do not edit.
[root@iZ8vb5yl5m390bo5rw0r8cZ network-scripts]# 

[root@iZ8vb5yl5m390bo5rw0r8cZ network-scripts]# nl ifcfg-eth0
     1  # Created by cloud-init on instance boot automatically, do not edit.
     2  # If you don't want cloud-init genrated automatically,you can disable it in /etc/cloud/cloud.cfg
     3  # For more information, please refer to: https://help.aliyun.com/document_detail/57803.html
     4  #
     5  BOOTPROTO=dhcp
     6  DEVICE=eth0
     7  ONBOOT=yes
     8  STARTMODE=auto
     9  TYPE=Ethernet
    10  USERCTL=no

[root@iZ8vb5yl5m390bo5rw0r8cZ etc]# more bashrc
# /etc/bashrc
# System wide functions and aliases
# Environment stuff goes in /etc/profile
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
# are we an interactive shell?
if [ "$PS1" ]; then
  if [ -z "$PROMPT_COMMAND" ]; then
    case $TERM in
    xterm*|vte*)
      if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
          PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
      elif [ "${VTE_VERSION:-0}" -ge 3405 ]; then
          PROMPT_COMMAND="__vte_prompt_command"
      else
          PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAM
E%%.*}" "${PWD/#$HOME/~}"'
--More--(28%)

[root@iZ8vb5yl5m390bo5rw0r8cZ etc]# less bashrc
# /etc/bashrc
# System wide functions and aliases
# Environment stuff goes in /etc/profile
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
# are we an interactive shell?
if [ "$PS1" ]; then
  if [ -z "$PROMPT_COMMAND" ]; then
    case $TERM in
    xterm*|vte*)
      if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
          PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
      elif [ "${VTE_VERSION:-0}" -ge 3405 ]; then
          PROMPT_COMMAND="__vte_prompt_command"
      else
          PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'

[root@iZ8vb5yl5m390bo5rw0r8cZ etc]# head -n 20 bashrc
# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

# are we an interactive shell?
if [ "$PS1" ]; then
  if [ -z "$PROMPT_COMMAND" ]; then
    case $TERM in
    xterm*|vte*)
      if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
          PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
      elif [ "${VTE_VERSION:-0}" -ge 3405 ]; then
          PROMPT_COMMAND="__vte_prompt_command"
      else

[root@iZ8vb5yl5m390bo5rw0r8cZ etc]# tail -n 20 bashrc
       umask 022
    fi

    SHELL=/bin/bash
    # Only display echos from profile.d scripts if we are no login shell
    # and interactive - otherwise just process them to set envvars
    for i in /etc/profile.d/*.sh; do
        if [ -r "$i" ]; then
            if [ "$PS1" ]; then
                . "$i"
            else
                . "$i" >/dev/null
            fi
        fi
    done

    unset i
    unset -f pathmunge
fi
# vim:ts=4:sw=4

软链接和硬链接

硬链接:A---B 如果B是A的硬链接,那么A和B指向同一个文件.如果删除A.B仍然可以访问到A中的文件.(用户可以根据这个属性,对一些重要的文件进行多路径.防止误删)

软链接:A---B 类似于windows下的快捷方式.删除A,那么B也访问不到了   (也称为符号链接)

创建连接 ln命令. 默认是创建硬链接.查看文件属性是文件属性.  加 -s 表示创建软链接

ln   源文件 xx

ln -s 源xx xx

touch命令创建文件

echo 输入字符串 向文件中输入字符串

[root@iZ8vb5yl5m390bo5rw0r8cZ home]# touch aa
[root@iZ8vb5yl5m390bo5rw0r8cZ home]# ls
aa  apache-tomcat-9.0.38  apache-tomcat-9.0.38.zip  jdk1.8.0_20  redis  www
[root@iZ8vb5yl5m390bo5rw0r8cZ home]# ln aa bb
[root@iZ8vb5yl5m390bo5rw0r8cZ home]# ls
aa  apache-tomcat-9.0.38  apache-tomcat-9.0.38.zip  bb  jdk1.8.0_20  redis  www
[root@iZ8vb5yl5m390bo5rw0r8cZ home]# ln -s aa cc
[root@iZ8vb5yl5m390bo5rw0r8cZ home]# ll
total 11548
-rw-r--r-- 2 root  root         0 Mar 15 17:45 aa
drwxr-xr-x 9 root  root      4096 Sep 10  2020 apache-tomcat-9.0.38
-rw-r--r-- 1 root  root  11805236 Mar 13 14:13 apache-tomcat-9.0.38.zip
-rw-r--r-- 2 root  root         0 Mar 15 17:45 bb
lrwxrwxrwx 1 root  root         2 Mar 15 17:46 cc -> aa
drwxr-xr-x 7 root  root      4096 Mar 13 14:13 jdk1.8.0_20
drwx------ 2 redis redis     4096 Mar 10 17:37 redis
drwx------ 3 www   www       4096 Mar 10 17:37 www

[root@iZ8vb5yl5m390bo5rw0r8cZ home]# echo "i love you" >> f1
[root@iZ8vb5yl5m390bo5rw0r8cZ home]# cat f1
i love you

如果rm -rf A   删除A ,那么硬链接还可以访问,软链接就失效了

vim编译器

三种使用模式

  • 命令模式

刚启动vim时,就会进入到命令模式.在命令模式中.

输入 i 就进入到了输入模式.

输入 : 就进入了底线命令模式

x    删除当前光标所在的字符

  • 底线命令模式

在底线输入模式中 w表示保存,q表示退出.

输入 wq  表示保存并退出

  • 输入模式

输入模式就是开始在文档中写东西.

按下ESC 键,就进入到命令模式

ENTER 键,回车换行

HOME/END 键,移动光标到行首行尾

一般的完整操作

  1. vim xxx.txt 新建或者打开文件,进入到命令模式
  2. i   进入输入模式,编辑完成  ESC键退出
  3. : 进入底部命令模式,wq保存退出

一般模式下 的基本命令

+号,光标移动到非空格的下一行

-号,光标移动到非空格的上一行,(一般在配置文件中,空格非常多)

数字+ENTER : 光标向下移动n行

数字+空格 :光标向右移动多少n列

搜索替换

/字符   在光标之下寻找字符,

?字符  光标之上寻找字符

n    定位到下一个匹配的字符

N    定位到上一个匹配的字符

底部命令模式

ZZ   如果修改就保存退出,无修改就直接退出

:set nu  显示行号

账号管理

useradd 命令 添加用户

useradd 选项 用户名

-m :自动创建这个用户的主目录/home/haixin

理解一下本质:Linux中一切皆文件,这里的添加用户说白了就是往某个文件中写入用户的信息

/etc/passwd这个文件中记录这所有账号的信息

cat /etc/passwd 可以查看刚刚创建的用户信息

userdel 删除用户

userdel -r haixin 删除用户的时候将它的目录一并删除

usermod 修改用户

usermod -d /home/233 haixin

修改完毕之后查看配置文件即可

cat /etc/passwd

切换用户

root用户

  1. 切换用户的命令为 su username
  2. 从普通用户切换到root用户 sudo su
  3. 在终端输入exit或logout或ctrl+d.可以退回原来的用户,(ctrl+d也是执行exit命令)
  4. 在切换用户时,如果想使用新用户的工作环境

,可以在su和username之间加-   :su -root

在阿里云买的服务器,主机名一开始是一串随机数字.

hostname     查看主机名

hostname newname   修改主机名  (修改之后重新连接及可看到新主机名)

[roothome.php?mod=space&uid=555129 home]# su haixin2    一个root 就是当前账户名.home.php?mod=space&uid=402414 后面是主机名,然后是当前目录名  $ 表示普通用户.# 表示超级用户,也就是root用户

用户的密码设置问题

我们通过root创建账户的时候,要创建用户的密码

linux上输入密码时是没有任何显示的,正常输入就可以,并不是系统问题

超级用户:

passwd username:

new password

re password

普通用户:

passwd

(current) UNIX password: #旧密码

new password:

re password:

冻结账号

passwd -l haixin 锁定账户,不能登录了

passwd -d haixin 清除账户密码,并锁定

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

wylksy 发表于 2021-3-17 15:41
谢谢楼主分享
笨蛋先森 发表于 2021-3-17 15:49
dunkyy 发表于 2021-3-17 15:41
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-10 19:38

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表