Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

how to remove all files except one in linux

# if you are using a loop

shopt -s extglob

rm -rf !("abc.txt" | "abc.log" )  # others will be removed except these two
OR
rm -v !(*.zip|*.odt)

shopt -u extglob 
Comment

linux remove all files except specific ones

# Basic syntax:
find /directory/to/search -type f -name "pattern_to_match" ! -name "pattern_to_ignore" -delete

# Example usage:
touch file1 file2 file3

# This will delete all files except those containing "3"
find . -type f -name "*file*" ! -name "*3*" -delete

# Note, if I'm only deleting a moderate number of files, I prefer to use the
#	following which asks for confirmation before deleting:
find . -type f -name "*file*" ! -name "*3*" -ok rm -- {} ;
Comment

PREVIOUS NEXT
Code Example
Shell :: netlify build command 
Shell :: how to initialize a git repository command line 
Shell :: get pytorch version version in ubuntu 
Shell :: rsync port ssh 
Shell :: pscp ubuntu copy folder recursively 
Shell :: pip install geopandas 
Shell :: ubuntu delete from ssh known hosts 
Shell :: install all pack kubectl kubens kubectx 
Shell :: git stop tracking directory 
Shell :: how to extract tar.gz file in colab 
Shell :: react-native clean and rebuild 
Shell :: update yarn global 
Shell :: Install Nginx, MariaDB and PHP centos rhel 
Shell :: see if urdf is valid 
Shell :: Brew was unable to install [php@7.1]. 
Shell :: kubectl restart deployment 
Shell :: Could not install packages due to an EnvironmentError: [WinError 32] The process cannot access the file because it is being used by another process 
Shell :: device or resource busy 
Shell :: apache default config 
Shell :: how to push code to github forcefully 
Shell :: move hidden files linux 
Shell :: trojitá ubuntu 
Shell :: how is linux 
Shell :: tmux how to kill all sessions 
Shell :: powershell join array 
Shell :: android studio 
Shell :: permission denied while installing npm 
Shell :: docker clear build cache 
Shell :: merge changes into previous commit 
Shell :: install wget 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =