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

Angular Dependency Injection Explained

Table of contents Overview 1. Dependency Injectio...

The 6 Most Effective Ways to Write HTML and CSS

This article shares the 6 most effective methods,...

Computed properties and listeners details

Table of contents 1. Calculated properties 1.1 Ba...

Detailed explanation of three solutions to the website footer sinking effect

Background Many website designs generally consist...

Mysql GTID Mha configuration method

Gtid + Mha + Binlog server configuration: 1: Test...

mysql implements the operation of setting multiple primary keys

User table, ID number must be unique, mobile phon...

The complete version of the common Linux tool vi/vim

Why learn vim Linux has a large number of configu...

MySQL online DDL tool gh-ost principle analysis

Table of contents 1. Introduction 1.1 Principle 1...

Detailed comparison of Ember.js and Vue.js

Table of contents Overview Why choose a framework...

Linux MySQL root password forgotten solution

When using the MySQL database, if you have not lo...

Tutorial diagram of installing mysql8.0.18 under linux (Centos7)

1 Get the installation resource package mysql-8.0...

How to express relative paths in Linux

For example, if your current path is /var/log and...

A summary of some of the places where I spent time on TypeScript

Record some of the places where you spent time on...

Will the index be used in the MySQL query condition?

When an employer asks you whether an index will b...

Implementation of CentOS8.0 network configuration

1. Differences in network configuration between C...