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

Detailed installation and use of SSH in Ubuntu environment

SSH stands for Secure Shell, which is a secure tr...

Vue implements form validation function

This article mainly describes how to implement fo...

Vue implements the countdown component for second kills

This article shares the specific code of Vue to i...

HTML+CSS3 code to realize the animation effect of the solar system planets

Make an animation of the eight planets in the sol...

MySQL 8.0.21 installation and configuration method graphic tutorial

Record the installation and configuration method ...

SELinux Getting Started

Back in the Kernel 2.6 era, a new security system...

Analyzing ab performance test results under Apache

I have always used Loadrunner to do performance t...

How to implement draggable components in Vue

This article shares with you how to implement dra...

Vertical and horizontal splitting of MySQL tables

Vertical Split Vertical splitting refers to the s...

jQuery uses the canvas tag to draw the verification code

The <canvas> element is designed for client...

js to achieve cool fireworks effect

This article shares the specific code for using j...

JavaScript event delegation principle

Table of contents 1. What is event delegation? 2....

React.js framework Redux basic case detailed explanation

react.js framework Redux https://github.com/react...

Docker MQTT installation and use tutorial

Introduction to MQTT MQTT (Message Queuing Teleme...