First
let’s go through the RM command in UNIX:
The
rm command is used in Unix / Linux to remove a file or a directory. The syntax
is as follows:
Syntax:
rm [OPTION] [FILE]
OPTION’s
include
>
rm –f {file-name} – To remove files forcefully without prompting to the user.
>
rm –i {file-name} – To remove files by prompting to the user for confirming.
>
rm –r {file-name} – To remove files in directories recursively.
Now
we will see how to delete All Files in Directory except Few files>
1)
USING RM COMMAND:
To
remove all files from directory /home/opt/class/ except .log and .zip
> rm /home/opt/class/ !(*.zip|*.log)
To
remove all files except a specific file (file123)
> rm !(file123)
2)
USING FIND COMMAND:
Find
command is used to search the files in a particular directory.
To
remove all files from directory /home/opt/class/ except .log
> find /home/opt/class/
-iname "*.log" –delete
You
can use ‘-name’ command for case sensitive search and ‘-iname’ for search not considering case.
Some
other applications of using rm command;
To
delete all files in the current directory;
>
rm
/home/opt/class/ * (Use interactive mode ‘i’ to be on safer
side)
To
delete files in a directory that has any of the enclosed characters. In this
example characters to be checked are A, B OR C
>
rm *[ABC]*
Good stuff, but why the contents cannot be copy to save? Is that design like that in purpose to keep copyright?
ReplyDeleteHi,.I think you can copy it.Please try again :)
Delete