Saturday, September 16, 2006

Find, Copy or Delete Hidden Files in a Directory

I'm often asked where are the hidden files located on a system. My response to a user: Mostly in your home directory. Most are probing for their .profile or .cshrc file. I tell them to use the ls command coupled with the "-a" option. The "-a" shows the hidden files.

# cd /home/esofthub
# ls -la

Bonus: Copy hidden files or directories to a directory or delete hidden files and directories from a directory (per reader's request).

# cp -p .hiddenfile my_destination_directory
# cp -p .login my_destination_directory
# cp -pr .hiddendirectory my_destination_directory
# cp -pr .* my_destination_directory (copies all hidden files and hidden directories recursively)

To delete a hidden file or directory, make sure you know where you are at before performing the activities below.

# pwd
# rm .hiddenfile
# rm -r .hiddendirectory

To delete hidden files and directories as a wildcard (deletes all hidden files in the current directory and directories recursively)
# rm -r .*

Even though I was referring to $HOME, this reader makes a good point...watch where you are at on the system - pwd

Petr Smid said...

Be CARFEUL!!! If you do rm -rf .* you will delete the entire disk (because .* applies to .. as well)

1 comment:

Petr Smid said...

Be CARFEUL!!! If you do rm -rf .* you will delete the entire disk (because .* applies to .. as well)