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

Vue routing relative path jump method

Table of contents Vue routing relative path jump ...

A simple example of mysql searching for data within N kilometers

According to the coefficient of pi and the radius...

Vue+echarts realizes stacked bar chart

This article shares the specific code of Vue+echa...

The role of nextTick in Vue and several simple usage scenarios

Purpose Understand the role of nextTick and sever...

Solve the scroll-view line break problem of WeChat applet

Today, when I was writing a small program, I used...

Analysis of MySQL cumulative aggregation principle and usage examples

This article uses examples to illustrate the prin...

How to install redis in docker and set password and connect

Redis is a distributed cache service. Caching is ...

Summary of Common Problems with Mysql Indexes

Q1: What indexes does the database have? What are...

Solution to the problem that MySQL commands cannot be entered in Chinese

Find the problem Recently, when I connected to th...

Summary of MySQL slow log related knowledge

Table of contents 1. Introduction to Slow Log 2. ...

Detailed explanation of the difference between var, let and const in JavaScript

Table of contents As a global variable Variable H...

How to create scheduled tasks using crond tool in Linux

Preface Crond is a scheduled execution tool under...