search
HomeSystem TutorialLINUXHow to use Linux commands to create or delete folders?

How to use Linux commands to create or delete folders?

Feb 29, 2024 pm 02:13 PM
linuxfolderOrder

PHP editor Youzi will introduce you in detail how to use commands to create or delete folders in Linux systems. In Linux, use the mkdir command to create a new directory, and use the rm command to delete a directory. These two commands are the most basic and commonly used folder operation commands in Linux systems. Mastering them can help you manage the file system more efficiently. Next, we will explain how to use these two commands one by one, so that you can easily master the skills of creating or deleting folders.

How to use Linux commands to create or delete folders?

What is a Linux system?

Linux is a free-to-use and freely disseminated Unix-like operating system. It is a multi-user, multi-task, multi-thread and multi-CPU operating system based on POSIX and UNIX. Linux inherits the network-centric design philosophy of Unix and is a multi-user network operating system with stable performance. It can run major UNIX software tools, applications and network protocols. It supports 32-bit and 64-bit hardware.

1. Linux delete folder command

Deleting a directory in Linux is very simple. Many people are still accustomed to using rmdir. However, once the directory is not empty, they will fall into deep distress. Now use the rm -rf command.

Just rm directly, but you need to add two parameters -rf, namely: rm -rf directory name

Note: Be extra careful when using rm -rf. Linux does not have a recycle bin.

1. Delete directories and files rm(remove)

Function description: Delete files or directories.

Syntax: rm [-dfirv][--help][--version][file or directory]

Supplementary instructions: Execute the rm command to delete files or directories. If you want to delete a directory, you must add the parameter "-r", otherwise only the files will be deleted by default.

parameter:

  • -d or –directory Directly delete the hard link data of the directory to be deleted to 0 and delete the directory.
  • -f or –force Forcefully delete files or directories.
  • -i or –interactive Ask the user before deleting existing files or directories.
  • -r or -R or –recursive Recursive processing, processing all files and subdirectories in the specified directory together.
  • -v or –verbose Display the instruction execution process.

2. Delete folder:

de>rm -rf fileNamede>

Delete folder instance:

rm -rf /var/log/httpd/access

The /var/log/httpd/access directory and all files and folders under it will be deleted.

3. Delete files:

de>rm -f fileNamede>

2. Linux add file command

1. Create directories: mkdir(make directories)

Syntax: mkdir [-p][--help][--version][-m ][Directory Name]

Note: mkdir can create a directory and set the permissions of the directory at the same time.

parameter:

  • -m or –mode Set the directory permissions when creating the directory.
  • -p or –parents If the upper-level directory of the directory to be created has not been created yet, the upper-level directory will be created together.

Example: mkdir test

2. Create file touch

Function Description: Change file or directory time

Syntax: touch [-acfm][-d ][-r ][-t ] [--help] [--version][file or directory] or touch [-acfm][--help][--version][date and time][file or directory]

Note: Use the touch command to change the date and time of a file or directory, including access time and change time.

parameter:

  • -a or –time=atime or –time=access or –time=use Change only the access time.
  • -c or –no-create Do not create any files.
  • -d Use the specified date and time instead of the current time.
  • -f This parameter will be ignored and will not be processed. It is only responsible for solving the compatibility problem of the BSD version of the touch command.
  • -m or –time=mtime or –time=modify Only change the change time.
  • -r Set the date and time of the specified file or directory to be the same as the date and time of the reference file or directory.
  • -t Use the specified date and time instead of the current time.

Example: touch test.txt

Note: There is no file suffix name to distinguish file types under Linux. The system file types are only executable files and non-executable files.

The above is the detailed content of How to use Linux commands to create or delete folders?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:脚本之家. If there is any infringement, please contact admin@php.cn delete
How to Make a USB Drive Mount Automatically in LinuxHow to Make a USB Drive Mount Automatically in LinuxApr 30, 2025 am 10:04 AM

This guide explains how to automatically mount a USB drive on boot in Linux, saving you time and effort. Step 1: Identify Your USB Drive Use the lsblk command to list all block devices. Your USB drive will likely be labeled /dev/sdb1, /dev/sdc1, etc

Best Cross-Platform Apps for Linux, Windows, and Mac in 2025Best Cross-Platform Apps for Linux, Windows, and Mac in 2025Apr 30, 2025 am 09:57 AM

Cross-platform applications have revolutionized software development, enabling seamless functionality across operating systems like Linux, Windows, and macOS. This eliminates the need to switch apps based on your device, offering consistent experien

Best Linux Tools for AI and Machine Learning in 2025Best Linux Tools for AI and Machine Learning in 2025Apr 30, 2025 am 09:44 AM

Artificial Intelligence (AI) is rapidly transforming numerous sectors, from healthcare and finance to creative fields like art and music. Linux, with its open-source nature, adaptability, and performance capabilities, has emerged as a premier platfo

5 Best Lightweight Linux Distros Without a GUI5 Best Lightweight Linux Distros Without a GUIApr 30, 2025 am 09:38 AM

Looking for a fast, minimal, and efficient Linux distribution without a graphical user interface (GUI)? Lightweight, GUI-less Linux distros are perfect for older hardware or specialized tasks like servers and embedded systems. They consume fewer res

How to Install Wine 10.0 in RedHat DistributionsHow to Install Wine 10.0 in RedHat DistributionsApr 30, 2025 am 09:32 AM

Wine 10.0 stable version release: Running Windows applications on Linux to a higher level Wine, this open source and free application, allows Linux users to run Windows software and games on Unix/Linux operating systems, ushering in the release of the 10.0 stable version! This version has been provided with source code and binary package downloads, and supports various distributions such as Linux, Windows and Mac. This edition embodies a year of hard work and over 8,600 improvements, bringing many exciting improvements. Key highlights include: Enhanced support for Bluetooth devices. Improve support for HID input devices. Optimized performance of 32-bit and 64-bit applications.

How to Install and Configure SQL Server on RHELHow to Install and Configure SQL Server on RHELApr 30, 2025 am 09:27 AM

This tutorial guides you through installing SQL Server 2022 on RHEL 8.x or 9.x, connecting via the sqlcmd command-line tool, database creation, and basic querying. Prerequisites Before beginning, ensure: A supported RHEL version (RHEL 8 or 9). Sudo

How to Install Thunderbird 135 on a Linux DesktopHow to Install Thunderbird 135 on a Linux DesktopApr 30, 2025 am 09:26 AM

Mozilla Thunderbird 135: Powerful cross-platform mail client Mozilla Thunderbird is a free, open source, cross-platform email, calendar, news, chat and contact management client designed to efficiently handle multiple email accounts and news sources. On February 5, 2025, Mozilla released the Thunderbird 135 version, introducing a number of new features, performance improvements and security fixes. Thunderbird 135 main features: XZ Packaging for Linux Binaries: Smaller files, faster unpacking, and better integration with modern distributions. Cookie storage support: when creating space

How to Lock Files for Renaming or Deleting in LinuxHow to Lock Files for Renaming or Deleting in LinuxApr 30, 2025 am 09:11 AM

This guide demonstrates how to protect files on Linux from accidental renaming or deletion using simple commands. We'll use the file important.txt in /home/user/ as an example. Method 1: Using chattr for Immutability The chattr command modifies fil

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools