Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi pals, I am trying to find all the files that are more than 2 days old, then only taking 10 files and copying them to my current working directory. The command I am using is
in your example tail will print the first 10 lines of every file found.
you might want to do something like:
Code:
find .... | tail ... | xargs ....
Do you really need that sudo at the beginning?
Is this your homework?
Thanks! Well, this is part of a bigger assignment but as you may notice I am learning these pieces and learning to put them together rather than asking someone to do the assignment on my behalf.
In relation to the question, I haven't been able to produce the desired output. But I am working at it:
Also, if there are spaces in the file or directory names, then you'll want to use -print0 instead of -print with find and --zero-terminated for tail and --null for xargs.
Also, if there are spaces in the file or directory names, then you'll want to use -print0 instead of -print with find and --zero-terminated for tail and --null for xargs.
I am sorry I couldn't understand you. I haven't used -print anywhere. What are you trying to suggest? Thanks anyway for your willingness to help!
see man find (for example). -print is there, by default, otherwise find will not print the result. If you have files or dirs whith space[s] in their names (like: My Folder, Home Dir, or anything similar) then you need to use -print0.
see man find (for example). -print is there, by default, otherwise find will not print the result. If you have files or dirs whith space[s] in their names (like: My Folder, Home Dir, or anything similar) then you need to use -print0.
Oh, I now understand what you meant. So I included that option too. But the output is still this:
Code:
[osboxes@osboxes audios]$ find / -type f -mtime +2 -print0 2>/dev/null | tail -n 5 | xargs --null cp -p .
cp: target '/home/osboxes/.local/share/Trash/files/sysstat-12.5.1/tests/04120' is not a directory
cp: target '/home/osboxes/.cache/mozilla/firefox/u8yq4oi3.default-default/cache2/entries/086767472BEAC57998BD85866314BF1EAE9E6B0A' is not a directory
cp: target '/var/log/vboxadd-install.log' is not a directory
cp: target '/usr/lib/modules/4.18.0-193.el8.x86_64/kernel/drivers/hwmon/lm83.ko.xz' is not a directory
...
No problem. Be sure to look up each of the options used above in the manual pages. The idea is not so much to remember them as to be able to comfortably look stuff up as needed.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.