Linux file management command example analysis [permissions, create, delete, copy, move, search, etc.]

Linux file management command example analysis [permissions, create, delete, copy, move, search, etc.]

This article describes the Linux file management commands with examples. Share with you for your reference, the details are as follows:

1. File permissions

Read r 4
Write w 2
Run x 1

Files are divided into three types of permissions:

  1. Owner permissions
  2. User permissions within the group
  3. Permissions for users outside the group

2. View the files in the directory

ls [options] [path or filename]
-l : View detailed information
-a: View all files, including hidden files

First column: file permissions
- (rw-) (---) (---)
The first character indicates the file type (- indicates a normal file, d indicates a folder)
The second one indicates the owner's permissions
The third one indicates the group permissions
The fourth column indicates the permissions outside the group. The second column: the number of file nodes. The third column: the file owner. The fourth column: the group to which the file belongs. The fifth column: the file size. The sixth column: the last modification time of the file. The seventh column: the file name.

3. Directory Management

mkdir directory name creates a directory
-p recursive creation
-m specifies permissions when creating a directory (Linux defaults to creating directory permissions of 755)

rmdir directory name delete directory (only empty directories can be deleted)
-p recursive delete

4. File creation and deletion

touch file name to create a file
rm file name delete file (will prompt whether to delete)
-r recursive delete
-f means close confirmation

5. Copy and move files

cp [options] source file path target file path copy file
-R : copy recursively
-p: Keep the original attributes of the file during the copy process
-v : Display the copy process

> cp -R /home/user1/123 /home/. (. means use the original file name)

mv [options] source file path target file path move file
-v : Display process

> mv /home/user1/123 /home/.

*mv can also realize the renaming function.

6. File Statistics

wc [options] file list statistics file content
-c counts the number of characters
-l count lines
-w count words

>wc -c 1.txt
 
>wc -w 1.txt
 

7. Search for matching rows

grep [options] string source file
-n Display line numbers
-c How many lines to match in total
-i Ignore case

> grep -ni hello 1.txt

I hope this article will help you maintain your Linux system.

You may also be interested in:
  • Detailed explanation of the problem that the space is not released after the Linux file is deleted
  • How to deal with the problem that the file is deleted but the space is not released in Linux
  • Linux unlink function and how to delete files
  • Linux implements scheduled backup of MySQL database and deletes backup files older than 30 days
  • Linux regularly backs up the MySQL database and deletes previous backup files (recommended)
  • How to delete folders, files, and decompress commands on Linux servers
  • 5 Ways to Clear or Delete Large File Contents in Linux
  • Comparison of the efficiency of different methods of deleting files in Linux

<<:  Discussion on more reasonable creation rules for MySQL string indexes

>>:  The process of using vxe-table to make editable tables in vue

Recommend

Detailed implementation plan of Vue front-end exporting Excel files

Table of contents 1. Technology Selection 2. Tech...

Supplementary article on front-end performance optimization

Preface I looked at the previously published arti...

Docker installs the official Redis image and enables password authentication

Reference: Docker official redis documentation 1....

Detailed example of MySQL (5.6 and below) parsing JSON

MySQL (5.6 and below) parses json #json parsing f...

How to Enable or Disable Linux Services Using chkconfig and systemctl Commands

This is an important (and wonderful) topic for Li...

js realizes a gradually increasing digital animation

Table of contents background Achieve a similar ef...

Common scenarios and avoidance methods for index failure in MySQL

Preface I have read many similar articles before,...

HTML Tutorial: Collection of commonly used HTML tags (6)

Related articles: Beginners learn some HTML tags ...

How to install multiple mysql5.7.19 (tar.gz) files under Linux

For the beginner's first installation of MySQ...

Two ways to understand CSS priority

Method 1: Adding values Let's go to MDN to se...

MySQL 5.7.15 version installation and configuration method graphic tutorial

This article shares with you a detailed tutorial ...

How to use Vuex's auxiliary functions

Table of contents mapState mapGetters mapMutation...

A brief discussion on which fields in Mysql are suitable for indexing

Table of contents 1 The common rules for creating...