Tag Info

Hot answers tagged

5

With GNU find: find . -name foo.mp4 -printf '%h\n' With other finds, provided directory names don't contain newline characters: find . -name foo.mp4 | sed 's|/[^/]*$||' Or: find . -name foo.mp4 -exec dirname {} \; though that means running one dirname command per file. If you need to run a command on that path, you can do (standard syntax): ...


3

man rsync says about --files-from: The filenames that are read from the FILE are all relative to the source dir -- any leading slashes are removed and no ".." references are allowed to go higher than the source dir. So try making the paths output by find relative: rsync -avz ... --files-from=<(ssh user@remote1 'cd /home/admin/Backup/; ...


3

You don't need xargs at all, just use exec option: find . -maxdepth 1 -name "*.md" -exec aspell check {} \; And just in case you, or any future reader, will really need to use xargs - you can do that by spawning new shell and taking standard input from terminal (/dev/tty): find . -maxdepth 1 -name "*.sh" | xargs -n1 sh -c 'aspell check "$@" < ...


3

Use a while-read loop to process the lines of the file while IFS=: read userid filename do find . -user "$userid" -name "$filename" done < "$uidscript"


2

While the other options are fine, I'd like to correct some mistakes in your approach: userid=$(cat $uidscript|cut -c1 -d':'): -c gets characters, you need fields. Use cut -f1 -d:. Useless use of cat: Just do: cut -f1 -d: <"$uidscript". Store the result in an array so you can iterate over it and another array easily: IFS=$'\n' # split on newline set ...


2

You could do: IFS=: # split on : set -f # disable glob part of the split+glob operator echo find . $( awk -F: ' { printf "%s", sep "(:-user:" $1 ":-name:" $2 ":):" sep = "-o:" }' < "$uidfile") (remove the echo if that's the right command you want to run).


1

You could always just use a simple loop: for f in *.md; do aspell check "$f"; done


1

If you want to test for any of the bits, use /. I.e. for your use case: find $DIRECTORY -perm /4000 and: find $DIRECTORY -perm /2000 or combined: find $DIRECTORY -perm /6000 You may use both folders and files as argument for GNU find. Another, IMO better readable, approach is using the mnemonic shortcuts. I.e.: find $DIRECTORY -perm /u=s,g=s ...



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