Linux is a free and open source operating system widely used in servers and personal computers. In Linux, files and folders can be managed through the command line interface. This article will introduce the commands for creating files and folders in Linux and give specific code examples.
In Linux, use the "touch" command to create a new empty file. You can specify the location of the file using an absolute path or a relative path.
Example 1: Create a new file named "example.txt" under the current path.
touch example.txt
Example 2: Create a new file named "newfile.txt" under the absolute path "/home/user/documents/".
touch /home/user/documents/newfile.txt
In Linux, use the "mkdir" command to create a new folder. You can also use absolute paths or relative paths to specify the location of the folder.
Example 1: Create a new folder named "example_folder" under the current path.
mkdir example_folder
Example 2: Create a new folder named "new_folder" under the absolute path "/home/user/documents/".
mkdir /home/user/documents/new_folder
If you need to create a new multi-level folder in Linux, you can use the "mkdir -p" command. This command can create a multi-level folder structure.
Example 1: Create a new "example_folder" folder under the current path, and create a subfolder named "subfolder" under the folder.
mkdir -p example_folder/subfolder
Example 2: Create a new folder named "new_folder" under the absolute path "/home/user/documents/", and create a subfile named "sub_folder" under the folder folder.
mkdir -p /home/user/documents/new_folder/sub_folder
Summary:
New files and folders can be easily created through the Linux command line interface. Use the "touch" command to create a new empty file, and the "mkdir" command to create a new folder. If you need to create multi-level folders, you can use the "mkdir -p" command. Mastering these commands can improve the efficiency of file management and enable us to better utilize the Linux system for work and study.
The above is the detailed content of How to create files and folders under Linux?. For more information, please follow other related articles on the PHP Chinese website!