linux directory of the file, input and output

File directory structure

ls 查看文件
ll 查看详细文件
  • Files and directories are organized into a tree upside down
  • Start from the root file system, '/'
  • File names are case-sensitive strict
  • Hidden files. Beginning
  • File separator is '/'

File naming convention

  • File character up to 255 characters
  • Including the file name including the path up to 4095
  • colour
    • Blue -> Folder
    • Green -> executable file
    • Red -> archive
    • Clear Blue -> Link file (windows shortcuts)
    • Gray -> Other documents
    • White -> File
  • In addition to '/' and NULL. All other characters can be used
  • Case sensitive

File system structure

/boot # 引导文件的存放位置,内核文件,引导加载器都在此目录
/bin  # 所有用户都可以使用的命令.
/sbin # 管理类命令,即root用户可以使用的命令. system 管理
/lib  # 启动时程序使用的基本库文件,windows库文件以.dll结        尾,linux库文件以.so结尾
/lib64 # 存放x86-64系统上的辅助库文件,windows系统中    program files/program files(x86)
/etc   # 存放配置文件的目录
/home  # 普通用户家目录
/root  # 管理员家目录
/media # 便携式移动设备的挂载点
/mnt   # 临时文件的挂载点
/dev   # 设备文件(硬件设备)和特殊文件存放位置
/opt   # 第三方的应用安装位置
/tmp   # 重启之后清空此文件夹下文件,临时文件的放置点,类似于windows回收站
/usr   # 存放安装程序
/var   # 存放经常变化的文件,比如目录.  /var/log
/proc  # 存放内核启动和进程相关的虚拟文件,(进程被表示文件)
/sys   # 输出当前系统上的硬件相关文件
/srv   # 系统上允许永达ode数据

The composition of linux applications

  • binary file
    • /bin
    • /sbin
    • /usr/bin
    • /usr/sbin
    • /usr/local/bin
    • /usr/loacl/sbin
  • Library file
    • /lib
    • /lib64
    • /usr/lib
    • /usr/lib64
    • /usr/local/lib
    • /usr/local/lib64
  • Profiles
    • /etc
    • /etc/name
    • /usr/local/etc
  • Help Files
    • /usr/share/man
    • /usr/share/doc
    • /usr/local/share/man
    • /usr/local/share/doc

Absolute and relative paths path

  • Absolute path
    • Begin to root
    • The complete file storage location
    • You can read any file or folder
  • relative path
    • Does not begin to root
    • Relative to the current position to decide
    • Simply represents a file or folder
    • The current directory .. the parent directory

Directory names and group names

# 基名
[root@localhost log]#basename /etc/sysconfig/network-scripts/ifcfg-ens33 
ifcfg-ens33
[root@localhost log]#basename /etc/sysconfig/network-scripts
network-scripts

# 目录名
[root@localhost log]#dirname /etc/sysconfig/network-scripts
/etc/sysconfig
[root@localhost log]#dirname /etc/sysconfig/network-scripts/ifcfg-ens33 
/etc/sysconfig/network-scripts

Change directory

Change directory cd change directory

  • A relative path may be used
  • You can use an absolute path

Switching home directory

cd # 切换家目录
cd - # 回到上一次目录

Displays the current working directory

pwd # 显示当前工作目录 print working directory
[root@localhost network-scripts]#pwd
/etc/sysconfig/network-scripts

pwd -p # 查看链接的真正目录
[root@localhost /]# cd lib
[root@localhost lib]# pwd -p
/usr/lib

List directory or file

-rw-r--r--. 1 root root 0 Aug 22 17:21 10
Competence Hard disk citations Owner is a group size interview time file name
ls list
ls -a  # 显示所有文件
ls -l  # 以长格式显示文件列表
-rw-r--r--. 1       root root  0  Aug 22 17:21    10
权限    硬盘引用次数  属主 属组  大小   访问时间   文件名称
ls -R  # 递归显示目录
ls -d  # 显示目录本身
ls -1  # 文件分行显示
ls -S  # 按照文件大小排序
ls -r  # 倒序显示
ls -t  # 按照时间排序
ls -lh # 显示人类易读方式
ls -d */ # 显示当前目录下文件夹
ls l.  # 只显示隐藏文件
ls -lut # 时间倒叙排列

# 这里全是段命令可以自由组合

Directory type under linux

- 用来表示文件
d 用来表示目录
b 块设备
c 字符设备
| 表示符号链接文件
s socket套接字文件

View file status stat

File: ‘anaconda-ks.cfg’
Size: 1747          Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 33574992    Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Context: system_u:object_r:admin_home_t:s0
# Size   磁盘大小 Blocks 块大小  IO Block Io块大小
# Access 权限     Uid    用户   
Access: 2019-08-22 12:09:03.288000381 +0900 # 访问时间
Modify: 2019-08-22 11:47:12.262947345 +0900 # 修改时间
Change: 2019-08-22 11:47:12.262947345 +0900 # 改动时间

Access # 最近访问时间 atime 查看cat文件内容就会改变
Modify # 最近修改时间 mtime 改变内容时发生变化
Change # 最近改动时间 ctime 元数据发生变化就会改变

touch

创建空文件和刷新时间,如果文件存在,则刷新时间,不存在则创建文件
touch -a 修改atime和ctime
touch -m 修改mtime和ctime
# 无论是-a 还是-m ctime都会改变

File wildcard

*           # 表示0-多个字符
?           # 匹配任意单个字符
~           # 表示家目录
[123]       # 表示其中一个
[-]         # 范围
# 根据ascii码 
file[a-z]   # 字母(有坑) 缺少Z   
file[A-Z]   # 字母(有空) 缺少a
[^]         # 取反
[:lower:]   # 小写字母
[:upper:]   # 大写字母
[:alpha:]   # 所有字母
[:alpha:]   # 所有字母
[:alnum:]   # 表示字母和数字
[:digit:]   # 表示数字

Create a directory

mkdir    # 创建目录
-p a/b/c   # 递归创建
-v         # 显示创建详细过程

Display the directory tree

yum install-y tree  # 安装目录树
tree                # 显示目录树
tree -d             # 仅显示文件夹
-L num              # 仅显示num层,排除当前目录

Remove directory

rmdir   # 只能删除非空目录
-p      # 递归删除空父目录
-v      # 显示删除过程
rm -rf  # 删除非空目录

Copy files and folders

Cp copy default under an alias, the original command itself (\ cp) are not prompted to overwrite

使用方法:
Usage: cp [OPTION]... [-T] SOURCE DEST
  or:  cp [OPTION]... SOURCE... DIRECTORY
  or:  cp [OPTION]... -t DIRECTORY SOURCE

cp              # copy
-i              # 显示覆盖提示信息
-n              # 不覆盖
-f              # 非强制的
-R -r           # 递归复制,如果复制文件夹,不加递归复制会报错
-s              # 拷贝一个链接文件
-d              # 只复制链接文件不复制原文件
-a              # 归档
-v              # 显示复制过程
-b              # 覆盖之前,备份原来的文件
--backup=number # 备份
-p              # 复制时保留原来的属性
  • If the source file is a file
    • The target file is a file
      • If the target file does not exist, create a new target file, and writes the contents of the target file
      • If the target file exists, the original command is directly covered recommended -i prompt the user.
    • The goal is folder
      • Create a file with the same name in the folder, and the contents of the file is written to the new file
  • If the original file into multiple files
    • The target must be the folder, and the folder must exist. Other cases are being given
  • If the original file is a folder
    • Target file is the file: No
    • Target file must be a folder, you must use the -r option
    • If the target file does not exist: directly create a destination folder, and the original data folder are copied to the destination folder
    • If the destination file exists:
      • If the file is an error
      • If the folder: create a folder with the same name in the target folder, and target on the new folder.

Move, rename

mv move

mv  # move
Usage: mv [OPTION]... [-T] SOURCE DEST
  or:  mv [OPTION]... SOURCE... DIRECTORY
  or:  mv [OPTION]... -t DIRECTORY SOURCE...

-i             # 提示
-f             # 强制
-b             # 备份
--backup=number # 备份后面加数字
-v             # 显示过程

delete

rm remove

Usage: rm [OPTION]... FILE...

-i         # 提示
-r -R      # 递归删除
-f         # 强制
rm -rf     # 慎用
rm -rf /*  # 慎用
cd /
rm -rf *

# 这里需要提前用VMware 提前快照,然后恢复快照
# 右击里面点击拍摄快照

link

Soft links

ln -s 源文件 目标文件   # 创建命令 
1.相当于windows快捷方式
2.可以对目录做软链接,执行另外的一个文件或者目录的路径,大小是路径的长度的字符
3.对磁盘引用次数没有影响
4.可以跨分区
5.源文件发生改变,软链接会跟着发生变化
6.源文件删除,软链接不能访问,再添加相同名字时,即可引用

Hard links

ln 原文件 目标文件     # 创建硬链接
1.磁盘引用次数发生变化
2.指向的是硬盘上的同一块区域
3.硬盘的引用数会随着硬链接的次数而增加
4.不能对目录做硬链接
5.不能跨越分区
6.源文件发生改变,硬链接会发生改变
7.源文件删除,硬链接可以访问,磁盘引用数减少

CP

View file types

file

Input and output

1.标准输入      默认是来自键盘的输入  stdin      0
2.标准输出      默认输出到终端窗口    stdput     1
3.标准错误输出  默认输出到终端窗口    stderr      2

I / O Shigesada direction

> 覆盖
1.  >    将>标准输出重定向到文件中
2.  2>   将错误输出重定向到文件中
3.  &>   将所有的输出都重定向到文件中
禁止,允许覆盖
1.  禁止覆盖set -C
2.  允许覆盖set +C
>> 追加
1.  >>    将标准输出追加到文件中
2.  2>>   将错误输出追加到文件中
3.  &>>   将所有的输出都重定向到文件中

Standard input and input errors kept separate

[root@localhost ~]# ls f 45yu > log.log 2>error.log
[root@localhost ~]# cat log.log
f
[root@localhost ~]# cat error.log
ls: cannot access 45yuio: No such file or directory

Merge all outputs

  • &> Redirect coverage
  • & >> append redirection
  • command>file 2>&1
  • command>>file 2>&1
  • (): Merging a plurality of output files (Error 1; Error 2) 2> file
  • &> / Dev / null (similar to a black hole, receiving unlimited)
  • /dev/zero

Importing files from stdin

tr replace characters

# 参数
-t 截断
-d 删除
-s 压缩,去重
-c 取反
tr字符替换
tr 'a-z' 'A-Z' < /etc/issue

# 按字符顺序替换
tr ab 12
ab
12
abb
122
# 分赃不均则默认取最后
tr abc 12
abc
122
# 解决分赃不均问题(截断)
tr -t abc 12
abc
12c
# 删除
tr -d abc
a1b1c
11
# 去重
tr -s a
aaaaabc
abc
# 取反
tr -sc a
aasdaaaa
# tr -d a 默认会把回车删掉,要ctrl+d删除
# 解决办法 tr -dc 'a\n'

读入文件和输出文件不能是同一文件,要写到新的文件中
tr -d <issue>issue

Multiline sent to stdin

1. cat > f1
# ctrl c可以结束
2. cat > f2 <<EOF 
# <<后面的值随便写,但是必须以它结束,约定俗成EOF
> EOF 
# 结束,结束之后,才能显示.

pipeline

Pipe "|" is used to denote

Command 1 | command 2 | 3 command

  • The output of the command as a result command output 2, 2 of the command output as a result of the input command 3
  • By default, standard output, only the pipe
  • If you need to also pass the error output, you need to | &
  • Usually a combination of a plurality of commands for
有一些命令是不接受管道的
# 如touch,cat等 

Guess you like

Origin www.cnblogs.com/taosiyu/p/11432946.html
Recommended