Tag Info

Hot answers tagged

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 ...


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 ...


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


7

Why do so difficult with -regex? Just do it with -name find -type f -name "[[:upper:]]*"


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 ...


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 ...


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 ...


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 ...


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 ...


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 ...


4

I assume all the 250 files are in the same directory and follow the same naming pattern. If that is the case, you could do, for i in "$remove"*;do mv "$i" "${i#"$remove"}";done Testing ls no_responseEvent_2002.02.07.03.15.56.970 no_responseEvent_2002.02.07.03.15.56.972 no_responseEvent_2002.02.07.03.15.56.971 ...


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 ...


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


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 ...


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.


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.


3

You'll want to use find's -exec option: find corpus/ -type f -exec ./individual.sh {} \; For each match that find finds, it'll execute individual.sh, replacing {} with the name of the file it found. \; is how you end an exec with find. The reason your pipe doesn't work is that the output from find is being provided to individual.sh via STDIN, not as an ...


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


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


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.


2

The -exec operand of find evaluates to true if the command succeeds (i.e. returns zero) and false if it fails (returns nonzero), so you can use the success/failure of grep as part of the expression used by find. Together with find's ! operand, which negates the following operand, you can search for files for which one grep command succeeds and another grep ...


1

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


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 '\-\-\-\-\-\-\-\-\-\-\-\-\-'


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

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 ...


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= *


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 ...



Only top voted, non community-wiki answers of a minimum length are eligible