The most complete version of Linux file operation commands

Linux file operation commands

1. File management commands

  • touch # Create a new file touch --help product to see touch related help documents
    Insert picture description here

  • mkdir #New folder
    New folder New hierarchical folder
    Insert picture description here

  • rm #Delete files and folders
    Delete files rm xxx
    Delete folder rm -r xxxr means recursively delete the folder and its contents
    Forced delete file rm -fr xxxf means forced delete without prompt
    Insert picture description here

  • cat ##View file content

cat xxx
cat xxx -n  #显示空行行数
cat xxx -b  #不显示空行行数

Insert picture description here
Insert picture description here
Insert picture description here

  • gedit ## Graphical text editor
gedit xxx

Insert picture description here

  • ## vim graphical text editor no
    vim the enter editing mode + <:> Save and Exit + + <:> + <! WQ> Save and exit forcibly
    move the cursor to the left and right arrow keys
    Insert picture description here

Insert picture description here

Vim can open two files at the same time vim -o 111 222 vim -p 111 222
-o: means that two files are opened in up and down mode, ++ up and down keys control the editing window
-p: means that two files are opened in left and right mode, <:>++ enter the next window<:>+ +

Go to the previous window

Insert picture description here

Insert picture description here
Insert picture description here
#vim After editing, exit directly without saving when an exception occurs
O: Read-only open the file
E: Continue editing
R: Restore the unsaved content Edit
D: Delete the .swp file enter the editing
Q: Exit the current file editing
A: Exit the vim program
Insert picture description here

  • head #View the head xxx head -n xxx
    first ten lines of the file by default view the first ten lines of the file -n can be set to view the first ten lines

  • tail #View how many lines after the filetail xxx tail -n xxx

  • View the last ten lines of the file by default -n can also set the last few lines of the file
    Insert picture description here

  • less ##分页
    ###less xxx Enter less mode to view files
    ###In less mode, press up and down to view pgup, pgdn page view
    ###In less mode, you can press to enter edit mode, press to exit less

  • wc ##View file capacity
    wc -l ##View file line count
    wc -m ##View file character count
    wc -c ##View file byte count
    wc -w ##View file word count
    Insert picture description here

  • fiel #View file type

file xxx

Insert picture description here

  • cp ###Copy and create a new file according to the source file
cp 文件  文件夹
cp -r 文件夹  文件夹
  • mv ##Moving the same partition to move files is a process of renaming, while moving different partitions is a process of moving and deleting
mv 文件 文件夹
mv 文件夹  文件夹

2. File addressing in Linux

  1. Linux system structure

    • FHS (Filesystem Hierarchy Standard) linux hierarchy standard
    • Note that everything in Linux is a file
    • System Secondary Directory-
      /bin #System General
      Command-/sbin #System Management Command-
      /dev #Device File-
      /home #Ordinary User Home Directory-
      /root
      #Super User Home Directory- /lib64 or /lib#64-bit function Library or 32-bit function library-
      /proc #Process information-
      /run #Currently running system and hardware-
      /srv #System data (constant)
      -/var #System data (change)
      -tmp #System temporary file storage location-
      / mnt
      #Temporary device mount point- /media #cdrom Temporary mount point-
      /etc #System configuration file-
      /opt # Third-party software installation location-
      /boot #System boot partition, the file read when the system starts-
      /sys #About kernel setting directory-
      /usr #Store most system resources
  2. The concept of relative path absolute path
    -absolute path: start from the root directory, can be used in any situation
    -relative path: start execution from the current location.

  3. Commands about file addressing
    -pwd ## Display the current location
    Insert picture description here

     	- ls   ##查看当前目录下有哪些文件     ls --help 可以查看用法,不过多列举
     ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200927221855740.png#pic)
     	- cd    ##切换工作目录     cd ~- 和 cd - 的含义一样  都是切换回上一次所在目录
     	![在这里插入图片描述](https://img-blog.csdnimg.cn/20200927222031988.png#pic_)
    

4. File batch processing

	*                                  ##匹配0~任意字符
	?								   ##匹配单个字符
    [[:alpha:]]                        ##匹配单个字母	
    [[:digit:]] 					   ##匹配单个数字
    [[:lower:]]                        ##匹配单个小写字母
    [[:upper:]]                       ##匹配单个大写字母
    [[:alnum:]]                      ##匹配单个数字或字母
    [[:punct:]]                       ##匹配单个符号
    [[:space:]]                      ##匹配单个空格

Insert picture description here

	字符集合表示方法
			[]                ##条件是或者关系是模糊匹配,[1-10]   1到10      [!1-10][^1-10]  表示除了[1-10]以外
			{}				  ##点名机制,精确定位集合中的每一个元素,{1..10} 1-10每个元素    

Insert picture description here
Insert picture description here
Insert picture description here

	~                                     ##默认代表当前用户家目录
	~username 					          ##指定用户家目录
	~+ = . 	                              ##当前目录
	~-                                    ##当前目录之前所在目录
	.. 	                                  ##上一级目录

Guess you like

Origin blog.csdn.net/qwerty1372431588/article/details/108836583