![]() |
|
|
|
|
|||||||
| Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| deleting specific lines from all files in a directory | vrms | UNIX for Dummies Questions & Answers | 3 | 04-25-2008 08:08 AM |
| deleting empty files in a directory | berlin_germany | Shell Programming and Scripting | 5 | 01-26-2007 11:47 AM |
| shell script: deleting files from a directory | onlyc | Shell Programming and Scripting | 1 | 07-09-2006 03:41 AM |
| Accidentally deleting directory/files | milhan | UNIX for Advanced & Expert Users | 4 | 08-27-2003 06:59 AM |
| Deleting A Directory! | firefinger | UNIX for Dummies Questions & Answers | 2 | 10-19-2001 09:17 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi Guys,
I want to know wheather it is possible to delete directory not files, Example: In one directory there are 10 dirs and 100 files but my req is to delete only dirs not file Wheather it is possible ? |
| Forum Sponsor | ||
|
|
|
|||
|
Code:
for d in dir/*/.; do
rmdir "${d%/.}"
done
|
|
|||
|
yes sometimes we just miss the simplest things. however take note it still suffers from "argument too long" issues if there are too many directories ( maybe there's a workaround somewhere)
Code:
# ls -p | grep "/" | wc -l
31998
# rm -r */
bash: /bin/rm: Argument list too long
# ls -p|awk '/\/$/&&!/\./' | xargs -i rm -rf "{}"
# ls -p | grep "/" | wc -l
0
|
|
||||
|
Quote:
Just to make it clear, I don't think ls and awk are needed in the case you describe (argument list too long). Code:
for d in */;do rm -r "$d";done Code:
xargs -0n1000 rm -r < <(printf "%s\000" */) Code:
autoload -U zargs zargs *(/) -- rm -r Last edited by radoulov; 04-13-2008 at 10:36 AM. Reason: corrected |
| Thread Tools | |
| Display Modes | |
|
|