O
O
Oleg Ponomarev2021-08-05 20:31:25
linux
Oleg Ponomarev, 2021-08-05 20:31:25

How to delete files in a directory without deleting folders?

There are directories with a file, let's say there are directories that make up the path /dir1/dir2/dir3/. How to delete files in all directories without deleting the directories themselves?

A similar command rm -f /path/to/directory/{*,.*}cannot be deleted, files are deleted only in one directory.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2021-08-05
@zamsisadmin

find /dir1 -type f -delete
Find in the folder /dir1and deeper all occurrences of the type "file" ( -type f) and delete them ( -delete)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question