Deleting files with spaces in Linux (not directories)

Deleting files with spaces in Linux (not directories)

In our daily work, we often come into contact with files without spaces. This makes the deletion operation much simpler. But sometimes we come across files with spaces in them. How should we delete this kind of file?

First, let's demonstrate how to use the find command combined with the xargs command to delete files without spaces.

[root@ELK-chaofeng test]# touch 1.txt 2.txt
[root@ELK-chaofeng test]# ls
1.txt 2.txt
[root@ELK-chaofeng test]# find . -type f | xargs
./1.txt ./2.txt
[root@ELK-chaofeng test]# find . -type f | xargs rm -rf
[root@ELK-chaofeng test]# ls
[root@ELK-chaofeng test]#

Next we demonstrate deleting files with spaces

[root@ELK-chaofeng test]# touch 1.txt 2.txt '1 2.txt'
[root@ELK-chaofeng test]# ls
1 2.txt 1.txt 2.txt
[root@ELK-chaofeng test]# ll
total 0
-rw-r--r-- 1 root root 0 Feb 14 12:24 1 2.txt
-rw-r--r-- 1 root root 0 Feb 14 12:24 1.txt
-rw-r--r-- 1 root root 0 Feb 14 12:24 2.txt
[root@ELK-chaofeng test]# find . -type f -print0 | xargs -0 rm -rf
[root@ELK-chaofeng test]# ls

The above parameter -print0, compared with the default -print, outputs sequences separated by null characters instead of spaces. xargs also has a parameter -0, which can accept input streams separated by null instead of spaces.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Summary of 10 ways to delete files in a directory in Linux
  • How to delete special character file names or directories in Linux
  • Linux uses lsof/extundelete tools to restore accidentally deleted files or directories
  • Deleting files in a directory using C language in Linux

<<:  Monitor changes in MySQL table content and enable MySQL binlog

>>:  Why is it not recommended to use index as key in react?

Recommend

CSS draw a lollipop example code

Background: Make a little progress every day, acc...

XHTML tutorial, a brief introduction to the basics of XHTML

<br />This article will briefly introduce yo...

Example code for implementing photo stacking effect with CSS

Achieve results step 1. Initial index.html To bui...

TypeScript union types, intersection types and type guards

Table of contents 1. Union Type 2. Crossover Type...

Analyze the difference between computed and watch in Vue

Table of contents 1. Introduction to computed 1.1...

Example of disabling browser cache configuration in Vue project

When releasing a project, you will often encounte...

Execute the shell or program inside the Docker container on the host

In order to avoid repeatedly entering the Docker ...

MySQL quickly inserts 100 million test data

Table of contents 1. Create a table 1.1 Create te...

Basic usage tutorial of IPTABLES firewall in LINUX

Preface For production VPS with public IP, only t...

Vue integrates PDF.js to implement PDF preview and add watermark steps

Table of contents Achieve results Available plugi...

Detailed explanation of MySQL injection without knowing the column name

Preface I feel like my mind is empty lately, as I...

JavaScript implements click toggle function

This article example shares the specific code of ...

Let's talk about the size and length limits of various objects in MySQL

Table of contents Identifier length limit Length ...

How to connect to docker server using ssh

When I first came into contact with docker, I was...

Detailed explanation of react setState

Table of contents Is setState synchronous or asyn...