Basic properties of the file
basic attributes
In Linux, every file has a set of basic attributes. You can use ls -l
the command to view the detailed properties of the file.
The following is ls -l(简写ll)
an example of command output:
In this example, we can interpret the following basic properties:
-rw-r--r--
: This part indicates the access permission of the file. The first character indicates the file type,-
which indicates a normal file, andd
indicates a directory. The following characters are divided into three groups (3 characters in each group), which respectively represent the permissions of the file owner (user), the permissions of the group to which the file belongs, and the permissions of other users. Each character represents a permission,r
which means read permission,w
write permission,x
execute permission,-
or no permission.
1
: This number indicates the number of links, that is, how many file names point to this file.
root
: This is the owner (user) of the file.
root
: This is the group the file belongs to.
1243
: This is the size of the file in bytes.Jul 20 10:32 : This is the time the file was last modified.
anaconda-ks.cfg
: This is the name of the file.
These are the basic attributes of the file, which can be modified by other commands such as chmod
and .chown
Change file properties
To change the attributes of a Linux file, you can use the chmod command. This command allows you to change the permissions of a file, including read, write, and execute permissions. For example, to set the owner permission of a file to read, write, and execute, the following command can be used:
chmod u+rwx filename
Among them, u represents the file owner , r represents the read permission , w represents the write permission , and x represents the execute permission . You can also use the g and o options to change a file's group and permissions for other users. For example, to set the group permission of a file to read-only, you can use the following command:
chmod g+r filename
Among them, g indicates the group to which the file belongs, and r indicates the read permission. Finally, you can use numeric notation to change the permissions of a file. For example, to set the owner permission of a file to read, write, and execute, the following command can be used:
chmod 700 filename
Among them, 7 means that the owner permission is read, write and execute, and it means that the group and other users have no permission.
Example of permission modification
echo "testInfo">text.txt
cat text.txt
ll
Get full permissions.
chmod 777 text.txt
Create a file
single creation
In the Linux operating system, files can be created in the following ways:
Use the touch command to create an empty file, for example: touch filename.txt
Use the echo command to output the content to a file, for example: echo "hello world" > filename.txt
Use editors such as vi or nano to create and edit files, for example: vi filename.txt
Use the cat command to combine multiple files into one file, for example: cat file1.txt file2.txt > filename.txt
Use the cp command to copy an existing file, for example: cp sourcefile.txt targetfile.txt
The above are several common ways to create files, and which way to use depends on the specific needs and operating habits.
Create multiple files at once
In Linux, you can use some commands to create multiple files at once, for example:
1. Touch command: you can create an empty file, you can create multiple files at the same time, for example:
touch file1 file2 file3
2.echo command: You can output the content to a file, or create multiple files at the same time, for example:
echo "hello" > file1 && echo "world" > file2 && echo "linux" > file3
3. cat command: multiple files can be combined into one file, and multiple files can also be created at the same time, for example:
cat > file1 file2 file3
The above are some commonly used methods for creating multiple files, and you can choose the appropriate method according to your actual needs.
create folder
single creation
In Linux systems, you can use mkdir
the command to create folders.
Syntax: [mkdir [options] directory name]
mkdir dir1
Create a new folder under an existing folder:
mkdir dir1/dir2
Create multi-level directories at once
Use the parameter [-p] to create a multi-level directory.
mkdir -p a/b/c/d/e