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.jck8banddo.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).
Double-check before deleting (optional but recommended!)
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

