zoukankan      html  css  js  c++  java
  • 基本命令:查看系统版本、cd、ls、pwd、cat、cp、mv

    系统核心命令

    cd

    Linux中切换目录的命令。

    格式:

    cd 路径(需要切换的目录路径)

    路径:

    • 绝对路径:从根路径开始
    • 相对路径:从当前目录开始
    • 特殊路径:
      • . : 当前目录
      • .. : 上级目录

    注:系统根指的是 /

    ls

    查看对应路径下的文件。

    格式:

    ls 路径(默认是当前路径)

    要求:在当前目录查看/root目录下有哪些文件?

    参数:

    -a : 显示隐藏文件(隐藏文件:在Linux系统中,以.开头的文件及文件夹就可以称之为隐藏文件或隐藏文件夹)

    [root@localhost yum.repos.d]# ls -a ../../root
    .  ..  anaconda-ks.cfg  .bash_history  .bash_logout  .bash_profile  .bashrc  .cshrc  .tcshrc
    

    -l : 列出指定路径下的文件详细信息

    [root@localhost yum.repos.d]# ls -l ../../root
    total 4
    -rw-------. 1 root root 1757 Mar  3 10:51 anaconda-ks.cfg
    权限位        用户组 用户名     时间           文件名称
    

    pwd

    显示当前所在路径。

    [root@localhost yum.repos.d]# pwd
    /etc/yum.repos.d
    [root@localhost yum.repos.d]# cd /root/
    [root@localhost ~]# pwd
    /root 
    

    cat

    查看文件内容的命令

    格式:

    cat [路径]文件名称

    mv

    移动一个文件

    格式:

    mv [原来的文件路径] [新的文件的路径]

    可以使用*匹配多个文件。

    [root@localhost yum.repos.d]# mv CentOS-* backup/
    mv: overwrite ‘backup/CentOS-Base.repo’? y
    [root@localhost yum.repos.d]# ls -l
    total 0
    drwxr-xr-x. 2 root root 187 Mar  3 16:14 backup
    [root@localhost yum.repos.d]# 
    

    查看系统版本

    [root@localhost yum.repos.d]# cat /etc/redhat-release 
    CentOS Linux release 7.6.1810 (Core) 
    

    cp 复制

    复制,拷贝  
    
    语法:
    
    	命令     源文件     目标目录
    	
    选项:
    	
    	-r		#递归复制   复制目录时所使用的
    	
    	-p		#保持源文件属性
    	
    	-d		#复制的时候保持软连接 
    	
    	-a		===  -pdr
    	
    	-t		#把源文件的位置根目标目录的位置进行调换   在批量拷贝文件时使用 
    	
    	-i		#当拷贝的文件在目标目录已经存在时,提示是否覆盖     系统自带的别名 
    
    
    [root@qls ~]# cp  /etc/hosts  /root
    [root@qls ~]# cp  /etc/passwd   ./
    [root@qls ~]# cp  /etc/resolv.conf   .
    [root@qls ~]# ll
    total 12
    -rw-r--r--. 1 root root 158 Jul  9 09:11 hosts
    -rw-r--r--. 1 root root 873 Jul  9 09:11 passwd
    -rw-r--r--. 1 root root  51 Jul  9 09:11 resolv.conf
    
    
    
    [root@qls ~]# cp  /opt/   ./
    cp: omitting directory ‘/opt/’
    [root@qls ~]# cp  -r   /opt/  ./
    [root@qls ~]# ll
    total 12
    -rw-r--r--. 1 root root 158 Jul  9 09:11 hosts
    drwxr-xr-x. 2 root root   6 Jul  9 09:14 opt
    -rw-r--r--. 1 root root 873 Jul  9 09:11 passwd
    -rw-r--r--. 1 root root  51 Jul  9 09:11 resolv.conf
    
    
    [root@qls ~]# ll  /etc/grub2.cfg 
    lrwxrwxrwx. 1 root root 22 Jul  6 02:14 /etc/grub2.cfg -> ../boot/grub2/grub.cfg
    [root@qls ~]# cp  /etc/grub2.cfg  ./
    [root@qls ~]# ll
    total 20
    -rw-r--r--. 1 root root 4229 Jul  9 09:16 grub2.cfg
    -rw-r--r--. 1 root root  158 Jul  9 09:11 hosts
    drwxr-xr-x. 2 root root    6 Jul  9 09:14 opt
    -rw-r--r--. 1 root root  873 Jul  9 09:11 passwd
    -rw-r--r--. 1 root root   51 Jul  9 09:11 resolv.conf
    [root@qls ~]# rm -f grub2.cfg 
    [root@qls ~]# cp  -d  /etc/grub2.cfg   ./
    [root@qls ~]# ll
    total 12
    lrwxrwxrwx. 1 root root  22 Jul  9 09:16 grub2.cfg -> ../boot/grub2/grub.cfg
    -rw-r--r--. 1 root root 158 Jul  9 09:11 hosts
    drwxr-xr-x. 2 root root   6 Jul  9 09:14 opt
    -rw-r--r--. 1 root root 873 Jul  9 09:11 passwd
    -rw-r--r--. 1 root root  51 Jul  9 09:11 resolv.conf
    
    
    [root@qls ~]# cp  -t  ./   /etc/fstab 
    [root@qls ~]# ll
    total 16
    lrwxrwxrwx. 1 root root   7 Jul  6 02:13 bin -> usr/bin
    -rw-r--r--. 1 root root 501 Jul  9 09:21 fstab
    lrwxrwxrwx. 1 root root  22 Jul  9 09:16 grub2.cfg -> ../boot/grub2/grub.cfg
    -rw-r--r--. 1 root root 158 Jul  9 09:11 hosts
    drwxr-xr-x. 2 root root   6 Jul  9 09:14 opt
    -rw-r--r--. 1 root root 873 Jul  9 09:11 passwd
    -rw-r--r--. 1 root root  51 Jul  9 09:11 resolv.conf
    
    
    
    [root@qls ~]# cp  /etc/hosts   ./
    cp: overwrite ‘./hosts’? n
    
    [root@qls ~]# alias 
    alias cp='cp -i'
    
    
    #强制覆盖不提示    临时取消别名 
    
    [root@qls ~]# cp  /etc/hosts  ./
    
    

    mv剪切

    移动和重命名文件 
    
    语法:
    
    	命令     源文件    目标目录  
    	
    选项:
    
    	-i		#当文件已经存在时,移动的时候,提示是否覆盖目标文件    系统自带别名 
    	
    	-f		#强制覆盖,不提示  
    	
    	-t		#把源文件的位置跟目标目录的位置进行调换 
    
    [root@qls ~]# ll  /opt/
    total 12
    -rw-r--r--. 1 root root 501 Jul  9 09:28 fstab
    -rw-r--r--. 1 root root 158 Jul  9 09:28 hosts
    -rw-r--r--. 1 root root  51 Jul  9 09:28 resolv.conf
    [root@qls ~]# mv  /opt/hosts   ./
    [root@qls ~]# ll
    total 4
    -rw-r--r--. 1 root root 158 Jul  9 09:28 hosts
    [root@qls ~]# ll /opt/
    total 8
    -rw-r--r--. 1 root root 501 Jul  9 09:28 fstab
    -rw-r--r--. 1 root root  51 Jul  9 09:28 resolv.conf
    
    
    [root@qls ~]# cp -r  /mnt/   /opt/
    [root@qls ~]# ll /opt/
    total 8
    -rw-r--r--. 1 root root 501 Jul  9 09:28 fstab
    drwxr-xr-x. 2 root root   6 Jul  9 09:59 mnt
    -rw-r--r--. 1 root root  51 Jul  9 09:28 resolv.conf
    [root@qls ~]# mv /opt/mnt/   ./		#在移动目录的时候,不需要加任何的选项  
    [root@qls ~]# ll
    total 4
    -rw-r--r--. 1 root root 158 Jul  9 09:28 hosts
    drwxr-xr-x. 2 root root   6 Jul  9 09:59 mnt
    
    
    [root@qls ~]# cp  /etc/hosts  /opt/
    [root@qls ~]# ll /opt/
    total 12
    -rw-r--r--. 1 root root 501 Jul  9 09:28 fstab
    -rw-r--r--. 1 root root 158 Jul  9 10:00 hosts
    -rw-r--r--. 1 root root  51 Jul  9 09:28 resolv.conf
    [root@qls ~]# ll
    total 4
    -rw-r--r--. 1 root root 158 Jul  9 09:28 hosts
    drwxr-xr-x. 2 root root   6 Jul  9 09:59 mnt
    [root@qls ~]# mv  /opt/hosts   ./		#文件已经存在时,提示是否覆盖  
    mv: overwrite ‘./hosts’? n
    
    [root@qls ~]# alias 
    alias cp='cp -i'
    alias egrep='egrep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias grep='grep --color=auto'
    alias l.='ls -d .* --color=auto'
    alias ll='ls -l --color=auto'
    alias ls='ls --color=auto'
    alias mv='mv -i'
    
    #强制覆盖不提示  
    
    [root@qls ~]# mv  /opt/hosts   ./
    
    #强制覆盖不提示 
    
    [root@qls ~]# mv  -f  /opt/hosts   ./
    [root@qls ~]# ll
    total 4
    -rw-r--r--. 1 root root 158 Jul  9 10:00 hosts
    drwxr-xr-x. 2 root root   6 Jul  9 09:59 mnt
    [root@qls ~]# ll /opt/
    total 8
    -rw-r--r--. 1 root root 501 Jul  9 09:28 fstab
    -rw-r--r--. 1 root root  51 Jul  9 09:28 resolv.conf
    
    
    [root@qls ~]# mv -t  /opt/   ./hosts  
    [root@qls ~]# ll
    total 0
    drwxr-xr-x. 2 root root 6 Jul  9 09:59 mnt
    [root@qls ~]# ll /opt/
    total 12
    -rw-r--r--. 1 root root 501 Jul  9 09:28 fstab
    -rw-r--r--. 1 root root 158 Jul  9 10:00 hosts
    -rw-r--r--. 1 root root  51 Jul  9 09:28 resolv.conf
    
    #在移动文件或者目录的过程中,修改了名称  
    
    [root@qls ~]# mv  mnt/   mot
    [root@qls ~]# ll
    total 0
    drwxr-xr-x. 2 root root 6 Jul  9 09:59 mot
    [root@qls ~]# mv  /opt/hosts   ./host
    [root@qls ~]# ll
    total 4
    -rw-r--r--. 1 root root 158 Jul  9 10:00 host
    drwxr-xr-x. 2 root root   6 Jul  9 09:59 mot
    
  • 相关阅读:
    Asp.net中导出Excel文档(Gridview)
    以太坊难度炸弹是什么?极大抑制矿工继续以POW方式挖矿!
    Solidity语言基础 和 Etherum ERC20合约基础
    BCH/BSV coin split troubleshooting
    比特币学习-Transaction的locktime属性
    在BCH硬分叉后防止重放攻击-2
    在BCH硬分叉后防止重放攻击-1
    区块链硬分叉-软分叉简单了解
    BTC和BCH 区别和联系?
    BCHABC/BCHSV的矛盾所在
  • 原文地址:https://www.cnblogs.com/caodan01/p/14505478.html
Copyright © 2011-2022 走看看