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

Docker Compose network settings explained

Basic Concepts By default, Compose creates a netw...

Vue implements user login switching

This article example shares the specific code of ...

Several ways to update batches in MySQL

Typically, we use the following SQL statement to ...

Detailed tutorial on installing Hbase 2.3.5 on Vmware + Ubuntu18.04

Preface The previous article installed Hadoop, an...

Zabbix monitoring docker application configuration

The application of containers is becoming more an...

Detailed explanation of MySQL information_schema database

1. Overview The information_schema database is th...

Tutorial on installing mysql5.7.18 on windows10

This tutorial shares the installation and configu...

About Docker security Docker-TLS encrypted communication issues

Table of contents 1. Security issues with Docker ...

Some experience in building the React Native project framework

React Native is a cross-platform mobile applicati...

Comparison of CSS shadow effects: drop-Shadow and box-Shadow

Drop-shadow and box-shadow are both CSS propertie...

A thorough analysis of HTML special characters

A Thorough Analysis of HTML (14) Special Characte...

MySQL 5.7.18 download and installation process detailed instructions

MySql Download 1. Open the official website and f...