Deleting all files except a specific one?

Mike K

How do I delete all files that start with 'labtest,' but keep the file 'labtest' itself undeleted?

I was trying

rm labtest*[!"labtest"]

But that didn't work out too well.


Question 5

Enter a command to delete all files that have filenames starting with 'labtest',
 except 'labtest' itself, from the current directory (Delete all files starting
with 'labtest' followed by one or more characters).

You entered: rm *labtest?![labtest]
Please try again.

roaima

This will delete all files in the current directory starting with labtest except for the file labtest itself. It will not consider files unless they begin with labtest

echo labtest?*    # List files that begin with "labtest"

rm labtest?*      # Delete them

The question-mark is a single character wildcard: it must match something. The asterisk is a globbing wildcard and will match zero or more characters. The combination ensures that we cannot match just labtest by itself.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Delaying all items except specific one

From Dev

how to tail all files except one

From Dev

Git: Checkout all files except one

From Dev

How to catch all exceptions except a specific one?

From Dev

Remove all elements with specific class except for one

From Dev

Deleting a all files in a folder except one folder in windows command prompt or batch script?

From Dev

Ignore all files and files in subdirectories except one file

From Dev

How to add all source files in a folder, except for specific files?

From Dev

Delete all files except filenames with specific string

From Dev

Deny all configuration files except one in Apache

From Dev

select all forms except one without specific action using css

From Dev

Deleting everything, except for two files

From Dev

Restore all files except one folder

From Dev

Deleting all files in a folder except files X, Y, and Z

From Dev

delete all files of specific pattern without deleting the presently using file

From Dev

Is it possible to have Nautilus show hidden files except for one specific folder?

From Dev

make git commit all files of specific type except for a couple

From Dev

Ignore all files and files in subdirectories except one file

From Dev

Remove all files/directories except for one file

From Dev

How to delete all files and directory except one named directory from a specific folder in centos

From Dev

list all files with extension .log except one

From Dev

staging all files except specific files using glob patterns in git

From Dev

Deleting everything, except for two files

From Dev

Get all files from dir and all subdirs EXCEPT one subdir

From Dev

Deleting all subfolders except one recursively

From Dev

(VBA) apply to all, except one specific

From Dev

recursively delete all files+folders except a specific one file in solaris

From Dev

Remove all hidden files except specific files

From Dev

How to delete all files except those created on a specific day of the week?

Related Related

  1. 1

    Delaying all items except specific one

  2. 2

    how to tail all files except one

  3. 3

    Git: Checkout all files except one

  4. 4

    How to catch all exceptions except a specific one?

  5. 5

    Remove all elements with specific class except for one

  6. 6

    Deleting a all files in a folder except one folder in windows command prompt or batch script?

  7. 7

    Ignore all files and files in subdirectories except one file

  8. 8

    How to add all source files in a folder, except for specific files?

  9. 9

    Delete all files except filenames with specific string

  10. 10

    Deny all configuration files except one in Apache

  11. 11

    select all forms except one without specific action using css

  12. 12

    Deleting everything, except for two files

  13. 13

    Restore all files except one folder

  14. 14

    Deleting all files in a folder except files X, Y, and Z

  15. 15

    delete all files of specific pattern without deleting the presently using file

  16. 16

    Is it possible to have Nautilus show hidden files except for one specific folder?

  17. 17

    make git commit all files of specific type except for a couple

  18. 18

    Ignore all files and files in subdirectories except one file

  19. 19

    Remove all files/directories except for one file

  20. 20

    How to delete all files and directory except one named directory from a specific folder in centos

  21. 21

    list all files with extension .log except one

  22. 22

    staging all files except specific files using glob patterns in git

  23. 23

    Deleting everything, except for two files

  24. 24

    Get all files from dir and all subdirs EXCEPT one subdir

  25. 25

    Deleting all subfolders except one recursively

  26. 26

    (VBA) apply to all, except one specific

  27. 27

    recursively delete all files+folders except a specific one file in solaris

  28. 28

    Remove all hidden files except specific files

  29. 29

    How to delete all files except those created on a specific day of the week?

HotTag

Archive