General :: Recursively Count All The Files In A Directory?

Oct 12, 2010

I have a really deep directory tree on my Linux box. I would like to count all of the files in that path, including all of the subdirectories.

For instance, given this directory tree:

/home/blue
/home/red
/home/dir/green
/home/dir/yellow
/home/otherDir/

If I pass in /home, I would like for it to return 4 files. Or, bonus points if it returns 4 files, 2 directories. Basically, I want the equivalent of right-clicking a folder on Windows and selecting properties and seeing how many files/folders are contained in that folder.

How can I most easily do this? I have a solution involving a Python script I wrote, but why isn't this as easy as running ls | wc or similar?

View 5 Replies


ADVERTISEMENT

General :: Recursively Add Read Privilege To All The Files Under A Certain Directory?

Jan 18, 2010

I'm under linux . by default, other user can't read anything under my home directory. let's see my home directory is /home/superman , and I tried to use

chmod +r /home/superman

to let others can acess files under my home directory , but it does not work .

View 1 Replies View Related

General :: Count The Number Of Lines In All Files In This Directory?

Jul 5, 2011

I want to count the lines of all files in this directory and all its subdirectories, but exclude directories "public", "modules", and "templates".

View 2 Replies View Related

General :: Recursively Remove Subdirectories And Files But Not The First Parent Directory?

Feb 11, 2010

I'm able to use the following to remove the target directory and recursively all of its subdirectories and contents. find '/target/directory/' -type d -name '*' -print0 | xargs -0 rm -rf

However, I do not want the target directory to be removed. How can I remove just the files in the target, the subdirectories, and their contents?

View 4 Replies View Related

General :: Overwriting Specific Files In Directory Tree Recursively

Jul 19, 2011

I would like to overwrite files in a directory tree, recursively. The ones I would like to overwrite match the filename "x_alpha*.png" and have a size exactly 456 bytes. Is there any way to search for these recursively in a directory tree, and overwrite them with a reference file, for example "e:mydirgood.png"

I am using Windows 7, but I have UnxUtils, so I can use those too. What I am looking for is something like this, generated automatically:
copy /y e:mydirgood.png e:mydiracx_alpha0023.png
copy /y e:mydirgood.png e:mydirefgx_alpha0045.png
copy /y e:mydirgood.png e:mydirhx_alpha0248.png

View 2 Replies View Related

General :: Rsync Files Recursively But Place In One Remote Directory?

Jan 29, 2011

i would like to find and backup all *.mp4 files from /Pictures and its sub-directories and move them to a single directory on a remote. I can find and move the files but I don't want the directory structure...just the files to be placed in the remote directory.

To find my files I use

rsync -r -a -v -e "ssh -l user" --delete --include '*/' --include '*.mp4' --exclude '*' /home/drew/Pictures/ remoteserver:/Users/drew/mp4

but this creates all the subdirectories

I also tried

find ~/Pictures -name "*.mp4" -exec rsync -r -a -v -e "ssh -l user" --delete {} remote:/Users/drew/mp4 ;

This works but takes forever

View 3 Replies View Related

Red Hat / Fedora :: Extracting Files In Sub Directory Recursively

Feb 27, 2010

I am new in Linux and I need to extract alot of zipped files (different format (e.g tar.gz, tar.gz2)) which are in subdirs and I do not want to go to each subdir and extract each file because it will take alot of time. Is there away to extract all files that are existing in dirs and subdir with "for loop" or is there a script that can do the job automatically.

View 1 Replies View Related

Programming ::Word Count For All Files In A Directory?

Apr 7, 2011

Word Count for all files in a directory

View 1 Replies View Related

Fedora :: Configure Grep To Search Recursively Through All Files In A Directory?

Oct 1, 2010

somewhere lurking is a file containing the default print resolution, which is not being overwritten by printer settings or cups management. I've asked on the cup forum and nothing successful.

So here's the question:

How can I configure grep to search recursively through all files in a directory, or if need be starting from root to find the pattern "2880" I've looked in the man page for grep and I can't see how to do it, is grep the right tool to use for this ?

View 2 Replies View Related

Programming :: Sort Oldest 5 Files In A Directory Tree Recursively Based On Timestamp?

Jun 3, 2010

I have a directory listing with many subdirectories having many files. I want to recursively search for the oldest 5 files starting from the base directory and not 5 from each subdirectory. I am writing a shell script which sorts them using ls -lRtur|egrep "txt|jpg" > /tmp/file1 Now from this /tmp/file1 file I want to sort the files same as what the ls -ltr command does that is oldest file time to newest file time first. How do I sort based on Linux time stamp? The files itself also have Linux timestamps embedded in them So I can sort based after extracting them as well if it is easier.
My /tmp/file1 has entries like below.

-rw-rw-r--. 1 usr1 usr1 705 2010-01-22 17:25 sample20100603173659.jpg

I want to get the 5 oldest files and then delete them.

View 1 Replies View Related

General :: How To Recursively Copy Directory Into Another One

Apr 25, 2011

I moved to Mac OS X recently and bumped into the "feature" of Mac where copying files from an external drive resets the file modification/update date/timestamp to the current date (which Windows does not), causing a disaster for my 10+ years of backup work files where date is important. So, before I learned how to avoid that (e.g. using the -p "preserve" flag in the "cp" copy command) I have in the meantime added to my new Mac hard drive many more files as well as updating existing old files.

I have a backup external hard drive with all my old data and proper modification dates. I have a Mac hard drive with reset modification file dates (a single or two particular days). The Mac hard drive has all the "true" and "current" file contents with files modified and added. I need to Copy all the original files from the external harddrive, preserving file metadata (really only modified date), but ONLY overriding the new internal Mac hard drive IF

The file contents (md5 or whatever) is the same or The file was updated after the day (which of course I can see on all files) on which the original disasterous cope was performed (implying the file is new or modified) Ensure the copy leaves all the new and modified files completely intact on the Mac internal hard drive. "No prompting/stopping of the copy of any kind (i.e., not verbose) is required but is o.k". "Recursive copy - obviously I would like to copy all* files folders and subfolders found in export".

View 1 Replies View Related

General :: Recursively Download An Entire Web Directory?

Feb 3, 2010

i have a web directory that has many folders and many sub folders containing files.

i need to download everything using wget or bash.

View 7 Replies View Related

General :: Copy Permissions From One Directory Recursively To Another?

May 23, 2011

I have a system where the permissions of many files are messed up. I have another system that has the same files, if I put that hard drive in, without simply overwriting the files, is there a way where I can recursively set the permissions of each file to that of this other directory?

View 1 Replies View Related

General :: Get The Last Change Time Of Directory Recursively

May 28, 2011

How can I get the last time any of the files in a directory or its subdirectories has changed?
e.g

Dir - changed 1/1/1
Sub Dir 1 - changed 2/1/1
Sub Dir 2 - changed 3/1/1
File 1 - changed 10/1/1
File 2 - change 5/1/1


The output for this for Dir should be 10/1/1 (File 1 was the last modified one). Getting the last file name to be modified is a bonus but isn't necessary.

View 3 Replies View Related

General :: Search LDAP Directory Recursively?

Oct 12, 2010

How would the command for recursive search in LDAP look like when I'm searching for "cn" or "ou"?

View 3 Replies View Related

General :: Zip -x For A Directory - Subfolder Contents Not Being Excluded Recursively?

Dec 9, 2010

I am attempting to use the zip command with the '-x' option to exclude a folder e.g. 'zip upload.zip public_html -x public_html/jquery/*'. However, parts of this folder are still being added to the archive. I made a shell script (saved as 'compress.sh' and ran as '. compress.sh') to do the archiving so I could test adding nested wildards for multiple subfolder levels.

Code:

#!/bin/bash
rm -f upload.zip
zip -r upload.zip public_html
-x public_html/jquery

[code]....

Each new line I added here that has the nested wildcards made the archive file size a bit smaller. Adding more /*'s than this didn't affect the file size. Even after all this though, there were still a couple megabytes of files and folders from the 'jquery' directory that were added to the archive.

Here's some examples of files and folders that were created after I unzipped the archive:
public_html/jquery/js/tablesorter/addons/pager/icons [folder]
public_html/jquery/js/tablesorter/addons/pager/.svn/entries [file]
public_html/jquery/js/tablesorter/build/.svn/text-base/js.jar.svn-base [file]

Why is it that despite all the -x lines, the files and folders like these were still being added to the archive? How can I simply recursively exclude the entire public_html/jquery folder from the archive?

View 4 Replies View Related

General :: Copying Jpegs Recursively While Preserving The Directory Structure?

Aug 9, 2010

So I have a bunch of directories:

dir1
dir2
dir3
etc.

which themselves all contain subdirectories:

dir1subdir1subdir2etc.and at the lowest level they contain all of these jpegs that I need. The problem is that I only need some of them. They're named like this:

pic1.jpg
pic1_med.jpg
pic1_small.jpg
pic2.jpg
pic2_med.jpg
etc.

I want to just grab the ones without the size suffix and copy them all to another set of folders, while preserving the directory structure. The numbering all starts at 1 for each low level subdirectory, so I think that the directory structure is the only way to not get them mixed up.

I know that cp has a recursive option -r but how do I just extract the ones without the underscore? And then how do I preserve the directory structure when I move them over?

View 1 Replies View Related

General :: Trying To Display Count Of Number Of Subdirectories In Directory

Feb 7, 2011

I am a noob and I am trying to display a count of the number of subdirectories in a directory. I have been able to use find -type d to list directories and subdirs but I want a numerical value of dirs and subdirs. I know ls -l gives a count but when I try ls -l -d all it shows is "." I also have tried a combination with the -R option but nothing seems to be working for me.Please forgive my ignorance but I am working on a script for class and this is the first step.

View 3 Replies View Related

General :: Recursively Cp All Directories, Files And Hidden Files?

May 17, 2010

Ubuntu 10.04

I want to copy all directories, files, and hidden files and hidden directories with one command. I want these items to replace any same items in the target directory.

I have tried several things, such as:

cp -r *
cp -aR *

but I only seem to get visible files and directories. Obviously, I am missing something. (A brain, probably....)

View 9 Replies View Related

General :: Copy File Recursively Ignoring Destination Directory Structure?

Jul 8, 2011

I have the following content on the source directory:

source/foo.txt
source/bar/another_file.txt
source/bar2/and_another.txt

I want copy those files to a destination directory which, after copy, shall look like this:

destination/foo.txt
destination/another_file.txt
destination/and_another.txt

How can I do this? It seems that "cp" lacks such an option

View 1 Replies View Related

General :: Count Files In Dir Then Move That Many Files In A Script?

Dec 17, 2009

what I got - from a crontab run a script (understand that part), this script needs to count the amount of files in /outgoing/, then take 30 less that number, and move that many files from /readycalls/. I need to keep the asterisk outgoing que full of .call files with out having to many in there at any given time.

View 3 Replies View Related

Ubuntu :: Recursively Copy From Directory To Another Directory

Mar 23, 2010

I'm facing a little trouble with copying a .txt file(only) from a directory and subdirectory to another directory. -R command don't work I think if I want to do this, since I don't want to copy subdirectory.

View 6 Replies View Related

General :: Removing Files Or Directories Recursively

Jan 29, 2010

The rm command man pages discusses removing files or directories recursively. So what is meant by deleting a file or directory recursively? And what are some reasons for doing so?

View 3 Replies View Related

General :: List Contents Of All Files Recursively?

Jan 22, 2011

What I would like to do is to print the contents of all text files in a particular directory, recursively. Problem being that there are directories and possibly binaries scattered around in the filesystem as well.

Trying cat * works as long as there are no directories in there, but when there are it gives an error instead and prints nothing.

I'm sure it's easy using file -f or something but I can't figure it!

View 8 Replies View Related

General :: Script To Rename Files Recursively?

May 8, 2011

I'm planning to writing a script to rename files recursively.

To be said that I'm using /bin/sh (not /bin/bash) as this is the only shell available on the busybox of the linux router (tomato) I'm using.

Basically I would like to rename files with extension .jpg using as a suffix the filename of another file in the very same directory with extension .avi

The reason for this is because pretty much all the DLNA devices like modern TV playing .avi files will display a thumbnail of the video when browsing the filesystem, however to do so they'll need .jpg image wit hthe same filename of the video in the very same directory.

View 3 Replies View Related

General :: How To Recursively Find Files Over Certain Size

Apr 15, 2010

I made an account under freeshell.org and it has been very satisfactory so far. I recommend everyone getting an account under freeshell.org. But anyways, how do I find files over, for example, 500 KB, in the entire, my shell account?

View 1 Replies View Related

General :: Recursively Searching PHP Or HTML Files

May 5, 2010

I'm a frequent user of grep. I know that I can recursively search a directory using the -r flag:
Code:
// will recursively search all files
grep -r 'some string' *

However, if I want to limit my search to PHP files, the -r flag is suddenly useless:
Code:
// for some reason, this only searches the PHP files in the current dir
grep -r 'some string' *.php

Any good way to recursively search a directory and its subdirs for a string but ONLY look at PHP or HTML files (and possibly TXT files too) ? I'm really hoping for a nice, short command that doesn't involve using an exclude file and which isn't really painful to type. I do this kind of search very frequently and have resorted to either searching EVERY file which is really slow (TAR and ZIP files really slow it down) OR typing repeated commands to search *.php, */*.php, etc.

View 6 Replies View Related

General :: List Recursively All Files With Timestampsand Fullpath?

Jan 3, 2011

I want to list recursively all files in given direcotry, with their fullpath and their timestamps.Something like this:10:30 Dec 10 2010 /tmp/mydir/myfileI've tryied with:find . -type f -exec ls -la {} ;but that don't give me the fullpath.

View 3 Replies View Related

General :: How Do I Recursively Delete Duplicate Files Using Terminal

Mar 1, 2011

I'm using a mac, and just transferred a bunch o photos from another computer, and as it turns out, there is a bunch of duplicates.I'm not too familiar with the mac terminal, but if there is a solution for linux, it will probably work for the mac.Just need to be able to recursively scan all folders in my Pictures folder and then Delete them.

View 1 Replies View Related

General :: Command Line - Compressing All .pdf Files Recursively (.tar)?

Jun 20, 2011

At the linux command line, I'd like to compress all .pdf files in a directory, any of it's subdirectories and so on - but only .pdf files. I'm struggling to figure out the syntax

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved