Hot answers tagged

7

Try: for movie in ./*/*.mp4; do mv -- "${movie%/*}/folder.jpg" "${movie%.mp4}.jpg"; done ${movie%/*} and ${movie%.mp4} are both examples of suffix removal. ${movie%/*} returns the directory that the movie file is in and ${movie%.mp4} returns the name of the movie file minus the extension .mp4. Example Consider three directories, dir1, dir2, and dir3, ...


3

You can do this with find and mv, but it isn't the simplest approach here. You're on macOS, so zsh is preinstalled. Zsh comes with a neat file mass-renaming tool called zmv. Run zsh in a terminal, then in zsh run something like: autoload zmv zmv -n '[^_]#_([0-9])_*' '/elsewhere/${1}/${f}' Explanations: -n tells zmv to display what it would do, but not ...


2

Have you tried aide? I think it will help in your case. # apt install aide [On Debian/Ubuntu] # yum install aide [On RHEL/CentOS] # dnf install aide [On Fedora 22+] # zypper install aide [On openSUSE] # emerge aide [On Gentoo]


2

If you've got the perl version of rename (sometimes formerly called prename) you can apply a Regular Expression substitution: rename -n 's/^.*?\.(.*?)#.*/$1/' * If you don't understand Regular Expressions (REs) they're very much worth learning. s/xx/yy/ - replace xx with yy ^ - match an implicit start-of-line .*? - match as short a string as possible of ...


2

If a variable, filename, contains one of your files' name, then ${filename%.job-*} would be the name without the bit after the last dot. To loop over the filenames, renaming each one in turn, for filename in SOA_*.job-*; do echo mv -i "$filename" "${filename%.job-*}" done The echo is there for protection. You should run the loop once and inspect the ...


1

The shell is splitting input on whitespace. You can use bash globbing with the recursive ** to get the filenames split properly: shopt -s globstar for f in **/*_0_*; do mv "$f" /dest/; done If they're all going to the same place, the loop is not needed: shopt -s globstar mv **/*_0_* /dest/ ... or use find -exec, which passes filenames directly from ...


1

You could try the inotify tools. It is available in a wide selection of Linux-like OSes. It works by adding a "watch" to a directory, specifying events to listen for. A lovely article on this subject can be found at https://www.linuxjournal.com/content/linux-filesystem-events-inotify From the manpage: DESCRIPTION The inotify API provides a ...


1

Use find -exec: find /opt/slm/data -name data.log -exec sh -c ' TARGET="/opt/slm/output/$(basename "$(dirname "$1")")"; cp -i "$1" "$TARGET" ' find-sh {} \;


1

With zsh: autoload zmv # best in ~/.zshrc zmv -n -C '**/(*)/data.log' '/opt/slm/output/$1' remove the -n (for dry run) if happy. The -C is for copy (as oppose to rename/mv) as even though your description says rename, it looks like you want to copy the files instead into the output directory.


1

#!/bin/bash OUTDIR=/opt/slm/output/ find /opt/slm/data -name data.log | while read FILE; do OUTFILE="$(basename "$(dirname "$FILE")")" cp -p "$FILE" "$OUTDIR$OUTFILE" done


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