Tag Info

New answers tagged

2

find can take many dirs as arguments: find dir1 dir2 dir3 -name pattern so find patern dir just lists everything inside two directories: pattern and dir.


1

In find, when you use the -name that means only output files with that name as a result


0

You may also try using locate utility, e.g.: updatedb -o ~/tmp.db -l0 -U $PWD; cd $(locate -d ~/tmp.db -l 1 -b -r foo-) For more complex regex pattern check info locate.


0

Based on the final requirement you don't need cd; you can do the following: find . -type d -name 'foo-*' -exec make -C {} ';' and find . -type d -name 'foo-*' -exec phing -f {}/build.xml ';' The asterisks are handled by find internally, and I believe this is POSIX compatible.


0

Does drush mung backticks and vertical bars?  If not, you could use cd `ls | grep foo- | head -n 1` If backticks don't work, but |, $, ( and ) do, then you could change the above to cd $(ls | grep foo- | head -n 1) If | doen't work, but $, ( and ) do, then you could do cd $(myprog) where myprog is a script that you write to determine the directory ...


-1

You can use DuplicateFilesDeleter, it is a fast way to find and delete all duplicate files.


6

Let us suppose that we have file1 in the current directory. Then: $ find . -maxdepth 0 -name "file1" $ find . file1 -maxdepth 0 -name "file1" file1 Now, let's look at what the documentation states: -maxdepth 0 means only apply the tests and actions to the command line arguments. In my first example above, only the directory . is listed on the ...


1

The find command has a switch for that. It's called -exec. $ find . -name '*.dcm' -exec dcmdjpeg {} {} \; This will substitute filenames as they're found by find into the places where there are {}. So in the above we'll be doing this for each filename. dcmdjpeg file1.dcm file1.dcm dcmdjpeg file2.dcm file2.dcm ... If there are spaces in your filenames ...


1

find itself doesn't support extended atttribute but you can use such as: find ~/ -type f -iname "*" -exec lsattr {} + | grep -v '\-\-\-\-\-\-\-\-\-\-\-\-\-'


0

For only adding numbers into the file. awk 'NR>1{print $1,$2,substr(FILENAME,7),$4 }' xyp/dep* > "xyzp/area1" For sorting by numbers. ls -1v xyp/dep* | xargs awk 'NR>1{print $1,$2,substr(FILENAME,7),$4 }' > "xyzp/area1" For sorting from minus numbers. ls xyp/dep* | sort -t 'p' -k 3 -n | xargs awk 'NR>1{print $1,$2,substr(FILENAME,7),$4 ...


0

Another option is find /path -perm /u=x,g=x,o=x -type f It looks through /path, finds user, global and other executables that are regular files.


1

You wrote: It surprises me to see find iterate/walk through the complete filesystem when I do a simple find -inum 12345 find, by definition, does a tree walk starting at the given directory or directories, with a default starting directory of .. find -inum 12345 will walk through the entire directory tree starting with the current working directory. ...


1

It's not as efficient, but the code is easier to read and understand, in my opinion, if you just copy the files and then delete after. find /original/file/path/* -type f -mtime +7 -exec cp {} /new/file/path/ \; find /original/file/path/* -type f -mtime +7 -exec rm -rf {} \;


4

In general, the empty string does not denote the current directory, neither to shell commands nor in system calls. It did on some older systems, but not on POSIX-compliant systems. Occasionally you'll find a program which uses the current directory when you pass an empty string and the program expects a directory name. This is sometimes deliberate, and ...


1

The very simple reason is that at least for the ext2/ext3/ext4 type filesystems the filenames are stored via the directory entries data stored in directory type files. This means that those files that are from type directory have a more or less intricate system to store filenames (of the files inside of the directory) and the inodes which lead to the data ...


-3

UNIX has three syscalls: lstat(),fstat(),stat() All of these system calls return a stat structure, which contains the following fields: struct stat { dev_t st_dev; /* ID of device containing file */ ino_t st_ino; /* inode number */ mode_t st_mode; /* protection */ nlink_t st_nlink; /* number of ...


0

If the files are in the current directory you can just use ls: $ ls *.sh If you want the files in subdirectories also and just need the filename you could do something like: $ find . -name '*.h' -exec basename {} \; There are commands that will get the absence of a string as the current directory, but basically because they will get the current ...


12

A long time ago (in 7th edition, 32V, 4.2BSD, 4.3BSD), at the system-call level a zero-length pathname denoted the current working directory (when used for lookup; it was disallowed when trying to create or delete a file or directory). In System III, it was an error to use a zero-length pathname under all circumstances, and the POSIX standard has this to say ...


0

There are various tricks you can use to get find's output without the leading ./: Use find's -printf option and tell it to only print %f. See man find: %f                     File's name with any leading directories removed (only the last element). ...


2

I cannot think of any example where the empty string denotes the current directory .. You may be thinking of invocations like ls, but that is because ls assumes the current directory if no parameter is given, and in fact it won't take the empty string: ulmi@silberfisch:~$ ls "" ls: cannot access : No such file or directory


4

You can use: find * -name "*.h" Note that files in the current directory whose name starts with . will be omitted, and files whose name starts with - will be interpreted as options by find and cause havoc, so this is not a general equivalent to find . …. The absence of of a string ending in "/" as part of a file name implies the current directory, but ...


5

Use find ... -print0 | while IFS= read -d '' construct: find ${POLLDIR} -type f -mmin +1 -print0 | while IFS= read -r -d '' -r sendfile; do echo "${sendfile}" ls -l "${sendfile}" and-so-on if success_above then mv "${sendfile}" "${donedir}/." fi done The -d '' sets the end of line character to \0 which is what separates each file found by ...


0

For directories and files already created: find /start_directory -type d -exec chmod 755 {} \; find /start_directory -type f -exec chmod 660 {} \; If your users should be able to create new files and/or subdirectories please give more details because a solution depends on exact requirements.


1

Well, just don't set the same permissions on the directory and the files within it: $ chmod g+rx directory/ $ chmod g= directory/* Here, the group members can enter and browse the directory, yet they won't be able to read the files within it. Edit: regarding your new title, I would suggest: $ chmod a+rx directory/ $ chmod u=rwX,g=rX,o= *


0

I normally use the following: find . -type f -print0 | xargs -0 sudo chmod 440 find . -type d -print0 | xargs -0 sudo chmod 555 However, that doesn't take into account executables. I was thinking of doing something like this for files: find . -type f -print0 | xargs -0 sudo chmod ug+r ug-w o-rwx But it's still two commands and I'm not sure if this is ...


9

There are errors in your assumptions, but first some background: You should discern two uses of -exec: with \; the {} will be replaced by a single item found with + the {} will be replaced by many items (as many as the commandline can hold). Therefore your example of -exec use invokes as many cp command as items found by find. Using find ... -exec ...


3

You can use find . -maxdepth 1 -mmin -$((60*5)) -type f to list all regular files in the current directory, which were changed during the last 5 hours. $((60*5)) is calculated by the shell and therefore equal to 300 min.


0

I'm not sure which version of grep you are using, but if I'm reading the man page of grep correctly, then the scanning will be stopped after the first successful match. Is that what you want? What I understood from your question was that you wanted to "open all files". If you don't mind using vim or gvim, then you can use this: $ grep -n mystring *.ext ...


1

For future reference - you can use install to do this directly: install -D ./2013/01/10/IMG_0141.JPG ../Archiv/Bilder/2013/01/10/IMG_0141.JPG Note: you need to append the file path in the second argument for this to work. In other words: Incorrect: find . -ctime +365 -exec install -D '{}' ../Archiv/Bilder/ \; Correct: find . -ctime +365 -exec install ...


1

Your find command runs into the problem that the intermediate directories (in this case /home/Bruno/Archiv/Bilder/2013/01/23/) has not been created yet. That has nothing to do with the (harmless) '.' in your path. You either have to first create the whole directory structure to the target or make a small script that you call instead of mv that first creates ...


1

-exec takes the exit status of the command you put in it and uses it logicially within find So, just something simple like this should work find . -iname "*.ext" -exec grep -q "mystring" {} \; -exec open {} \;


0

Why do you want to "touch" the file before calling gzip? From gzip's man page: Gzip reduces the size of the named files using Lempel-Ziv coding (LZ77). Whenever possible, each file is replaced by one with the extension .gz, while keeping the same ownership modes, access and modification times. You don't have to touch the file at all, simply ...


3

If you have spaces in file names then you need to use print0 option for file, later -0 for xargs, and lastly -I {} for second xargs. find . -iname "*.maxpat" -print0 | xargs -0 grep -l "mystring" | xargs -I '{}' open '{}' Tested with emacs as an open command.


-1

Use pwd by find: find `pwd` -iname *.maxpat | xargs grep -l "mystring" | xargs open


2

Using GNU find, you can search for all directories and files that belong to groupX: find / -group groupX From man find: -group gname File belongs to group gname (numeric group ID allowed).


2

You can move the external loop into an "internal" loop and obviate word-splitting issues like so: find /home/family/Music -name '*.m4a' -exec \ sh -c 'for i; do ffmpeg -i "$i" -acodec libvorbis -aq 6 -vn -ac 2 "$i.ogg"; done' sh {} + Notice that -print0 is no longer needed Additionally, you need to quote *.m4a to avoid accidental glob expansion by shell


3

Use while loop together with read -d '' -r: find /home/family/Music -name '*.m4a' -print0 | while read -d '' -r file; do echo "$file" done


0

If you want to know what the symbolic link points to, enter following command: find / -type l -exec ls -l {} \;


4

The solution that might work for your case is, find . -type d '!' -exec test -e "{}/utilities.py" ';' -print Testing I created 4 sub directories named dir1, dir2, dir3 and dir with spaces. I wanted to test if this handles spaces equally well which is why I created a directory with spaces in its name. I created files file1, file2, file3 and file4 in ...


5

That is because your -exe action is tied to the -name "*.h" put parenthesis around the expression and it will work. the default action will -print that is why the initial expression worked. find . \( -name '*.cpp' -or -name '*.h' \) -exec echo '{}' \; Also for efficiency if you use | xargs instead of -exec it is a LOT faster with a large result set as it ...


1

And just in case you need to have the most compatible version, you can do it with regular find and sort (no reliance on gnu extensions, such as printf): find . -ls | grep -i -e '\.png$' -e '\.jpe*g' | sort -k7,7nr -k7,7 : Sort on columns 7 to 7 (ie, only 7) (... this should be a parameter, allowing one to change the column number in case on their old ...


0

find /home/odroid/USBHD/Movies/ -iname "*.mkv" -mtime '-1' -print0 | xargs -0 -I{} rsync -a --ignore-existing {} /home/odroid/NASVD/Movies/


3

Put a* and d* under quotes, so that shell would not expand them,and also add -name keyword. If you only want to search for files and not also directories for example then add -type f. find . -name 'a*' -type f -exec chmod o+r {} \; find . -name '*d' -type f -exec chmod o+x {} \; If you want to change only in current directory and not subdirectories, add ...


8

You can just do the whole thing with (GNU) find and sort, no need for du: $ find . -iname '*png' -printf '%s %p\n' | sort -rn 68109 ./7.png 21751 ./2.png 21751 ./1.png 5393 ./6.png 2542 ./5.png 1717 ./4.png 1003 ./3.png 878 ./10.png 793 ./9.png 587 ./8.png


3

You could use a combination of find, du and sort like the following: find <directory> -iname "*.png" -type f -print0 | xargs -0 -n1 du -b | sort -n -r This searches for all regular files in <directory> ending with .png (case-insensitive). The result is then passed to xargs which calls du with each single file, getting its size in bytes (due to ...


0

You could do find . -name 20140926.log | while read file; do printf "%s - " "$file "; grep 123456 $file | grep -c 'food=100' done This has the advantage of not breaking on file names with spaces. It does break on newlines and backslashes, however. If your files can be completely unreasonable, use this: find . -name 20140926.log | while read -rd '' ...


1

grep -H will print file names for you, but since you're doing multiple greps you can just echo the file name yourself: for f in $(find . -name '20140926.log'); do echo -n "$f " grep 123456 $f | grep -c 'food="100"' # grep -c prints count of matches done


1

You have two syntax error: type f must be -type f. You need a space before \). So the fixed command: find . -type f \( -iname "SS1*.tar" -o -iname "SS2*.tar" -o -iname "SS3*.tar" -o -iname "SS4*.tar" \) -exec cp {} /backup_file/backup/weekly \;


1

Simpler: find . -type f -iname "SS[1234]*.tar" -exec cp {} /backup_file/backup/weekly \;


0

I faced the same problem you described. Here's my solution: #!/bin/bash files=*.jpg minimumWidth=640 minimumHeight=640 for f in $files do imageWidth=$(identify -format "%w" "$f") imageHeight=$(identify -format "%h" "$f") if [ "$imageWidth" -gt "$minimumWidth" ] || [ "$imageHeight" -gt "$minimumHeight" ]; then mogrify -resize ...



Top 50 recent answers are included