I tried the options:

ls -lrt | awk '{ f=$NF }; END{ print f }' 


 ls -t1 | head -n1 

But the last file copied to the folder is not shown. What other options are there?

UPD: Option does not work either:

 ls -t1 | tail -n1 

All these commands always give out one single file name for my folder. Although the files continue to continuously flow into the folder. What is needed is the last file in the folder. It does not have to be the newest file.

  • If you still understand what you ask. Do you copy a group of files to a folder and want to track the process? Or what? And further. If this is what I think about, then I don’t know the general solution, but for a more specific tip, I need additional information about the problem. (By the way for a specific file - tail -f ) - alexlz
  • Watch - did not look, but on stackoverflow recommend dnotify, and apt-cache gave the answer fam. Watch it apt-cache search dnotify fam - monitor files - alexlz
  • can be on history grepnut. but better LS and on the time of creation - jmu
  • on time modification then. - thunder
  • And how to find out the time of creation? - alexlz

2 answers 2

@abg , file modification time is measured in seconds . Therefore, when bulk copying such files (with the same time) there will be many.

Your team

 ls -t1 | tail -n1 

shows the last (oldest, not the latest) file. But

 ls -t | head -1 

will show the newest (one of them).

In general, if you describe the problem in more detail, then there may be some better solution.

    For the general case, perhaps suitable

     cp -v 'from' 'to' | tail -1 

    To highlight the name of the file, you probably have to use regular. Like that:

     cp -v 'from' 'to' | tail -1 | sed 's/.*\/\(.*\)»$/\1/' 
    • What kind of nonsense? avp @ avp-ubu1: ~ / hashcode $ cp -v | tail -1 cp: missing file operand Try `cp --help 'for more information. avp @ avp-ubu1: ~ / hashcode $ @goozler, have you tried it yourself? - avp
    • I wrote a template. It is clear that the copy team needs input: what to copy and where. Now I will correct the answer, if it is not clear. - goozler
    • uh, well, just the beginning of the command, I mean copying with the command cp -v src / * dst or something similar - sercxjo
    • This is another matter (just do not be so careless to make answers). Only, it seems to me, the author had in mind another task. IMHO he monitors the directory, and the file providers (those who copy to the directory) are unknown to him (or their code is not available). - avp