
- Kali Linux Tutorial
- Kali Linux - Home
- Installation & Configuration
- Information Gathering Tools
- Vulnerability Analyses Tools
- Kali Linux - Wireless Attacks
- Website Penetration Testing
- Kali Linux - Exploitation Tools
- Kali Linux - Forensics Tools
- Kali Linux - Social Engineering
- Kali Linux - Stressing Tools
- Kali Linux - Sniffing & Spoofing
- Kali Linux - Password Cracking Tools
- Kali Linux - Maintaining Access
- Kali Linux - Reverse Engineering
- Kali Linux - Reporting Tools
- Kali Linux Useful Resources
- Kali Linux - Quick Guide
- Kali Linux - Useful Resources
- Kali Linux - Discussion
Skip Hidden Files and Directories During Recursive Copy
Abstract
On the Linux command line, cp -r can be the first command that appears when we want to copy directories recursively. Dotfiles are understood to function under Linux as hidden files. We occasionally exclude hidden files and directories from directories while copying them recursively.
We'll learn how to do it in this tutorial.
Note − Linux commands are case-sensitive.
SCP command
Using the command-line tool SCP (secure copy), you can safely move files and directories between two places. We can copy a file or directory with scp from a local system to a remote system, from a remote system to a local one, and between two remote systems and your local system.
Run the following command to copy a file from a local system to a remote one −
$ scp script.txt remote_username@10.9.0.8:/remote/directory
Output
tutorials@10.9.0.8's password: script.txt 100% 0 0.0KB/s 00:00
Here the name of the file we want to copy is “script.txt”, the user on the remote server is tutorials, and the server's IP address is 10.9.0.8. The path to the directory you wish to copy the file to is in the /remote/directory field. The file will be copied to the remote user's home directory if a remote directory is not specified.
rsync command
A helpful Linux command-line utility that copies and syncs files and directories is called rsync. The utility can be used to synchronize data between two remote machines or locally between directories and discs.
In Linux, the fundamental rsync commands sync everything from the location you specify. You might want to exclude particular files, folders, or file types in numerous backup scenarios.
We can instruct the -exclude option to ignore hidden files and directories by passing it the ".*" pattern. We should point out that the ".*" pattern in this case is not a regex. Instead, it denotes any directory or filename that starts with a dot.
In the below example, we will copy all file recursively from ~/sample/ directory but exclude all *.backup files −
$ rsync -av -e ssh --exclude='*.backup' ~/sample/ root@fedora:/tmp
Output
sending incremental file list images/ images/fedora/user-data images/fedora/meta-data images/fedora/ sent 1,145,974,357 bytes received 137 bytes 45,904,896.00 bytes/sec total size is 1,145,674,357 speedup is 1.00
As you can see the output above, all the files have been recursively copied and doesn’t contains “.backup” files.
Conclusion
In this tutorial, we learned some examples of how to skip hidden files and directories during recursive copy in Linux. We discussed how to replicate directories recursively in this article while omitting hidden files and directories.
The method of copying everything and then removing hidden items is simple. It might, however, result in security holes and performance issues. Any Linux user can quickly repair this problem. Feel free to attempt any method offered by Linux to solve this issue in order to eliminate this error. The procedures outlined above work with various Linux distributions. All operating systems must have file descriptors as a fundamental element.
I hope you find these examples of the commands useful.
- Related Articles
- How to list non-hidden files and directories in windows using Python?
- How to copy readonly and hidden files/folders in the PowerShell?
- Generate temporary files and directories using Python
- Listing out directories and files using C#
- Listing out directories and files in Python?
- Delete empty files and directories in Linux
- Function to copy string (Iterative and Recursive)
- How to Remove All Directories and Files in Golang?
- How to Copy and Paste Skip Blank Cells in Excel?
- How to Protect Files and Directories from Deleting in Linux
- An Easy Way to Hide Files and Directories in Linux
- How to remove hidden files and folders using Python?
- How to get hidden files and folders using PowerShell?
- How to delete hidden files and folders using PowerShell?
- Recursive Search and Replace in Text Files in Linux
