Home > Common Problem > body text

What are the linux deletion commands?

zbt
Release: 2023-09-21 10:58:50
Original
8054 people have browsed it

Linux is an open source operating system widely used in servers, personal computers and other fields. In Linux systems, there are many different commands that can be used to delete files, directories, and links. This article will introduce some commonly used Linux deletion commands and their usage.

1. rm command: The rm command is used to delete files and directories. The basic syntax is:

rm [options] file name/directory name

Options:

-r: recursively delete the directory and its contents

- f: Forced deletion, no confirmation prompt

-i: Interactive deletion, prompt for confirmation before deletion

Example:

Delete file: rm file.txt

Delete directory: rm -r directory

2. rmdir command: The rmdir command is used to delete empty directories. The basic syntax is:

rmdir [options] Directory name

Options:

-p: Recursively delete the directory and delete its parent directory (if empty)

Example:

Delete an empty directory: rmdir directory

3. unlink command: The unlink command is used to delete files or symbolic links. The basic syntax is:

unlink file name/symbolic link name

Example:

Delete file: unlink file.txt

Delete symbolic link: unlink link

4. find command: The find command is used to find files and perform corresponding operations, including deletion. The basic syntax is:

find directory -name "file name" -exec rm {} \;

Example:

Delete all files ending with .txt in the current directory File: find . -name "*.txt" -exec rm {} \;

5. shred command: The shred command is used to safely delete files, that is, completely delete the file and overwrite its contents. The basic syntax is:

shred [options] File name

Options:

-u: Overwrite the content after deleting the file

-n: Specify Number of overwrites, the default is 3 times

Example:

Safely delete files: shred -u file.txt

Summary:

This article introduces some commonly used Linux deletion commands, including rm, rmdir, unlink, find and shred. These commands can be used to delete files, directories and links, providing different options and functions to meet different needs. When using these commands, you need to operate with caution to ensure that the correct files or directories are deleted to avoid irreparable losses. .

The above is the detailed content of What are the linux deletion commands?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!