|
| cool Statistics |
| | coolcommands: | 1338 | | Categories: | 83 | | Total queries: | 620363 | | Members: | 22813 | |
|
|
|
 |
|
|
Search coolcommands.com
 |
Submitted by:
lvo   |
coolcommand
Korn shell script to return if a directory is empty or not |
Description
Here is a little ksh script to return whether a directory is empty or not.
Return code 0 = empty Return code 1 = non empty Return code 2 = not a directory
#!/bin/ksh
# Format: emptydir.ksh [dirname] - default "."
typeset file dir=${1:-.}
[[ -d $dir ]] || { print -u2 "$0: $dir is not a directory"; return 2; }
for file in $dir/.* $dir/* do case ${file#$dir/} in
.|..) ;;
[*]) [[ -a $file ]];let $?;return;;
*) return 1;;
esac done
Sample runs:
1) Test current directory (.) - return code 1 = no # ./emptydir.ksh # echo $? 1
2) Test directory emptydir - return code 0 = empty # ./emptydir.ksh ./emptydir # echo $? 0
3) Test directory ./some/dir/non/existant - return code 2 = non existant directory # ./emptydir.ksh ./some/dir/non/existant ./emptydir.ksh: ./some/dir/non/existant is not a directory # echo $? 2 |
Example
emptydir.ksh |
Return to search results
 |  |  |  |
Random coolcommands
coolcommand: kill all the processes of a particular user
Example: ps -fU username | awk '{ system ("kill "$2)}'
[show me the details] |
coolcommand: how to prepare older Linux systems for 2007 DST change
Example: rpm –u tzdata-2006m-3.el4.noarch.rpm; reboot
[show me the details] |
coolcommand: how to determine the maximum number of user processes in Linux
Example: ulimit -u
[show me the details] |
coolcommand: how to add a disk to a volume group in AIX
Example: extendvg rootvg hdisk3
[show me the details] |
|
|
coolcommands.com - the search engine for UNIX sysadmins :: unix commands and scripts
|  |  |  |  |
|
|
|
|
 |
|
|
|
Top 5 Submitters
|
|---|
| lvo | 1160 |
| audet | 37 |
| kah00na | 32 |
| Mariom | 24 |
| lebjf000 | 14 |
Top 5 Searches
|
| Category Solaris | 51966 |
| Category AIX | 49058 |
| Category General UNIX | 47587 |
| solaris | 23554 |
| aix | 22739 |
|
|
|
|