- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shell script: how to check whether a directory...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2002 07:21 AM
10-18-2002 07:21 AM
--------------
#!/bin/sh
echo "Enter source directory: \c"
read dir1
echo "Enter destination directory: \c"
read dir2
pth=$PWD
cd "$dir1"
if [ ??? ] #Problem: How to do the checking here?
then
echo "no files in directory"
else
mv * "$pth"/"$dir2"
echo "Files transfered!"
fi
--------------
How do I do the checking of whether the directory is empty or not?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2002 07:26 AM
10-18-2002 07:26 AM
SolutionNFILES=$(ls ${dir1} | wc -l)
if [[ ${NFILES} -eq 0 ]]
then
echo "${dir1} is empty".
fi
You might also add some checking to make sure that ${dir1} exists and is a directory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2002 07:34 AM
10-18-2002 07:34 AM
Re: Shell script: how to check whether a directory is empty?
ls -a ${dir1}| grep -v -e ^.$ -e ^..$ |wc -l
Rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2002 11:39 AM
10-18-2002 11:39 AM
Re: Shell script: how to check whether a directory is empty?
grep -v ".." | wc -l)
#!/bin/sh
echo "Enter source directory: \c"
read dir1
echo "Enter destination directory: \c"
read dir2
pth=$PWD
cd $dir1
if [ $empty = "0" ]
then
echo "directory is empty"
else
mv * "$pth"/"$dir2"
echo "Files transfered!"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2002 11:40 AM
10-18-2002 11:40 AM
Re: Shell script: how to check whether a directory is empty?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2002 05:16 AM
10-22-2002 05:16 AM