You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Shell新手求助:如何删除指定目录之外的所有目录与文件?

How to Keep Only Your Target Directories in Shell

Hey there! Since you're new to working with the Shell, let's walk through this clearly so you can keep just the four directories you want.

First, let's recap what you need to remove:

  • The directory 2018-05-22
  • The two files do.jck8b and do.jck8b.64

Step 1: Delete the unwanted files

Open your Shell and run this command to remove the two files:

rm do.jck8b do.jck8b.64

The rm command is used to delete files, and you can list multiple files separated by spaces to delete them all at once.

Step 2: Delete the unwanted directory

Next, remove the 2018-05-22 directory with this command:

rm -r 2018-05-22

The -r flag tells rm to delete the directory and all its contents (since plain rm can't delete directories that have files or subfolders inside them).

If you're worried about accidentally deleting the wrong thing, first run this command to confirm which items are present:

ls -l

This will show you the full list of files and directories exactly like the output you shared. Make sure you're only targeting the right items before running the delete commands.

After running both delete commands, run ls -l again to verify that only your four desired directories remain!

内容的提问来源于stack exchange,提问作者Manjusha Yenakandla

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:59:38