1
vote
1answer
30 views

Apply recursive chmod to files or folders only

I'd like to apply chmods to files and folders in one line, Basically: chmod 700 ./* -R # but only apply to folders chmod 600 ./* -R # but only apply to files Of course I searched google and read ...
1
vote
2answers
49 views

How to locate a file in a directory

How can I locate a file using locate in CentOS under a specific directory from terminal? Locate search the whole database!
3
votes
5answers
168 views

How to prepend a particular text file contents to every text file in a directory and its subdirectories?

I hate to clutter my source code files with licensing/attribution comments but some times it is a requirement. So having dozens of source code files (organized in a tree of subdirectories) written I ...
3
votes
2answers
1k views

Get list of subdirectories which contain a file matching a string

How can I get a list of the subdirectories which contain a file matching a particular string? More specifically, I am looking for directories which contain a file with the letter 'f' somewhere ...
-1
votes
4answers
102 views

Need a command sequence that will move files from one directory to another based on a particular year? [duplicate]

I'm looking for a sequence of commands (one liner would be ideal) which will identify all the files created in particular year, and move the resulting files to another directory.
0
votes
1answer
155 views

How to escape spaces while using command's output in command line [duplicate]

I want to perform the following command in command line : $ md5sum $(find . -type f) But this would cause problems when it encounter files with spaces in filenames : md5sum: Kaufmann: No such ...
3
votes
2answers
267 views

Create Zip for each subfolder but containing only matched files

I am trying to figure out how to create a zip file for each subfolder containing only files that match my criteria. For instance I have: Folder1 Folder2 Folder3 Each folder contains the same set ...
1
vote
2answers
322 views

Need to copy files to existing directory and remove files already there with the same name but different extension

EDIT: Total rewrite of question for clarity. I have a directory tree (new) with a bunch of files of with an extension of .new. I have an identical tree (old) where many of the files have names ...
7
votes
3answers
4k views

Sorting files according to size recursively

how to scan a folder recursively and find the largest files in the folder, and sort them by size. I have tried using ls -R -S but it tends to list the directories as well I need to scan the folders ...
0
votes
2answers
148 views

The difference that quotation marks make in find command [duplicate]

When I have a nested directory find . -name "*.py" -print command gives me all the python scripts beneath current directory. However, find . -name *.py -print returns only the python scrips in current ...
5
votes
3answers
179 views

find all end subdirectories in a tree

given the following structure: oz123@debian:~/ $ tree . . ├── a │ ├── a1 │ ├── a2 │ └── a3 ├── a1 │ ├── a11 │ ├── a12 │ └── a31 ├── b │ └── b1 │ ├── b11 │ │ └── b21 │ ...
3
votes
3answers
997 views

How to find first match in multiple files

Is there a way for the find command to search for the first match or occurrence of a string or pattern within each of multiple files? I've been using the usual syntax: find dir -iname '*.ext' -exec ...
0
votes
1answer
411 views

How does -exec actually work

I am confused on the -exec command. E.g. in this case: find . -type f -name "*.c" -exec cat {} \;>all_c_files.txt It seems that I get cat file1 file2 file3 ... fileN While in this case: ...
3
votes
4answers
7k views

Move all files with a certain extension from multiple subdirectories into one directory

Suppose I have a bunch of zip files in several directories: Fol1/Fol2 Fol3 Fol4/Fol5 And I want to move them all to a common base folder. How would I do this?
2
votes
3answers
551 views

Howto recursively create PDF thumnbails on linux command line

I am able to use ImageMagick to create a thumbnail of the first page of a PDF using: convert -thumbnail x80 95.pdf[0] thumb_95.png This works fine and generates a thumb_95.png file. I have tried ...
2
votes
1answer
392 views

Help me parse this `find` command

Following command tells me the length of mp4 video files: find -type f -name "*.mp4" -print0 | \ xargs -0 mplayer -vo dummy -ao dummy -identify 2>/dev/null | \ perl -nle ...
10
votes
5answers
983 views

How to find files with 100% NUL characters in their contents?

What is the Linux command-line command that can identify such files? AFAIK the find command (or grep) can only match a specific string inside the text file. But I want to match whole contents, i.e. ...
2
votes
2answers
420 views

Sort the output of find before piping to openssh

I'm using this command to recursively generate a SHA-512 hash for each file in a directory hierarchy: find . -type f -exec openssl sha512 {} \; I'd like to sort the files in lexicographical order ...
1
vote
1answer
129 views

questions on find and grep

With respect to the following find command-line find . -type f -exec grep -l strings {} \; I do not understand the usage of -exec and {} \.
1
vote
5answers
1k views

Checking if a file exists in several directories

I've been working on this far too long and need some help. I need a script that will look at files in a directory and see if it exists in one of several directories. I need something like this: for ...
2
votes
1answer
147 views

How to have find only search for files in changed directories?

Currently I'm repeatedly doing a 'find' that's too slow. I'm searching for non-hidden executable files within "$root", excluding "$root/bin": find "$root" -type f -perm -o+x -not -path "$root/bin/*" ...
2
votes
2answers
2k views

UNIX commands help - find

I'm trying to learn UNIX commands and I'm playing this game to learn and I'm really stuck at the moment. I'm in a server through ssh and the directory is full of random files and folders and the ...
1
vote
2answers
444 views

Search and delete .Trash

I have 4 large USB devices with lots of backups collected over the years. I want to search for all .Trash folders and delete the contents on Fedora 17. I tried the following which failed:- # ...
2
votes
5answers
3k views

Execute on the basename of a find command

Suppose I have a directory structure as follows test test/a test/b Now I want to execute a command, such that in the . folder I can execute a command on the basename of the files a and b. So ...
55
votes
6answers
17k views

How can I find broken symlinks

Is there a way to find all symbolic links that don't point anywere? find ./ -type l will give me all symbolic links, but makes no distinction between links that go somewhere and links that don't. ...
4
votes
2answers
1k views

How to search for files by size and extension ?

I want to delete all empty files with a particular extension from a directory and all its subdirectories.
1
vote
1answer
316 views

How to create a cron which finds/kills/clears old puppet runs?

I am a new user of bash/cron, and I was given a task to create a cron which finds/kill/ and clears old puppet runs that were not successfully installed. The more help the better, but I am more or less ...
3
votes
4answers
4k views

Show files from the last 2 days on a mounted ntfs system?

What's exactly the command to show files younger than 2 days? I thought about something like this: $ find / -mtime -2 ...but I'm not sure how to print the date of the found files. My target is to ...
3
votes
1answer
80 views

What is the best way to find directories that exactly match a string irrespective of the path?

Suppose I have the directories: /foo/ /A/B/C/foo/D/E/ /F/foo/G/H/foo/I/ How can get a result that lists all the directories whose basename exactly matches a given string (for example foo in here)? ...
7
votes
1answer
2k views

List of modified files of the past 24 hours

Is there a reliable way to have a system that mails me the list of files that were modified in the past 24 hours inside a set of directories? (like /home/*/public_html/* and /home/*/*domains/*)
6
votes
6answers
296 views

Searching in many files

Is there some sophisticated technique to search strings in many files? I tried this basic technique for i in `find .`; do grep searched_string "$i"; done; It doesn't look much sophisticated and ...
6
votes
4answers
4k views

How can I run a specific command for each find result?

How would one run a specific command for each file that was found by using the find command? For the purpose of the question lets say that I would simply like to delete each file found by find. I am ...
5
votes
2answers
5k views

Looking for a Java class in a set of JARs with find, unzip, grep

I was trying to find the JAR containing a Java Class. JARs are in zip format. My first attempt was: $ find -name "*3.0.6.RELEASE.jar" | xargs -l1 unzip -l \ | grep stereotype.Controller ...
1
vote
2answers
7k views

Finding files containing certain strings under a directory [duplicate]

Possible Duplicate: How do I find text within a file and have it search multiple subfolders? I would like to find out all the files under mydir/ directory whose content contains the string ...
4
votes
2answers
5k views

How to list ALL directories according to their size? [without including the parent directory]

I have a bunch of random folders, some of them are hidden (beginning with a period). I want to list all of them, sorted by their sizes. I have something on the lines of this in mind: ls -d -1 -a */ ...
7
votes
4answers
545 views

How can I find a file whose name includes a given string, such as “abcde”?

Within a set of directories, how do I find a file whose name includes a given string, such as "abcde"?
2
votes
3answers
123 views

How to find every file that includes a given function?

I am trying to list all of the files that include a function, e.g., matrixCal. How can I to do this in linux?
0
votes
0answers
107 views

How to use find command with wildcard when current directory contains a match? [duplicate]

Possible Duplicate: find not recursive when file at top I'm having some confusion with the find command. If I type: find . -name *.xml or find ./ -name *.xml I receive a list of all ...
10
votes
5answers
3k views

Alternative to find?

Is there an alternative find program with a more conventional CLI interface? find works and expects parameters in a painfully different way from most other utils. Clarification: I'm looking for a ...
6
votes
3answers
13k views

Getting all files that have been modified on a specific date

Is it possible to find all php files within a certain directory that have been modified on a certain date I'm using find /var/www/html/dir/ -mtime -28 | grep '\.php' to get files modified within ...
5
votes
1answer
2k views

How to find files not of a certain type?

I'm trying to find out all of the different types of files in my unorganized music folder. I've been trying this command (to list files of types besides the ones I know are in there): find ...
6
votes
3answers
762 views

Deleting lots of files

I accidentally created 8 million files and every time I'm trying to delete them the server almost dies because of the rm process eating all disk IO (the server is remote without console). Should ...
5
votes
4answers
989 views

recursively chmod

I was trying to chmod folders and files with: find . -type d -exec chmod 755 {} \; find . -type f -exec chmod 644 {} \; But I was wondering: How to do it in one line using find and excluding the ...
8
votes
3answers
8k views

How can I move files by type recursively from a directory and its sub-directories to another directory?

What would be a good way to move a file type from a directory and all of its sub-directories? Like "move all *.ogg in /thisdir recursively to /somedir". I tried a couple of things; my best effort was ...
8
votes
6answers
749 views

Best way run a command on each file in a directory tree

There appear be a number of ways to do this including loops in shell script, find and xargs. Which of these is best, and which is most portable?