REMOVE MULTIPLE FILES EXCEPT ONE IN LINUX

I need to remove all of the files in the current directory except one directory “scripts”

[oracle@staxrac1 ~]$ ls
addnode     data         env.ora        jlib                          olap     perl      root.sh.old    sqlpatch
apex        dbjava       has            ldap                          OPatch   plsql     root.sh.old.1  sqlplus
assistants  dbs          hs             lib                           opmn     precomp   runInstaller   srvm
bin         deinstall    install        LINUX.X64_193000_db_home.zip  oracore  QOpatch   schagent.conf  suptools
clone       demo         instantclient  md                            ord      R         scripts        ucp
crs         diagnostics  inventory      mgw                           ords     racg      sdk            usm
css         dmu          javavm         network                       oss      rdbms     slax           utl
ctx         drdaas       jdbc           nls                           oui      relnotes  sqldeveloper   wwg
cv          dv           jdk            odbc                          owm      root.sh   sqlj           xdk

This can be accomplished using the below way

[oracle@staxrac1 ~]$ ls |grep -xv "scripts"|xargs rm -rf
[oracle@staxrac1 ~]$ ls
scripts

Leave a Reply