Linux file and directory management operations

Linux file and directory management

Experimental purpose and requirements

1. Understand the access permissions of Linux files and directories

2. Familiar with the packaging and compression of Linux files and directories

3. Master the related management operations of Linux files and directories

Experimental principle

The access permissions of files and directories are divided into: read-only, write-only, and executable. There are three different types of users that can access files and directories: file owner, group users, and other users. There are three groups of access rights for this file or directory, and each group is represented by three digits, which are: (1) the read, write and execute rights of the file owner. (2) Read, write and execute permissions for users in the same group as the owner. (3) Read, write and execute permissions of other users in the system.

Experimental procedure

Learn about file management and compressed archives, the specific steps are as follows:

1. Use the mkdir command to create a "test" directory under the "/root" directory.

2. Use the cp command to copy the /etc directory and all its contents to the test directory.

3. Use the cd and ls commands to access and view the "/root/test/etc" directory.

4. Change the permission and owner, and use the ls command to view the difference.

5. Pack the "/root/test/etc" directory into etc.tar.gz with the tar command, check the contents of etc.tar.gz, and decompress etc.tar.gz.

6. Delete the "test" directory.

7. Set umask. Recreate the test directory and check the permissions.

Concrete operation

1. Use the mkdir command to create a "test" directory under the "/root" directory.

Switch to root authority first, and then create the test directory.

mkdir test

insert image description here

2. Use the cp command to copy the /etc directory and all its contents to the test directory.

cp [选项]  源目录或文件名  目标目录或文件名
  • a: This option is usually used when copying directories, it preserves links, file attributes, and copies all content under the directory. Its effect is equal to the combination of dpR parameters.
  • d: Keep the link when copying. The link mentioned here is equivalent to the shortcut in Windows system.
  • f: Overwrite existing target files without prompting.
  • i: Contrary to the -f option, a prompt is given before overwriting the target file, asking the user to confirm whether to overwrite, and the target file will be overwritten when answering y.
  • p: In addition to copying the content of the file, the modification time and access rights are also copied to the new file.
  • r: If the given source file is a directory file, all subdirectories and files under the directory will be copied.
  • l: Do not copy files, just generate link files.
cp -r /etc test  #将/etc下所有子目录及文件复制到test目录下

insert image description here

3. Use the cd and ls commands to access and view the "/root/test/etc" directory.

insert image description here

4. Change permissions and owners, use the ls command to view the difference

ls -l /root/test

insert image description here

chmod 777 /root/test/etc

insert image description here

5. Pack the "/root/test/etc" directory into etc.tar.gz with the tar command, check the contents of etc.tar.gz, and decompress etc.tar.gz.

tar [选项]  文件目录列表
  • c or --create to create a new backup file.
  • f<backup file> or –file=<backup file> specifies the backup file.
  • z or --gzip or --ungzip Process the backup file through the gzip command.
  • v or --verbose displays the instruction execution process.
  • r or --append Add new files to the end of existing backup files.
  • t or –list lists the contents of the backup file.
  • x or --extract or --get restore files from backup files.
//压缩打包
tar -cvf /root/test/etc.tar /root/test
gzip /root/test/etc.tar  
ls /root/test

insert image description here

//解压缩
tar -zxf /root/test/etc.tar.gz

insert image description here
Check

ls root/test/etc #在/root/test目录下查看

insert image description here

6. Delete the "test" directory.

rm -r -f /root/test

insert image description here

7. Set umask. Recreate the test directory and check the permissions.

insert image description here

Guess you like

Origin blog.csdn.net/h_adam/article/details/128199619