General :: Delete Matching Files In All Subdirectories?
Feb 22, 2010How can I remove all .swp files in all of my subdirectories under Linux?
View 4 RepliesHow can I remove all .swp files in all of my subdirectories under Linux?
View 4 RepliesThis question is very similar to this one except that I want to maintain the file's original subdirectories.
For example if I had
/temp/a/a.txt
/temp/a/a.jpg
/temp/a/b.txt
/temp/b/c.txt
/temp/d/d.txt
/temp/d/d.jpg
/temp/d/e.txt
/temp/f.txt
[Code]...
How can I use grep -Ev "pattern" not only to delete the matching "pattern" but to edit and save the file permanently as well
View 2 Replies View RelatedI know I can do find . -type f, but that includes binary file and I couldn't find a way to exclude them with find
View 4 Replies View RelatedI'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?
I have a question about sed programming, actually a one-liner for which I cannot find a solution, right now. I need to delete a line matching a specific pattern only if it is the last line. In practice, I would put together the following:
Code:
#
# This deletes the last line of a file
[code]...
I have a requirement to list files using find command My folder contains below list of files with out extention.I have a requirement to exclude only ABC.123.* type files and list others. Even though files having MNO contains this pattern i should not exclude. Even if file ends with .txt or .doc it should not be excluded. That is ABC.123.1234.txt should not be excluded.But I am not getting what is required. Can any one please let me know if I am doing wrong any where. As per my requirement I cannot use grep, -regex, or -regex attributes to find command.
View 7 Replies View RelatedIf I wanted to copy all *.so files from src to dst I'd do:
cp src/*.so dst
However, I want to copy all *.so files from src and it's subdirs into dst.
I'm trying to do something very basic in bash. It's a kind of cross-reference matching between 2 files. I have a file1.txt. It's like this:
Code:
item1
item3
item4
...
I Have a file2.txt. It's like this:
Code:
item1 "Properties of item1"
item2 "Properties of item2"
item3 "Properties of item3"
item4 "Properties of item4"
item5 "Properties of item5"
...
My goal is to print out the lines in file2 that contains lines present in file1. I do:
Code:
for i in $(cat file1.txt); do grep $i file2.txt; done but I get no output. Will someone please tell me where am I mistaking?
In a bash shell script, I want to do something like this:
Code:
if [[ $(ls -ld /some/dir/foo_* | wc -l) -gt 4 ]]; then
rm -rf first_match_of /some/dir/foo_*
[code]....
Quote:Originally Posted by topcatI would like to know how i can write a shell script to delete a line if a particular pattern exists?E.g. I have a text file with multiple lines. Say 1000s. in the following pattern.
username@email.com:149.0.3.4:1
username1@email.com:149.0.3.4:1
username1@email.net:149.0.3.4:1
username1@email.edu:149.0.3.4:1
If the patternusername@email.com exists then the line "username@email.com:149.0.3.4:1 should be deleted from the file.I have a very similar question but I need to delete one line in a file which matches one very precise instance of a string only. Let's assume I have a file composed of thousands of lines and let's call the file chap-secrets. Let's take the following sample entries:
Code:
#USERNAME SERVER PASSWORD IP
pp pptpd blahblah *
[code]....
I have a file with joker character patterns:
./include/*
./src/*
etc.
From the current directory I would like to recursively get the list of files that do not match these patterns.
I have 2 massive duplicate dirs of the same format as below:
dir1
subdir1
file1
subdir2
file1
subdir3
file1
...
Dir2 is the same, but it has some newer files of the same name. I want to copy all file1's from Dir2 to the same name and folders in dir1. So basically something like:
cp -pr bkpDir1/*/*-big.gif Dir2/*/*-big.gif
This works for singular cases:
cp -pr bkpDir1/uniquesubdir/*-big.gif Dir2/uniquesubdir/*-big.gif
But not for wildcards:
cp -pr bkpDir1/subdir*/*-big.gif Dir2/subdir*/*-big.gif
Anyway the aim is to do the first cp above, I have tried a few options using find. In trying to show an example stumbled upon a way that worked, while in dir2:
find */*-big.gif | xargs -i cp -rp {} ../dir1/{}
Sure there are better ways also...
I am writing a shell script that finds all files named <myFile> in a directory <dir> or any of its subdirectories, recursively. I also need to take care of symbolic links that may form cycles, to avoid infinite loops. I am not supposed to use find command for the same
I started writing the code but got stuck. I thought using recursion may be a smart way, but its not working.
Code:
#!/bin/sh
findFiles()
{
thisDIR=$1
#cd $thisDIR
code....
I need to copy all subdirectories and files from one directory to another ever 5 minutes or so, with the old data automatically being overwritten with the new data. I'd also like this to run at startup. Is there any way this can be done? If so, what program would I need to schedule the automation and what is the command line I would need.
View 2 Replies View RelatedI'm searching within Java files for some occurrence of a phrase:
find . -name '*.java' | xargs grep -l 'string'
How do I change this command to print to the shell all of the lines which contain a match?
What is the best and simplest way to compare two directory structures without actually comparing the data in files. This works fine:
diff -qr dir1 dir2
But it's really slow because it's comparing files too. Is there a switch for diff or another simple cli tool to do this?
I have many files in a folder for example
Kiran.txt
Kiran1.txt
Kiran221.txt
Kiran144.txt
Time.csv
[Code]...
From this directory, I want to know how I could use grep to display files based on part of their filename - for example those starting with "Account" or those ending in ".sh".
I am using the diff command with the -r option, to compare a large number of files and files in subdirectories. My main interest is to find out which files have been changed, and not what the actual changes are, and since a lot of files has been changed, it would be a lot easier to view the file names only. Is there and option for diff that might do this, or does there exist a similar tool/command that could do the job?
View 1 Replies View RelatedI am to rename all the files within a directory (which contains multiple subdirectories) recursively without invalid characters.
I tried the coding posted above.
find . -type f -printf '%p
' | while read file; do
oldfile=$(basename "$file")
newfile=$(echo "$oldfile" | sed 's/[^A-Za-z0-9_.]/_/g')
if [ ! "$newfile" == "$oldfile" ]; then
echo mv "$file" "${file%$oldfile}$newfile"
code....
but I get an error on both of them stating "find: bad option -printf find: [-H | -L] path-list predicate-list"
I need to search in "/" and all subdirectories, all files greather than 30 MB.
View 5 Replies View RelatedI have a large directory tree with my ebooks and some of these files are zipped. I would like to move all of the zip files to another one so I can manipulate them. Since they are all scattered inside the tree, I would like to do it quickly and painfully with CLI. How should I proceed?
[code]...
I am trying to dl the files located here: http://good.net/dl/bd/CCCamp-2007/video/m4v/ using wget.
Now when I use the command wget -r -A .m4v http://good.net/dl/bd/CCCamp-2007/video/m4v/
I get the just a bunch of filefolders, but no files, ex."cccamp07-de-1845-Freifunk_und_Recht.m4v" but its a folder.
I am trying to do a find/grep/wc command to find matching files, print the filename and then the word count of a specific pattern per file. Here is my best (non-working) attempt so far:
wc `find . ( -name "*.as" -o -name "*.mxml" ) -exec grep -H HeightResizableList {}` ;
i currently have hundreds of files all in a single directory. What I would like to do is create 8 subdirectories and move the files into the subdirectories based on the first character of the file name. Ideally, the script would omit any 'the' or 'a' and use the second word for filing purposes. No filenames have spaces. Instead they use periodsThe subdirectories will be:
0-9
a-d
e-h
[code]...
How can I search for a string (for example, a constant) in all the (.cpp) files in the current direcotire and subdiretories.
View 4 Replies View RelatedIf I am logged in as root in a linux system and I run command rm -rf on / folder, should it remove all the files? also the kernel?
View 4 Replies View RelatedTwo machines -- both 64-bit, both the latest Truecrypt installed, one Windows, one Linux. I created encrypted pendrive (using partition mode; not file-partition on regular partition) with FAT system on it. I copied several files/directories there -- using Windows. Then I unmounted it, mounted in Linux, but when I checked if everything is OK, it appeared that only the highest level of file hierarchy is visible -- i.e. only files and directories at mount point. Directories are seen as empty (in fact they are NOT empty). When I unmount pendrive and mount it again on Windows, all files/subdirectories are visible again. It is not an issue with older version of TC on Linux, because the version is the same. The question: how to make files in subdirectories visible on Linux?
[code]...
In reading the rsync man page and browsing a lot of websites, I ended up a bit confused, or maybe it was just too much eggnog. Anyway, to exclude a directory "videos" with everything in it, which is /home/user1/camera/videos and I'm rsyncing the whole user1 directory to an external drive
[code]...
I have two table files with x (1st column) ,y (2nd column) coordinates and intensity (3rd column). I need to match these two tables and divide the intensities at the consecutive coordinates on the 3rd column. The problem is the size of the tables are not same and I want to ignore the lines if they are not in one of the other file.
Here is Table 1:
Code:
-7.500-30.00013.006
-7.500-22.50037.952
-7.500-15.00060.962
-7.500-7.50040.922
-7.5000.00014.348
code....