The following command:
find . -name "file2015-0*" -exec mv {} .. \;
Affects about 1500 results. One by one they move a previous level.
If I would that the results not exceeds for example in 400? How could I?
The Bash find Command 101 The find command allows you to define those criteria to narrow down the exact file(s) you'd like to find. The find command finds or searches also for symbolic links (symlink). A symbolic link is a Linux shortcut file that points to another file or a folder on your computer.
There are many methods to quit the bash script, i.e., quit while writing a bash script, while execution, or at run time. One of the many known methods to exit a bash script while writing is the simple shortcut key, i.e., “Ctrl+X”. While at run time, you can exit the code using “Ctrl+Z”.
The find command is used to search and locate the list of files and directories based on conditions you specify for files that match the arguments. find command can be used in a variety of conditions like you can find files by permissions, users, groups, file types, date, size, and other possible criteria.
You can do this:
find . -name "file2015-0*" | head -400 | xargs -I filename mv filename ..
If you want to simulate what it does use echo
:
find . -name "file2015-0*" | head -400 | xargs -I filename echo mv filename ..
You can for example provide the find
output into a while read
loop and keep track with a counter:
counter=1
while IFS= read -r file
do
[ "$counter" -ge 400 ] && exit
mv "$file" ..
((counter++))
done < <(find . -name "file2015-0*")
Note this can lead to problems if the file name contains new lines... which is quite unlikely. Also, note the mv
command is now moving to the upper level. If you want it to be related to the path of the dir, some bash conversion can make it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With