cmds copy and rm do not work on home directory SOLVED

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
pgmer6809
Level 4
Level 4
Posts: 228
Joined: Sun Mar 04, 2012 9:06 pm

cmds copy and rm do not work on home directory SOLVED

Post by pgmer6809 »

I have been trying to move my home directory to another partition.
but the cp cmd from the cmd line just does not want to copy most of my files in my home directory. It is almost as if it cant see them.
If I

Code: Select all

sudo su - to
root, and then do an

Code: Select all

 ls -al
I can see lots of files there. But when I just cp nothing much happens.

same sort of behaviour with rm. rm does not seem to see most of the files in my home directory. even as root I cant just rm -R *
however if I do a

Code: Select all

find . -name '*' -exec rm -R \{\} \; 
THEN most of the files get removed.

what has Mint done to prevent the proper operation of cp, rm, ls etc. even when running as root?

how does the MINT backup tool manage to get this done properly?

pgmer6809


SOLVED
ls -a fromdir
. .. .hide1 .hide2 junk1 junk2

cp fromdir/* fromdir/.??* todir

ls -a todir
. .. .hide1 .hide2 junk1 junk2
Works like a charm thanks. I'm embarassed I did not think of that myself. I was thinking in terms of a regex * matching everything without taking into account that file system utilities might have some extra smarts built in.
pgmer6809
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 3 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
karlchen
Level 23
Level 23
Posts: 18209
Joined: Sat Dec 31, 2011 7:21 am
Location: Germany

Re: cmds copy and rm do not work on home directory

Post by karlchen »

Hello, pgmer6809.

The point is that the filename mask "*" will return all filesnames which do not start with a leading dot.
Therefore

Code: Select all

cp * sometarget
will copy all files found in the current folder to sometarget, except all the files the names of which start with a leading dot.
Every profile folder, however, holds a lot of files and folders the names of which start with a leading .dot.

On the commandline you have to specify normal filenames and dot filenames separately, e.g. something like this

Code: Select all

cp ./* ./.* sometarget
In order to copy / move a complete home folder using a graphical file manager like Gnome Commander may be much more convenient. It can be configured to display hidden filenames and foldernames, too, i.e. the ones starting with a dot.

By the way, ignoring hidden objects by default is not special to Linux Mint, rather it is the normal behaviour on any Linux based system.

HTH,
Karl
Image
The people of Alderaan have been bravely fighting back the clone warriors sent out by the unscrupulous Sith Lord Palpatine for 771 days now.
Lifeline
User avatar
bjornmu
Level 3
Level 3
Posts: 189
Joined: Wed Dec 19, 2012 2:50 am
Location: Trondheim, Norway

Re: cmds copy and rm do not work on home directory

Post by bjornmu »

If you need to copy the *entire* home directory it's easiest to cd to the directory above it and then just do

Code: Select all

cp -pR user <target>
(Replace user with your user name). If the target directory already exists, you will get a subdirectory under it called 'user', otherwise you'll get the target directory as a copy of the original. This should copy absolutely everything. The 'p' option to cp is important as it preserves access flags so that executable files remain executable etc.

The suggestion of using ./.* to cover "dot files" may not be a good idea, as that also includes the special links . and ..

Whenever I need to do something with all "dot" files I use the pattern .??* which covers all except those with just a single character after the dot.
Locked

Return to “Scripts & Bash”