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

Usage of Node.js http module

Table of contents Preface HTTP HTTP Server File S...

Review of the best web design works in 2012 [Part 1]

At the beginning of the new year, I would like to...

How to deploy the crownblog project to Alibaba Cloud using docker

Front-end project packaging Find .env.production ...

Vue axios interceptor commonly used repeated request cancellation

introduction The previous article introduced the ...

How to compare two database table structures in mysql

During the development and debugging process, it ...

Provides helpful suggestions for improving website design

<br />Scientifically Design Your Website: 23...

Introduction to the use of base link tag base

<br />When you click the link, the web page ...

A useful mobile scrolling plugin BetterScroll

Table of contents Make scrolling smoother BetterS...

Vue-Element-Admin integrates its own interface to realize login jump

1. First look at the request configuration file, ...

React uses emotion to write CSS code

Table of contents Introduction: Installation of e...

Vue+video.js implements video playlist

This article shares the specific code of vue+vide...

Detailed explanation of using INS and DEL to mark document changes

ins and del were introduced in HTML 4.0 to help au...