I use Ubuntu 16.04 (xenial) with Bash 4.3.48(1) and zip 3.0.

In a file containing a bash script (#!/bin/bash) with many different functions, I also have this function used to create a full database backup + document root backup in one zip file:

imb() {
    date="$(date +%F-%T)"
    mysqldump -u root -p --all-databases | zip "$drt/db-$date.zip" - # Note the hyphen before this comment;
    zip -r "all_zipped-$date.zip" "$drt"/ -x "*/cache/*"
    rm -f "$drt/db-$date.zip"

I sourced the aformentioned file (source ~/function.sh) and executed imb in debug mode (set -x):

I was prompted for DB password and then some time passed (indicating DB backup created). Also, a verbose zip appeared (too long to paste or trace in terminal) indicating everything under document root was zipped.

Yet no backup appears under /var/www/html/.

My question

Due to a comment I feel I should ask two questions, which I found similar but actually different:

  1. Where did zip put my files (assuming this isn't a"file creation" in the sense of manual creation as with touch, for example)? Of course, files created and located somewhere by a processes, shouldn't necessarily be owned by my user.

  2. How could I find out where the the last file created by my current user, was located?

I expected it to be located in /var/www/html/:

zip -r "all_zipped-$date.zip" "$drt"/ -x "*/cache/*"

but wasn't. I don't know an efficient way to know where it was created without running on the entire file tree of my system up from root (/), as this could take hours in that machine.


When writing this question I visited my home dir ($HOME/), there I found the file, but I don't know why it was created there instead under document root.

  • You have two slightly different zip commands there... – Jeff Schaller Apr 14 '18 at 14:28
  • If you still have the output from the imdb run, the first few and last few lines of the zip command may be helpful. We don’t need to see the files it backed up, just whether it indicated where it put the zip file (or if it had trouble doing so). – Jeff Schaller Apr 14 '18 at 14:48
  • Is your question, what was the last file that the current user touched (as you have stated it). OR Where did zip (that I have just this moment run) put my files? – ctrl-alt-delor Apr 14 '18 at 17:33
  • @ctrl-alt-delor It's a good point: I think, and I might be wrong, that if I ran a command a sudo it isn't distinguishable (both the manual file creation and the function create a file owned by root). – user9303970 Apr 14 '18 at 17:39
  • @user9303970 that was not my point (being root or not), but this point is also valid. – ctrl-alt-delor Apr 14 '18 at 17:42
zip -r "all_zipped-$date.zip" "$drt"/ -x "*/cache/*"

creates an archive in the current directory, whatever that happens to be (your home directory in this case).

If you want to create the archive in ${drt}, you need to tell zip:

zip -r "${drt}/all_zipped-$date.zip" "$drt"/ -x "*/cache/*"

There’s no trivial way to find out where the last file was created by any given user; you’d need to use find and sort by decreasing timestamp. Using the last modification time as an approximation for creation time:

find . -user user9303970 -printf "%T@ %p\n" | sort -n -k1,1 -r | head -n 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.