1
vote
1answer
152 views

Basename gives extra operand error

I 'm using the following script to merge few pcap files into one using mergecap command. But when I run it it gives me a 'basename: extra operand /mnt/md0/capture/DCN/dcn_2014_02_04_00_11_47_598.pcap' ...
4
votes
2answers
58 views

Find files newer than another file within each subdirectory

I have a folder structure like this /Class/Student/Unit/files Each Unit folder contains a file MarkSheet* that I update when I mark a students work. I need a script that tests if the student has ...
0
votes
3answers
54 views

apply specific command for each git repository

I want compress all the git repositories on my computer (say in ~). I.e., for each directory {}, that contains directory or file (in case of submodules) named .git, I want to execute git gc ...
2
votes
3answers
82 views

The processing order and printing of files with find

This simple BASH script collects msgstrs in a PHP project: #!/bin/sh TARGET=/path/to/project LPATH=locale/cy_GB/LC_MESSAGES POFILE=messages.po mkdir -p $LPATH touch $TARGET/$LPATH/$POFILE cd $TARGET ...
3
votes
1answer
122 views

Find directories with a certain name

How can I loop through each directory recursively and whenever it finds a folder called VIDEO_TS, let Genisoimage convert that folder's content to an dvd-video iso image, the name of the iso would be ...
1
vote
1answer
94 views

Copying wallpaper images into a single folder

In my ubuntu 12.04 set-up, there are lots of wallpaper images in the directory /usr/share/wallpapers. For example, one might be usr/share/wallpapers/Leafs_Labyrinth/contents/images/1600x1200.jpg ...
1
vote
2answers
129 views

Count entries for each directory in tree

Say I have the following tree: root: d foo d bar /foo: d A - tmp.txt /bar: d B - tmp2.txt /foo/A: - tmp3.txt /bar/B: d = directory and - = file I need to answer the following question: which ...
2
votes
1answer
39 views

Linux shell - unexpected error

I'm new to the linux & command world. I have two directories, one called pasta (which contains 3 files) and another one called pasta2 (with nothing inside). I'm trying to move all 3 files from ...
1
vote
1answer
74 views

Find a particular nesting of directory names, e.g. …/project/dir1/dir2

I'm having some issues dealing with the find command; I don't know the syntax for it very well and I need to use it in a script to find a specific directory structure that could be located anywhere. ...
1
vote
2answers
122 views

mv complains about standard input in a pipeline that filters file name with grep

I'm trying to move several .avi files that have spaces in from a CD to my home folder. I've already know how to get rid of the spaces: find /media/mathscd/ | grep -L -r "*.avi" | for file in *; do ...
2
votes
5answers
146 views

Delete all files in directories except those whose path are listed in a file

Given the following files: data/A/a.txt data/B/b.pdf ... date/P/whatever.log ... data/Z/z.jpg I would like to delete all files in the data/A/, data/B/, ..., data/Z/ directories except those files ...
2
votes
2answers
198 views

Optimized way to list and delete files

I need to list and delete .php, .xml files. For this I am using find command. To list : find . -type f -name \*.php -print0 To delete : find . -type f -name \*.php -print0 | xargs -0 rm -r As I run ...
6
votes
2answers
358 views

How does this find command using “find … -exec sh -c '…' sh {} +” work?

@StephaneChazelas posted the following solution to this Q&A: Having some trouble using “find -exec {} +”. $ find . -iname "*.extension" -exec sh -c ' exec <command> "$@" <additional ...
4
votes
4answers
110 views

How to deal with spaces in a variable

I'm working on some scripting: for x in `find ./ -name *.pdf` do echo pathname $x done My filenames are Test1 ( Volume II), Test2 ( Volume II). I'm getting a return of pathname Test1 pathname ( ...
0
votes
3answers
239 views

using find, exec, sed to manipulate strings as args to another program

I can use find like this find -type f -path "./src*" -name "*.php" to find a list of files. For example ./src/Superuseradmin/Model/Mapper/UUID.php What I need to do is manipulate each string in the ...
1
vote
3answers
444 views

Setting file permissions in bash script

This script is not working the way I thought it would .I though it would find all the scripts that have every one rwx permissions changed to the permissions of xx5 #!/bin/bash # the / makes find ...
3
votes
2answers
196 views

How to run "find -exec <script> {}\;

I have a script that changes the properties of the files for a folder. Here is the example tree: dir 1 --file 1 --file 2 --file 3 dir 2 --file 1 --file 2 dir 3 --file 1 ...
3
votes
2answers
3k views

list all files newer than given timestamp and sort them

I want to list all files (sorted by date) that are newer than timestamp in format 20130207003851 in directory /tmp only. Subdirectories can be omitted. Using SUSE Linux Enterprise Server 11. The ...
2
votes
1answer
345 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 ...
3
votes
3answers
2k views

Preserve directory structure when moving files using find

I have created the following script that move old days files as defined from source directory to destination directory. It is working perfectly. #!/bin/bash echo "Enter Your Source Directory" read ...
-1
votes
1answer
127 views

Error while running bash script that moves files

I am new to bash script and want to create bash script that moves some days old files between source and destination as per days defined in script. When I run this script I get error find: paths ...
10
votes
4answers
2k views

Executing user defined function in a find -exec call

I'm on Solaris 10 and I have tested the following with ksh (88), bash (3.00) and zsh (4.2.1). The following code doesn't yield any result: function foo { echo "Hello World" } find somedir -exec ...
5
votes
3answers
7k views

Find files which are created a certain time after or before a particular file was created

I need a shell script which finds files which are created 1 hour before or 1 hour after a particular file (test.txt) was created. If I go with find -newer, that means I'd have to create a temporary ...
4
votes
2answers
147 views

Dealing with script interruption

I need to iterate over between 120k and 500k files. find handles this well. find $PWD -type f -path "fragments/*.pdbqt" For some reason I want to list the same set of files again, in the same ...
9
votes
4answers
8k views

How can I use bash's if test and find commands together?

I have a directory with crash logs, and I'd like to use a conditional statement in a bash script based on a find command. The log files are stored in this format: /var/log/crashes/app-2012-08-28.log ...
2
votes
1answer
133 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/*" ...
8
votes
3answers
4k views

find -exec in bash script with variable expansion

I'm trying to run a command similar to the one below in a bash script. It should search through all subfolders of $sourcedir and copy all files of a certain type to the root level of $targetdir. ...
3
votes
3answers
3k views

How to search and replace text in all php-files in a directory and it's subdirectories

I am looking for a shell script that recursively traverses all .php files in a directory and performs a search & replace of a particular text pattern. The search pattern is quite long ( > 5000 ...
3
votes
1answer
115 views

'find' across directories named …/dirnameXX/… with XX variable

I am executing this command to find certain files in specific directory: find ./rgs/test/maesXX/master/stdlist -name \*.extract \ -mtime +30 \! -size 0 -exec ls -lrt {} \; where XX could be ...
3
votes
1answer
534 views

Storing `find` parameters in a variable

I'm running the following bash command: find . \( -iname '*.aif' -o -iname '*.pdf' -o -iname '*.exe' -o -iname '*.mov' \ -o -iname '*.doc' \) -exec rm -f {} \; I'm running the same parameters ...
4
votes
3answers
235 views

Best way to work through / display a tree of images sorted by size

I've got a deep directory tree containing .PNG files. I'd like to find all the .PNG files in the directory, sort them in order of size from smallest to largest, and then display every 50th image. ...