Score:-4

Write a command that finds all empty files and directories in the current directory and all sub-directories

ls flag
Joy

Write a command that finds all empty files and directories in the current directory and all sub-directories.

Only the names of the files and directories should be displayed (not the entire path) Hidden files should be listed One file name per line The listing should end with a new line You are not allowed to use basename, grep, egrep, fgrep or rgrep

Raffa avatar
jp flag
Please, have some respect for the community and don't copy/paste a homework assignment ... At least put some effort in rewriting it.
Score:1
br flag

List regular empty files withouth path (2 possibilities):

find /mypath/mydir -size 0 -type f | awk -F "/" '{ print $NF }'

find /mypath/mydir -empty  -type f | awk -F "/" '{ print $NF }'

Use sudo, if some files or subfolders are not accessible for present user.

sudo find /mypath/mydir -size 0 -type f | awk -F "/" '{ print $NF }'

List empty folders withouth path:

sudo find /mypath/mydir -empty -type d | awk -F "/" '{ print $NF }'

Edit

Using Raffa's suggestion:

Files

find /mypath/mydir -size 0 -type f -printf '%f\n' 

Directories:

find /mypath/mydir -empty -type d -printf '%f\n'
Raffa avatar
jp flag
Instead of piping to AWK, you can use `find`'s own action `-printf '%f\n'`
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.