Thursday, February 10, 2011

*/ for directories

Want to do something to only the directories but not the files? Just use Bash parameter expansion: */ is "everything whose name ends with a /", eg directories.

For example:
#print all the directories
echo */
#also print all the directories (without -d it recurses)
ls -d */
#zip all the directories in target
zip myoutputfile.zip target/*/
Kinda cool.

2 comments:

farhan said...

thanks Simple but yet interesting and engaging.. Keep up the good work!
my friend's blog
source: www.wbupdates.com

Digital said...

Great explanation of using do and die() for managing directories! Your examples clearly illustrate how these commands can control the flow of execution when working with directory operations. The emphasis on error handling is particularly useful, as it helps prevent unexpected behavior in scripts. It might be helpful to see some real-world scenarios where these practices can prevent data loss or corruption during batch processing of directories. Thanks for sharing these insights—this is valuable for anyone looking to enhance their Bash scripting skills!

Digital Marketing Course In Hyderabad

Post a Comment