Home > System Tutorial > LINUX > How to create files and folders under Linux?

How to create files and folders under Linux?

WBOY
Release: 2024-02-18 13:24:22
Original
1849 people have browsed it

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.

  1. New file command: touch

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
Copy after login

Example 2: Create a new file named "newfile.txt" under the absolute path "/home/user/documents/".

touch /home/user/documents/newfile.txt
Copy after login
  1. New folder command: mkdir

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
Copy after login

Example 2: Create a new folder named "new_folder" under the absolute path "/home/user/documents/".

mkdir /home/user/documents/new_folder
Copy after login
  1. Command to create a new multi-level folder: mkdir -p

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
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template