Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | No |
Requirements | find |
Time | N/A |
find /path/to/search criteria action
Here’s an example find command using a search criterion and the default print action:
find /nas01/backups/home/user/ -name file-Name-here
To match only directories, use:
find /nas01/backups/home/user/ -type d -name file-Name-here -print0
To match only hidden dot directories, enter:
find /nas01/backups/home/user/ -type d -name ".*" -print0
To descend at most one levels of directories below the command line arguments pass the -maxdepth 1 option. This will avoid deleting nested directories:
find /nas01/backups/home/user/ -maxdepth 1 -type d -name ".*" -print0
Once satisfied with the result, use the xargs command to delete all hidden directories:
find . -maxdepth 1 -type d -iname ".[^.]*" -print0 | xargs -I {} -0 rm -rvf "{}"
OR
find . -maxdepth 1 -type d -iname ".*" -print0 | xargs -I {} -0 rm -rvf "{}"
🐧 4 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Won’t this, without maxdepth also delete directories higher than the specified (.* matches “..”)?
Why not use -exec:
find . -maxdepth 1 -type d -iname “.[^.]*” -exec rm -rvf “{}” \;
why not use -delete:
find -maxdepth 1 -type d -name “.[^.]*” -deletewe have got crammed
ls -al