Basic operation tutorial of files and permissions in centos

Basic operation tutorial of files and permissions in centos

Preface

Before we begin, we should briefly understand the file attributes and how to change file attributes:

From the above picture we can see some basic properties of the file, including permissions, number of links, owner and group, file size, modification time, file name, etc.

Change directory

cd: Change directory.

When we need to enter another directory, we need to use the cd command. '

The cd command has the following main usage modes:

cd [~]: Enter the home directory of the current user. For example, if I log in as user fuwh, I will enter the /home/fuwh directory.

cd directory name: enter the specified directory

cd .: represents the current directory

cd ..: represents entering the upper directory. For example, if I am in /home/fuwh now, using this command will enter the /home directory.

cd -: represents the previous working directory. For example, if we often need to switch between two directories, we can use this shortcut.

View the file list

Directory processing command: ls

Command name:

ls

Command English original meaning:

list

Command path:

/bin/ls

Execute permissions:

All users

Functional description:

Display directory files

grammar:

ls option [-ald] [file or directory]

-a Display all files, including hidden files

-l detailed information display

-d View directory properties


ls -lh converts the byte display of the file size into the familiar Windows

ls -lhd /etc is to view the size of the etc directory instead of viewing all the contents under the ect directory.

#ls -i View the id number of each file

Permission Flags

r means the file can be read
w means the file can be written (write)
x means the file can be executed (if it is a program)
- Indicates that the corresponding permission has not been granted

Permission Grouping

Example - rw-r--r-- 1 root root 48 Jan 8 20:14 token.txt

The first 10 digits -rw-rw-r--

The first one - represents the type. The first one rw - represents the owner (user).
The second rw- stands for group
The third r stands for other people.

From the above explanation, we can see that the permissions of the token.txt file are:

The current user itself: readable and writable, no executable permission

Current user group: readable but not writable, no executable permission

Other users: Readable but not writable, no executable permission

rwx can also be replaced by numbers

r------------4
w ------------2
x ------------1
-------------0

Permissions correspond to numbers, octal

-rw------- (600) 0420000000 Only the owner has read and write permissions
-rw-r--r-- (644) 0420400400 Only the owner has read and write permissions, the group and others only have read permissions
-rwx------ (700) 0421000000 Only the owner has read, write, and execute permissions
-rwxr-xr-x (755) 0421401401 Only the owner has read, write, and execute permissions, while the group and others have only read and execute permissions
-rwx--x--x (711) 0421001001 Only the owner has read, write, and execute permissions, while the group and others have only execute permissions
-rw-rw-rw- (666) 0420420420 Everyone has read and write permissions
-rwxrwxrwx (777) 0421421421 Everyone has read, write, and execute permissions

Modify file permissions

chmod 777 file|dir (-R recurse into subfolders)

[root@iZwz9id7ajv83jhb9gicj0Z spiders]# chmod 777 test_data/ -R
[root@iZwz9id7ajv83jhb9gicj0Z spiders]# ls
batj_kb.py batj_yb.py __init__.py items.py sztj_tjkb.py sztj_tjyb.py test_data
batj_kb.pyc batj_yb.pyc __init__.pyc items.pyc sztj_tjkb.pyc sztj_tjyb.pyc
[root@iZwz9id7ajv83jhb9gicj0Z spiders]# ls -l
total 60
-rw-r--r-- 1 spiderftp ftp 2484 Sep 19 17:07 batj_kb.py
-rw-r--r-- 1 spiderftp ftp 2806 Sep 19 17:07 batj_kb.pyc
-rw-r--r-- 1 spiderftp ftp 4751 Sep 19 17:07 batj_yb.py
-rw-r--r-- 1 spiderftp ftp 4801 Sep 19 17:07 batj_yb.pyc
-rw-r--r-- 1 spiderftp ftp 161 Sep 19 17:07 __init__.py
-rw-r--r-- 1 spiderftp ftp 132 Sep 19 17:07 __init__.pyc
-rw-r--r-- 1 spiderftp ftp 512 Sep 19 17:07 items.py
-rw-r--r-- 1 spiderftp ftp 606 Sep 19 17:07 items.pyc
-rw-r--r-- 1 spiderftp ftp 3900 Sep 19 17:07 sztj_tjkb.py
-rw-r--r-- 1 spiderftp ftp 3542 Sep 19 17:07 sztj_tjkb.pyc
-rw-r--r-- 1 spiderftp ftp 1522 Sep 19 17:07 sztj_tjyb.py
-rw-r--r-- 1 spiderftp ftp 2046 Sep 19 17:07 sztj_tjyb.pyc
drwxrwxrwx 3 spiderftp ftp 4096 Sep 20 11:58 test_data
[root@iZwz9id7ajv83jhb9gicj0Z spiders]# cd test_data/ 
[root@iZwz9id7ajv83jhb9gicj0Z test_data]# ls -l
total 60
-rwxrwxrwx 1 spiderftp ftp 2484 Sep 19 17:07 batj_kb.py
-rwxrwxrwx 1 spiderftp ftp 2806 Sep 19 17:07 batj_kb.pyc
-rwxrwxrwx 1 spiderftp ftp 4751 Sep 19 17:07 batj_yb.py
-rwxrwxrwx 1 spiderftp ftp 4801 Sep 19 17:07 batj_yb.pyc
-rwxrwxrwx 1 spiderftp ftp 161 Sep 19 17:07 __init__.py
-rwxrwxrwx 1 spiderftp ftp 132 Sep 19 17:07 __init__.pyc
-rwxrwxrwx 1 spiderftp ftp 512 Sep 19 17:07 items.py
-rwxrwxrwx 1 spiderftp ftp 606 Sep 19 17:07 items.pyc
-rwxrwxrwx 1 spiderftp ftp 3900 Sep 19 17:07 sztj_tjkb.py
-rwxrwxrwx 1 spiderftp ftp 3542 Sep 19 17:07 sztj_tjkb.pyc
-rwxrwxrwx 1 spiderftp ftp 1522 Sep 19 17:07 sztj_tjyb.py
-rwxrwxrwx 1 spiderftp ftp 2046 Sep 19 17:07 sztj_tjyb.pyc
drwxrwxrwx 2 root root 4096 Sep 20 11:58 test

Modify the user to whom the file belongs

chown user file|dir (-R recurse into subfolders)

[root@iZwz9id7ajv83jhb9gicj0Z spiders]# ls -l
total 60
-rw-r--r-- 1 spiderftp ftp 2484 Sep 19 17:07 batj_kb.py
-rw-r--r-- 1 spiderftp ftp 2806 Sep 19 17:07 batj_kb.pyc
-rw-r--r-- 1 spiderftp ftp 4751 Sep 19 17:07 batj_yb.py
-rw-r--r-- 1 spiderftp ftp 4801 Sep 19 17:07 batj_yb.pyc
-rw-r--r-- 1 spiderftp ftp 161 Sep 19 17:07 __init__.py
-rw-r--r-- 1 spiderftp ftp 132 Sep 19 17:07 __init__.pyc
-rw-r--r-- 1 spiderftp ftp 512 Sep 19 17:07 items.py
-rw-r--r-- 1 spiderftp ftp 606 Sep 19 17:07 items.pyc
-rw-r--r-- 1 spiderftp ftp 3900 Sep 19 17:07 sztj_tjkb.py
-rw-r--r-- 1 spiderftp ftp 3542 Sep 19 17:07 sztj_tjkb.pyc
-rw-r--r-- 1 spiderftp ftp 1522 Sep 19 17:07 sztj_tjyb.py
-rw-r--r-- 1 spiderftp ftp 2046 Sep 19 17:07 sztj_tjyb.pyc
drwxrwxrwx 3 spiderftp ftp 4096 Sep 20 11:58 test_data
[root@iZwz9id7ajv83jhb9gicj0Z spiders]# chown root test_data/ -R
[root@iZwz9id7ajv83jhb9gicj0Z spiders]# ls -l
total 60
-rw-r--r-- 1 spiderftp ftp 2484 Sep 19 17:07 batj_kb.py
-rw-r--r-- 1 spiderftp ftp 2806 Sep 19 17:07 batj_kb.pyc
-rw-r--r-- 1 spiderftp ftp 4751 Sep 19 17:07 batj_yb.py
-rw-r--r-- 1 spiderftp ftp 4801 Sep 19 17:07 batj_yb.pyc
-rw-r--r-- 1 spiderftp ftp 161 Sep 19 17:07 __init__.py
-rw-r--r-- 1 spiderftp ftp 132 Sep 19 17:07 __init__.pyc
-rw-r--r-- 1 spiderftp ftp 512 Sep 19 17:07 items.py
-rw-r--r-- 1 spiderftp ftp 606 Sep 19 17:07 items.pyc
-rw-r--r-- 1 spiderftp ftp 3900 Sep 19 17:07 sztj_tjkb.py
-rw-r--r-- 1 spiderftp ftp 3542 Sep 19 17:07 sztj_tjkb.pyc
-rw-r--r-- 1 spiderftp ftp 1522 Sep 19 17:07 sztj_tjyb.py
-rw-r--r-- 1 spiderftp ftp 2046 Sep 19 17:07 sztj_tjyb.pyc
drwxrwxrwx 3 root ftp 4096 Sep 20 11:58 test_data

Modify the group to which a file belongs

chgrp group file|dir (-R recurse into subfiles)

[root@iZwz9id7ajv83jhb9gicj0Z spiders]# ls -l
total 60
-rw-r--r-- 1 spiderftp ftp 2484 Sep 19 17:07 batj_kb.py
-rw-r--r-- 1 spiderftp ftp 2806 Sep 19 17:07 batj_kb.pyc
-rw-r--r-- 1 spiderftp ftp 4751 Sep 19 17:07 batj_yb.py
-rw-r--r-- 1 spiderftp ftp 4801 Sep 19 17:07 batj_yb.pyc
-rw-r--r-- 1 spiderftp ftp 161 Sep 19 17:07 __init__.py
-rw-r--r-- 1 spiderftp ftp 132 Sep 19 17:07 __init__.pyc
-rw-r--r-- 1 spiderftp ftp 512 Sep 19 17:07 items.py
-rw-r--r-- 1 spiderftp ftp 606 Sep 19 17:07 items.pyc
-rw-r--r-- 1 spiderftp ftp 3900 Sep 19 17:07 sztj_tjkb.py
-rw-r--r-- 1 spiderftp ftp 3542 Sep 19 17:07 sztj_tjkb.pyc
-rw-r--r-- 1 spiderftp ftp 1522 Sep 19 17:07 sztj_tjyb.py
-rw-r--r-- 1 spiderftp ftp 2046 Sep 19 17:07 sztj_tjyb.pyc
drwxrwxrwx 3 root ftp 4096 Sep 20 11:58 test_data
[root@iZwz9id7ajv83jhb9gicj0Z spiders]# chgrp root test_data/
[root@iZwz9id7ajv83jhb9gicj0Z spiders]# ls -l
total 60
-rw-r--r-- 1 spiderftp ftp 2484 Sep 19 17:07 batj_kb.py
-rw-r--r-- 1 spiderftp ftp 2806 Sep 19 17:07 batj_kb.pyc
-rw-r--r-- 1 spiderftp ftp 4751 Sep 19 17:07 batj_yb.py
-rw-r--r-- 1 spiderftp ftp 4801 Sep 19 17:07 batj_yb.pyc
-rw-r--r-- 1 spiderftp ftp 161 Sep 19 17:07 __init__.py
-rw-r--r-- 1 spiderftp ftp 132 Sep 19 17:07 __init__.pyc
-rw-r--r-- 1 spiderftp ftp 512 Sep 19 17:07 items.py
-rw-r--r-- 1 spiderftp ftp 606 Sep 19 17:07 items.pyc
-rw-r--r-- 1 spiderftp ftp 3900 Sep 19 17:07 sztj_tjkb.py
-rw-r--r-- 1 spiderftp ftp 3542 Sep 19 17:07 sztj_tjkb.pyc
-rw-r--r-- 1 spiderftp ftp 1522 Sep 19 17:07 sztj_tjyb.py
-rw-r--r-- 1 spiderftp ftp 2046 Sep 19 17:07 sztj_tjyb.pyc
drwxrwxrwx 3 root root 4096 Sep 20 11:58 test_data

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM.

You may also be interested in:
  • How to recover MariaDB database root user permissions in centos
  • Centos rsync file synchronization configuration steps sharing
  • How to set up folder sharing in CentOS 7 in VMware
  • VMware12 and CentOS7 shared folder problem analysis
  • Chinese file names display garbled characters in CentOS
  • CentOS system modifies the display color of the created folder directory
  • Steps to build FTP file service in CentOS
  • How to set up NFS file sharing in CentOS 6.8

<<:  MySQL replication table details and example code

>>:  How to add interface listening mask in Vue project

Recommend

Detailed explanation of how to mount remote file systems via SSH on Linux

Features of SSHFS: Based on FUSE (the best usersp...

Native js to achieve accordion effect

In actual web page development, accordions also a...

Several common methods for setting anchor positioning in HTML

There are several ways I know of to set anchor pos...

Reasons why MySQL kill cannot kill threads

Table of contents background Problem Description ...

linux exa command (better file display experience than ls)

Install Follow the README to install The document...

Linux uses shell scripts to regularly delete historical log files

1. Tools directory file structure [root@www tools...

Implementation of MySQL select in subquery optimization

The following demonstration is based on MySQL ver...

Common commands for deploying influxdb and mongo using docker

Deploy database based on docker sudo docker pull ...

Detailed explanation of custom configuration of docker official mysql image

In order to save installation time, I used the of...

MySQL date functions and date conversion and formatting functions

MySQL is a free relational database with a huge u...

Detailed explanation of the use of CSS pointer-events attribute

In front-end development, we are in direct contac...