Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash remove all files in directory except a few

## Ensure you enable this first!
shopt -s extglob

## Delete all file except file1 ##
rm  !(file1)
 
## Delete all file except file1 and file2 ##
rm  !(file1|file2) 
 
## Delete all file except all zip files ##
rm  !(*.zip)
 
## Delete all file except all zip and iso files ##
rm  !(*.zip|*.iso)
 
## You set full path too ##
rm /Users/vivek/!(*.zip|*.iso|*.mp3)
 
## Pass options ##
rm [options]  !(*.zip|*.iso)
rm -v  !(*.zip|*.iso)
rm -f  !(*.zip|*.iso)
rm -v -i  !(*.php)
Comment

PREVIOUS NEXT
Code Example
Shell :: how to compress pdf in linux 
Shell :: libxml2 install 
Shell :: npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: react-template@0.1.0 npm ERR! Found: react@18.0.0 
Shell :: bash return position of matching string 
Shell :: how to download utorrent in kali linux 
Shell :: discord components python install 
Shell :: chmod folder recursive 
Shell :: apache .htaccess Option ubuntu 
Shell :: how to cd to a directory with spaces 
Shell :: linux batch resize jpg 
Shell :: how to use multiple commands in linux 
Shell :: telegram on archlinux 
Shell :: requires pyqtwebengine<5.13, which is not installed. 
Shell :: install pip3.9 
Shell :: git unrelated histories 
Shell :: gimp deselect 
Shell :: how to use f12 
Shell :: for k in range bash 
Shell :: git crdencial --cache 
Shell :: recursively remove files with extension linux 
Shell :: how discharge changes e recover last commit git 
Shell :: brownie delete account 
Shell :: update cargo 
Shell :: execute powershell file windows 
Shell :: raspberry pi wifi setup wpa_supplicant 
Shell :: sudo apt-get install podman 
Shell :: how to clone a specific git tag 
Shell :: netcdf4 install conda 
Shell :: apt check if package is installed 
Shell :: git fix Large files detected. 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =