|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How can I remove all files and folders in a directory except one perticular file?
Suppose in a folder we have files f1,f2,f3.In this I want to delete all files except f1. can any one tel me? thanks in advance.. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
ls *|grep -v f1|xargs rm -rf
|
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Or copy f1 to /tmp, rm all the files in the current directory and move back /tmp/f1 to the current directory.
|
|
#4
|
||||
|
||||
|
Quote:
Code:
rm !(f1) [zsh] Code:
rm ^f1 [bash] Code:
shopt -s extglob rm !(f1) |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Sorry for bumping this, but . . .
if i wanted to delete all files and/or folders inside a specific folder but keep the files and folders that start with p and m, i should do . . . rm -R *.* !(p*) !(m*) is that correct ? Thanks ! |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
After enabling the extended glob you could try something like this: Code:
rm -r -- !(@(m|p)*) |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to remove blank lines in a file and save the file with same name? | vel4ever | Shell Programming and Scripting | 6 | 01-10-2012 02:31 AM |
| rm: cannot remove file: Read-only file system | figaro | UNIX for Dummies Questions & Answers | 4 | 12-23-2011 01:14 AM |
| Remove duplicate lines from first file comparing second file | gani_85 | Shell Programming and Scripting | 3 | 10-21-2011 07:43 AM |
| how to copy a file without remove the contents of the target file? | ahmedamer12 | UNIX for Dummies Questions & Answers | 2 | 04-22-2011 05:19 PM |
| Batch file to remove double quotes from a file | akashtcs | Shell Programming and Scripting | 11 | 01-11-2010 10:05 AM |
|
|