Listing hidden files is one of the common thing to do as sys admin. Doing manipulations with hidden files like copy / delete / move is very rare but still sometimes necessary here is how to do all this.
1. Find and show (only) all hidden files in current directory
find . -iname '.*' -maxdepth 1
maxdepth – makes files show only in 1 directory depth (only in current directory), for instance to list files in 2 subdirectories use -maxdepth 3 etc.
echo .*;
Yeah if you're Linux newbie it is useful to know echo command can be used instead of ls.
echo *
command is very useful on systems with missing ls (for example if you mistakenly deleted it 🙂 )
2. Find and show (only) all hidden directories, sub-directories in current directory
To list all directories use cmd:
find /path/to/destination/ -iname ".*" -maxdepth 1 -type d
3. Log found hidden files / directories
find . -iname ".*" -maxdept 1 -type f | tee -a hidden_files.log
find . -iname ".*" -maxdepth 1 type d | tee -a hidden_directories.log
4. Delete all hidden files in current directory
cd /somedirectory
find . -iname ".*" -maxdepth 1 -type f -delete
5. Delete all hidden files in current directory
cd /somedirectory
find . -iname ".*" -maxdepth 1 -type d -delete
6. Copy all hidden files from current directory to other "backup" dir
find . -iname ".*" -maxdepth 1 -type f -exec cp -rpf '{}' directory-to-copy-to/ ;
7. Copy and move all hidden sub-directories from current directory to other "backup" dir
find . -iname ".*" -maxdepth 1 -type d -exec cp -rpf '{}' directory-to-copy-to/ ;
– Moving all hidden sub-directories from current directory to backup dir
find . -iname ".*" -maxdepth 1 -type d -exec mv '{}' directory-to-copy-to/ ;
More helpful Articles
Tags: command, copy, Delete, dir, directory, echo, echo command, example, exec, hidden, iname, Linux, list, maxdepth, move, show, sub, sys admin, type, use