Facebook

Linux : How to copy/remove all files from a tree of directories.



Sometimes we face a situation when there are a huge or rather say a deep tree of directories. All these directories in turn contains directories and files and at the leaf node i.e. in the innermost directory there are some files.
Now you want to copy all files at one place or say you want to perform some action on all these or some selected files.


Going to each and every directory one by one and then copying files to another folder is very cumbersome. So here Linux provide you a very useful command
'find' , which will fetch you all the files or directories based on the criteria you supplied and perform the desired action.

1. To list all files in current directory and subdirectories

$ type . -type f

2. To list all directory and subdirectories

$ type . -type d

The dot(.) denotes the current directory. If you want to list all special files under the root directory then use






3. this will list all the image files with extension JPG anywhere inside / partition.

$ type / -name "*.JPG"







For more details see man page of find command or visit this link

4. Starting with the root directory, look for the file called fname 


$ find / -name fname
5. Starting with the root directory, look for the file containing the string fname

$ find / - name ”*fname*”

6. Find a file called missingfilename using the locate command - this assumes you have already used the command updatedb (see next)
$ locate missingfilename
7. Create or update the database of files on all file systems attached to the linux root directory
$  updatedb




Happy Learning :)

https://www.facebook.com/Newbie.StayHungry

No comments:

Post a Comment