General :: Recursively Browse Subfolders In A For Loop?
Feb 19, 2010I wrote a script for copying mp3 files to my girlfriend's mp3-player and it looks like this:
Code:
mount /dev/sdc /test -o sync
for i in *.mp3; do
[code]...
I wrote a script for copying mp3 files to my girlfriend's mp3-player and it looks like this:
Code:
mount /dev/sdc /test -o sync
for i in *.mp3; do
[code]...
lets say I have a project that have generated lots of xml files. Though all these xml files point to a location with the text name TEXT15. I want to change all the files that containts TEXT15 and change it to TEXT16. This actually works for files in a folder but not recursively in all the entire files....perl -pi -c 's/TEXT15/TEXT16/g' ./* but I have many subfolders and within this more subsub folders....i just want to do this recursively.
View 2 Replies View RelatedLet's say I have 4 subfolders in the folder test as shown below:
drwxr-xr-x 2 muskedear muskedear 4096 2010-04-03 17:11 sub001_p1
drwxr-xr-x 2 muskedear muskedear 4096 2010-04-03 15:38 sub002_p1
drwxr-xr-x 2 muskedear muskedear 4096 2010-04-03 15:38 sub001_p2
drwxr-xr-x 2 muskedear muskedear 4096 2010-04-03 15:38 sub002_p2
I want to loop through the folders and check if they end with *_p1 or *p2. If a given folder ends with *p1, I want to cd to that folder and manipulate certain files in that folder. If the folder ends with *p2, I want to perform different manipulations on certain files.
I have a mytext file with month and year as two separate fields. likemytext fil
08 2010
09 2010
10 2010
........
........
........
I want to read the values of each field i.e., month and year into an awk script.
How to go through all the subfolders and rename all the folders named 'Old' to 'New'
View 2 Replies View RelatedHow to get a list of all the subfolders with a specific name
e.g. all the folders which their name contains 'NAME' code...
but this won't give me a unique list (if the folder has subfolders it gets listed multiple times)
Let's say I want to get the size of each folder of a linux file system. When I use ls -la I don't really get the summarized size of the folders.If I use df I get the size of each mounted file system but that also doesn't help me. And with du I get the size of each subfolder and the summary of the whole file system.But I want to have only the summarized size of each folder within the ROOT folder of the file system. Is there any command to achiev that?
View 4 Replies View RelatedI have scripts in folders /opt/apache2/tools/ and also i have another folder called IDM under /opt/apache2/tools. i tried to configure htpasswd for just IDM folder only as below.
bash-3.00# pwd
/opt/apache2/tools
bash-3.00# ls -al
[code]...
Is there a way to allow other members of my group to access subfolders under my home directory, but not my home directory itself?I'm using CentOS 5.4
View 3 Replies View RelatedI want to get the size of each folder of a linux file system. When I use ls -la I don't really get the summarized size of the folders. If I use df I get the size of each mounted file system but that also doesn't help me. And with du I get the size of each subfolder and the summary of the whole file system. But I want to have only the summarized size of each folder within the ROOT folder of the file system. Is there any command to achieve that?
View 3 Replies View RelatedI want to rename files in multiple subfolders with a prefix (e.g., rename "file.tif" with "prefix_file.tif") and not have to be in the subfolder.
code: for f in /path/to/*; do echo mv "$f" "PRE_$f"; done
gives you this: mv /path/to/file1 PRE_/path/to/file1
instead I want this: mv /path/to/file1 /path/to/PRE_file1
I'd like to copy a file, say widgets/water.txt, to all subfolders in the folder widgets using a single command. So if the folder widgets has 10 subfolders like widgets/blue, widgets/green, etc. I'd like to copy water.txt to all of them with one command.
I tried the commands
Code:
cp water.txt ./*/water.txt
cp water.txt ./*/
However these don't seem to work. The latter gives 'cp: omitting directory' errors.
I am using secure delete to remove files from a Debian Linux PC. However, secure delete does not remove folders. This has lead me to look at writing a script that would move files to a predetermined folder for deletion. My plan is as follows:I have a folder on my desktop called shredder where I move the contents of the waste bin to. The script needs to identify all files within the folders and sub folders, within the shredder folder, and move each file to the shredder folder and then delete the folder. At this point secure delete can be used with a command like shred -v -u *.*on the shredder folder.The problem I have is in creating the code to move files from the different folders and then deleting the folders. Note that the names of the files, folders and subfolders will not always be known
View 12 Replies View RelatedI have a very large and deep directory. I would like to make all of it read only. The problem is I guess I have to distinguish between files (which will get a=r) and directories (which will get a=rx).How can I do that?
View 3 Replies View RelatedI 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".
i have a web directory that has many folders and many sub folders containing files.
i need to download everything using wget or bash.
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?
I have a Linux machine that shares some files through NFS. The shared directory is:
/foo
I then mounted a shared directory (from a Windows machine) to:
/foo/bar
/foo/bar is mounted successfully onto the Linux machine and everything is there. However any other machine that mounts /foo from the Linux machine everything is correctly there except /foo/bar is empty. Is there anyway to do a "recursive mount" of file shares. Here is the /etc/fstab entry for the Windows share mount of /foo/bar //windows_machine/share /foo/bar cifs username=user,password=pass 0 0 And the /etc/fstab entry on the client machines that mount /foo server:/foo /foo nfs rw 0 0
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 RelatedHow 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.
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 RelatedWhat 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!
How would the command for recursive search in LDAP look like when I'm searching for "cn" or "ou"?
View 3 Replies View RelatedI'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.
Is it possible to change only directories access permissions recursively with some linux command. I need to set x (access) permissions on directories but not execute on files. [URL]
chmod - change file access permissions
-R, --recursive
change files and directories recursively
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 RelatedI'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.
I have a folder that contains my group's website. The ownership of the entire directory is set to "www-data.website" (website being a group). I want to set the sticky bit on this directory such that if anyone creates a new file, either in the main directory or subdirectories, the ownership remains like above.
Q1: I have the sticky bit set on the main directory (drwxrwsr-x). But for some reason, some of the subdirectories don't have the sticky bit set. Is there a command I can use to change the sticky bit on Directories Only (i.e., not on the files)?
Q2: Is there a sticky bit that I can set for the ownership (not group) so that it is always set to www-data?
I promise I am carefully studying shell use, and much else, but right now I just need the shell instruction to search directories recursively, for files with .swo & .swp extensions, deleting the files as they're found.
View 7 Replies View RelatedI have a web app that has a bunch of symbolic links in subdirectories throughout it.I need to move the app to another directory structure, and I need to update all the symlinks to point to the new path.The problem is that there's a lot of these scattered throughout various directories.How can I recursively search from the root and recreate all symlinks pointing to /dev/ with /qa/?
View 3 Replies View Related