Linux novice introduction series: file and directory operation

This series of articles is to share the author's practical operation records when he first came into contact with and learned Linux. The content mainly includes some theoretical and conceptual knowledge of Linux, simple installation and deployment of Web programs and mysql database. I hope it can help some beginners and avoid detours.

be careful:

Case sensitive under Linux
Linux multiuser multithreading
Under Linux, each file and directory has access rights

File and directory operation (II)


2, Basic operation of files and directories

6. View Folder Size

# du -sh (view total system file size)
# du -sh /home/test (view the total size of a directory file)

7. Commands for displaying directory contents

# cd (change directory)
# pwd (displays the user's current working directory path)
# ls -a-l (displays all files in the current directory, - a displays hidden files, - l displays file details, - R displays files in subdirectories)
# ls -a-l test (displays all files in the test directory)
(ls -l Description of contents displayed in column 1:
	The first character indicates the type of file
	second~4 Characters indicate the file owner's access to this file
	fifth~7 Characters indicate the user group's access to this file
	eighth~10 Characters indicate other users' access to this file)

3, File permissions

1. File permission description

(1) Each file and directory in Linux system has access permission, which can be used to determine how users access and operate files and directories.
(2)Linux system specifies four different types of users: primary user, same group user, other users and super user; It specifies three permissions for accessing files or directories: read, write and executable.
(3) Set permissions in character mode: u (file owner), g (same group user), o (other users) and a (all users) represent different users; r (read), w (write) and x (executable) represent permissions; set file permissions through + (add a permission), - (cancel a permission)= (give the given permission and cancel the original permission).
(4) Use octal numbers to set permissions: three octal numbers represent the permissions of ugo respectively. After each octal number is converted into binary number, the corresponding three digits represent read, write and execution respectively. Each person determines the permissions by the sum of four (read), two (write) and one (execute). For example, 6 (4 + 2) represents the right to read and write, and 7 (4 + 2 + 1) has the right to read, write and execute.

2. Set file permissions

# chmod [who] [opt] [mode]
(who Representation object
u: Represents the owner of the file
g: Represents the same group of users
o: Indicates other users
a: Represents all users
opt Represents the operation: 
+: Add a permission
-: Cancel a permission 
=: Give the given permission and cancel the original permission
mode Then it represents the authority:
r: readable
w: Writable
x: (executable)
# chmod a+x test.txt
(set up test.txt File (all user executable)

# chmod a=rx,u=rwx test.txt
# chmod 755 test.txt
(Reset test.txt The file owner can write, and all users can only read and execute)

3. Modify the owner and group of the file or directory

# chown -R tomcat /home/test
(take/home/test The owner of all files in its subdirectories is changed to tomcat)
# chown -R tomcat:tomcat /home/test
(take/home/test The owner of all files in its subdirectories is changed to tomcat,Group changed to tomcat)

4, File decompression

# zip -r ./* (compress all files in the current directory into the file, - R recursion)
# zip -r test (compress the test file and all files in its directory into the file)
# unzip (unzip the file to the current directory)
# unzip -o -d t (unzip the file to the directory T, - D to specify the directory, - O to unzip silently)
# gzip -r ./* (compress all files in the current directory into. gz files, - R recursion)
# gzip -d -r ./* (extract all. gz files in the current directory)
# tar -czvf log.tar *.log
(All files in the current directory.log Type the file into a file named log.tar (package for)
# tar -rf log.tar test.txt
(Will file test.txt Add to archive allc.tar Medium)
# tar -tf log.tar
(see log.tar (content in)
# tar -xf log.tar
(recovery log.tar (files in)

5, File links (shortcuts)

File links are divided into soft links and hard links. Generally, the file links we commonly use are soft links. Soft link is also called symbolic link. Its characteristics are similar to shortcuts in Windows, so it's easier for everyone to understand.
(1) Soft link features:
Delete the soft link file and the source file will not be affected. When the original file is deleted, the soft link file will not find the actual data, so it shows that the file does not exist.
Soft links can link directories.
Soft links can span partitions.
(2) Hard link features:
Hard links to directories are not allowed, and hard links cannot be created between different mount points.
Whether you modify the source file (test file) or the hard link file (test hard file), the data in the other file will change.
Whether you delete the source file or delete the hard link file, as long as there is another file, this file (the file with inode number xxx) can be accessed.

# ln -s /home/test.txt /tmp/test.ln #Create soft link
-s Create soft connection
 Note: the path of soft link must be written as absolute path, not relative path (no requirement for hard link).

# ln /home/test.txt /tmp/test-hard #Create hard link
# ln /home/test.txt /tmp #Create hard link

Note: when establishing a hard link file, the target file does not have a file name, which will be consistent with the original name.

IT little fat bean: beginners step into the pit and share the process. I hope I can help some beginners. Welcome all IT workers to enter the pit for discussion-_-

Keywords: Linux Operating System

Added by kerplunk on Sat, 25 Dec 2021 15:50:53 +0200