Unix C++
Would you like to react to this message? Create an account in a few clicks or log in to continue.

listing and deleting directories

+2
Christopher
parvathy
6 posters

Go down

listing and deleting directories Empty listing and deleting directories

Post by parvathy Wed Mar 03, 2010 4:17 pm

how to list and delete more than one directories in one single command??????

parvathy

Posts : 7
Points : 15
Join date : 2010-02-26

Back to top Go down

listing and deleting directories Empty Re: listing and deleting directories

Post by Christopher Wed Mar 03, 2010 5:38 pm

Code:
$ ls -d */ | xargs rm -r

the above command will delete only the directories in the present directory without deleting files.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

listing and deleting directories Empty Re: listing and deleting directories

Post by parvathy Wed Mar 03, 2010 5:42 pm

hey......thanks

parvathy

Posts : 7
Points : 15
Join date : 2010-02-26

Back to top Go down

listing and deleting directories Empty Re: listing and deleting directories

Post by Navitha Thu Mar 04, 2010 12:58 pm

what does xagrs stands for. I know rm is for remove command what does - r do

Navitha

Posts : 14
Points : 24
Join date : 2010-02-26

Back to top Go down

listing and deleting directories Empty Re: listing and deleting directories

Post by Christopher Thu Mar 04, 2010 1:08 pm

xargs is used to pass more than one arguments to a command. In this example, the output of ls command is passed as argument to rm. Each file or directory in the output of ls command will be passed as arguments to rm individually.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

listing and deleting directories Empty Re: listing and deleting directories

Post by Navitha Thu Mar 04, 2010 1:36 pm

Hey thanks, I understood the xargs command what about the -r command.

Navitha

Posts : 14
Points : 24
Join date : 2010-02-26

Back to top Go down

listing and deleting directories Empty Re: listing and deleting directories

Post by urvershi Thu Mar 04, 2010 1:38 pm

-r or -R is used to recursively remove the files or directories.

urvershi

Posts : 21
Points : 70
Join date : 2010-02-26

Back to top Go down

listing and deleting directories Empty xargs

Post by jeeva Thu Mar 04, 2010 2:04 pm

xargs is to pass more than one arguements..
does it mean that if there is only one directory being passed then xargs is not required??
can you give some more examples!

jeeva

Posts : 50
Points : 93
Join date : 2010-03-04

Back to top Go down

listing and deleting directories Empty Re: listing and deleting directories

Post by jeeva Thu Mar 04, 2010 2:10 pm

actually both -r and -R recursively removes a directory but wats the difference!!!

jeeva

Posts : 50
Points : 93
Join date : 2010-03-04

Back to top Go down

listing and deleting directories Empty Re: listing and deleting directories

Post by Christopher Thu Mar 04, 2010 2:14 pm

i dont think so. Even if the output of ls is a single value, it wont work. if u r using a command('ls') which produce list of values, u have to use xargs.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

listing and deleting directories Empty Re: listing and deleting directories

Post by anand Thu Mar 04, 2010 2:18 pm

by mistake i have deleted all directories ... how to recover those.?...........
anand
anand

Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36

Back to top Go down

listing and deleting directories Empty Re: listing and deleting directories

Post by Christopher Thu Mar 04, 2010 2:33 pm

I think it is not possible to recover deleted files if u r in multiuser mode. i recommend adding more immunity to ur files which can prevent accident deletion of files.

for adding immunity

Code:
chattr +i file

for removing immunity

Code:
chattr -i file

anyways... these commands will work only for root user.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

listing and deleting directories Empty Re: listing and deleting directories

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum