简体   繁体   中英

Linux: How to delete all of the files (not directories) inside a directory itself (not childs)

There are some files in a directory whose names is not usual (Eg in unicode format). How to delete them?


First, find the files and then delete them:

find [dir_path] -maxdepth 1 -type f  | xargs rm -rf

Above is simple and not works when there is a space in any of file name(s). So, I've written a complex and complete command to handle spaces also:

find ./ -maxdepth 1 -type f  | awk -F '/' '{printf "'\''%s'\''\n",$2}' | xargs rm -rf

" -maxdepth 1 " means just from the directory not childs. In the other means, not recursive find. As you know, " xargs " executes a following command on the list sent to it.

You can just use the rm :

rm .* *

It doesn't delete directories and doesn't recurse into them by default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM