LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 01-03-2021, 10:00 AM   #1
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Rep: Reputation: Disabled
Lightbulb [lost+found] command cp not working


My usb stick is formatted in ext4 (the command mount -t vfat wasn't found at that moment). But when I want to copy everything from it, the cp command fails because of the lost+found directory.
Is there a way to bypass the error? For example, I tried
Code:
mount -v /dev/sdXY /mnt
cp /mnt/* ~/mydir 2> /dev/null
cp /mnt/* ~/mydir 2> /dev/null 1>&2
but it's not enough... Any idea?
 
Old 01-03-2021, 11:40 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,745

Rep: Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924
The lost+found directory is used by the fsck utility to copy corrupted and orphaned files. It is owned by root and a regular user does not have permissions to access the directory. When an ext filesystem is created the lost+found directory is also created in the filesystems "root" directory.

There is no need to copy the lost+found directory but everything else should still copy ok.
 
1 members found this post helpful.
Old 01-03-2021, 11:44 AM   #3
aiszisz
LQ Newbie
 
Registered: Dec 2020
Distribution: Slackware64 14.2
Posts: 28

Rep: Reputation: 11
Could you post the outputs of mount and cp?
Of course without the 2 > /dev/null

lost+found should be hidden as far as I know and hidden files are not copied by cp

Last edited by aiszisz; 01-03-2021 at 11:51 AM.
 
1 members found this post helpful.
Old 01-03-2021, 11:56 AM   #4
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Quote:
Originally Posted by aiszisz View Post
Could you post the outputs of mount and cp?
Of course without the 2 > /dev/null

lost+found should be hidden as far as I know and hidden files are not copied by cp
I think that you will find this applies to lost+found everywhere.

drwx------. 2 root root 16384 Feb 23 2018 lost+found

It is not hidden and cannot be copied by anyone except root. It should not ever be needed unless a device is failing. It only applies to the device/filesystem where found so should never be needed in any other form.

Last edited by computersavvy; 01-03-2021 at 12:01 PM.
 
1 members found this post helpful.
Old 01-03-2021, 12:20 PM   #5
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
The lost+found directory is used by the fsck utility to copy corrupted and orphaned files. It is owned by root and a regular user does not have permissions to access the directory. When an ext filesystem is created the lost+found directory is also created in the filesystems "root" directory.

There is no need to copy the lost+found directory but everything else should still copy ok.
The command cp /mnt/* ~/mydir stops after copying the first file, but if I try to copy the files one by one it works
Quote:
Originally Posted by aiszisz View Post
Could you post the outputs of mount and cp?
Of course without the 2 > /dev/null

lost+found should be hidden as far as I know and hidden files are not copied by cp
It's on another computer I just turned off... Maybe tomorrow I answer your question
Quote:
Originally Posted by computersavvy View Post
I think that you will find this applies to lost+found everywhere.

drwx------. 2 root root 16384 Feb 23 2018 lost+found

It is not hidden and cannot be copied by anyone except root. It should not ever be needed unless a device is failing. It only applies to the device/filesystem where found so should never be needed in any other form.
Maybe it's because the user is in the wheel group?
 
Old 01-03-2021, 12:33 PM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,927

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
2>/dev/null does not bypass any error, just suppresses the error message.
You ought to try rsync instead of cp, if you wish to skip/ignore directories (like lost+found).
 
1 members found this post helpful.
Old 01-03-2021, 01:04 PM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,745

Rep: Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924Reputation: 5924
Quote:
The command cp /mnt/* ~/mydir stops after copying the first file, but if I try to copy the files one by one it works
Then you might have permission and/or other problems.

As a quick test I created a disk image formatted as ext4 and created a few files owned by my user.

A cp /mnt/test/* /destination copied everything except the lost+found directory and the output was just a warning
cp: omitting directory ‘/mnt/test/lost+found’
 
1 members found this post helpful.
Old 01-04-2021, 10:55 AM   #8
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Then you might have permission and/or other problems.
Today it all goes well... Maybe I was doing the copy with root or with a sudo? Thank you for taking the time to try
 
Old 01-04-2021, 10:58 AM   #9
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
2>/dev/null does not bypass any error, just suppresses the error message.
Understood
Quote:
Originally Posted by pan64 View Post
You ought to try rsync instead of cp, if you wish to skip/ignore directories (like lost+found).
It's for a few config files but thanks for the rsync command, one day I need to give it a try
 
Old 01-05-2021, 03:49 AM   #10
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by thomasbb View Post
Is there a way to bypass the error? For example, I tried
Code:
mount -v /dev/sdXY /mnt
cp /mnt/* ~/mydir 2> /dev/null
cp /mnt/* ~/mydir 2> /dev/null 1>&2
but it's not enough... Any idea?
Remove the 2> /dev/null 1>&2 and 2> /dev/null!
then add the -v option to cp:
Code:
cp -v /mnt/* ~/mydir
cp -v /mnt/* ~/mydir
BTW, cp does not copy recursively until you tellit to do so. In other words, this will only copy single files, not directories with something in them.
Code:
man cp
 
2 members found this post helpful.
Old 01-05-2021, 05:17 AM   #11
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
Remove the 2> /dev/null 1>&2 and 2> /dev/null!
then add the -v option to cp:
It didn't work at that time, maybe I was doing the cp with sudo or root?
But yesterday, everything was ok
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] No package 'x11' found No package 'xext' found No package 'xdamage' found No package 'xfixes' found No package 'x11-xcb' found Jigsaw Linux From Scratch 14 02-23-2021 08:35 PM
"Command not found" on my server? “bash: sudo: command not found”? MilesOfRoses Linux - Server 7 04-01-2016 09:19 AM
[SOLVED] complete noob question. "command not found" "command not found" jeanlucpicard Linux - Newbie 4 08-27-2013 02:14 AM
Directory not found; -xzvf not found; Makefile not found RealGomer Linux - Software 4 09-20-2010 10:02 AM
bash: rpm: command not found && sudo: alien: command not found Java_Code Ubuntu 7 07-27-2006 11:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration