LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Reversing a wrong command (https://www.linuxquestions.org/questions/linux-newbie-8/reversing-a-wrong-command-4175533919/)

abudy8 02-13-2015 10:30 AM

Reversing a wrong command
 
Hi,

I created a user and when i logged in it took me to the $>
I was reading online and i stumbled with this command
cp -r /etc/skel/.* etc/skel/*
I was stupid enough to copy it
Now our home folder is full of files and my boss is not happy.

Is there a reverse to this command? or Can I just delete the files been copied?

Thanks

camorri 02-13-2015 10:50 AM

The reverse command would be rm. You can try to delete the files, however, most files found in the root file system will be owned by root and group root. Odds are, you do not have the privileges to delete these files.

Only the system administrators are going to be able to delete the files. So, find out who that is, and get them deleted.

abudy8 02-13-2015 11:01 AM

I deleted the file with the admin. Now somehow even user folders when they try to access it is permission denied .
I am trying to chown command to certain files. but still doesn't fix it

Users are frustrated now

What shall I do?

suicidaleggroll 02-13-2015 11:23 AM

You need to get a lot more specific about what you ran and where, what these files you're trying to remove are, what permissions things have been set to, etc.

Habitual 02-13-2015 11:41 AM

Quote:

Originally Posted by abudy8 (Post 5316612)
I deleted the file with the admin. Now somehow even user folders when they try to access it is permission denied .
I am trying to chown command to certain files. but still doesn't fix it

Users are frustrated now

What shall I do?

Let's look at exactly what happened...open a terminal and search in the (bash is it?) history file.
Code:

history | grep "cp -r" | last
and show us the output.

Stop changing file permissions and/or groups immediately.

abudy8 02-13-2015 12:11 PM

This is the part I missed up with

root pts/4 dynamic-10-124-2 Tue Feb 10 11:15 - 11:18 (00:03)
Al pts/4 dynamic-10-124-2 Tue Feb 10 10:49 - 11:14 (00:24)
Al pts/4 dynamic-10-124-2 Tue Feb 10 10:38 - 10:49 (00:10)
root pts/4 dynamic-10-124-2 Tue Feb 10 10:31 - 10:38 (00:06)
root pts/4 dynamic-10-124-2 Tue Feb 10 10:24 - 10:27 (00:02)
Al pts/4 dynamic-10-124-2 Tue Feb 10 10:19 - 10:24 (00:05)
root pts/4 dynamic-10-124-2 Tue Feb 10 10:10 - 10:19 (00:08)
Al pts/4 dynamic-10-124-2 Tue Feb 10 10:08 - 10:10 (00:01)
root pts/4 dynamic-10-124-2 Tue Feb 10 09:58 - 10:08 (00:10)

suicidaleggroll 02-13-2015 12:15 PM

I believe he meant
Code:

history | grep "cp -r" | tail
not last, last shows a list of the last logged in users which isn't of much use here, I don't think.

abudy8 02-13-2015 02:07 PM

I think It is working fine now.

Thank y'all

linux_walt 02-13-2015 03:38 PM

Glad to hear you didn't get fired.

Since I did a little experimenting, here's some commands you might enjoy to experiment with -on your own computer- :) :

In the directory that you need to remove files and folders newer than a certain day,

this should remove new folders:
rm -r $(find . -newerBt $(date +%Y-%m-%d -d '1 day ago'))

this should remove new files:
rm $(find . -newerBt $(date +%Y-%m-%d -f '1 day ago'))

The B in newerBt should stand for 'creation date'. However, the man page for 'find' states that this might not be supported on all systems.

I'm curious about the home directory being full of files. Were the extra files in the home directory itself, or in the home/<new user> directory you created?

http://www.linuxquestions.org/questions/linux-newbie-8/find-only-new-created-files-from-certain-date-=-display-folder-and-path-only-910158/

http://stackoverflow.com/questions/6...han-given-time

josephj 02-13-2015 10:17 PM

File Creation Date
 
@linux_walt - AFAIK, most file systems do not maintain a file creation date. I'm pretty sure ext[23] don't support it. Ext4 may, but it still might not be implemented. I seem to recall seeing something about it being implemented in either zfs or btrfs.

Besides, the semantics of it are very cloudy (at least to me). What does it mean if a file was created at one time, but its contents were completely replaced at a later time? It still uses the same inode, but it could even have been renamed.

@abuddy8 - It looks like you were running as the new user when you issued the unfortunate command. If that's the case, only that user was messed up. If so, the quickest thing would have been to just delete the user and add it back in again. Since it was just created, there wasn't anything there yet to lose.

You'd have to log in as another user or root for this to work, but you were able to do that to create the user in the first place.

Code:

sudo userdel -r username
http://www.cyberciti.biz/faq/linux-remove-user-command/

looks like it would have done the trick.

linux_walt 02-13-2015 10:56 PM

It's cloudy to me too, but I did test the first command to remove newer directories, and it seemed to work. Sort of. It does remove new folders, but also generates a lot of errors, because some of the folders it tries to delete, were already deleted when their parent folder was deleted. It can use a tweak to limit deletion to only the top level folders. It's just a rough pointer, slapped together using 2% knowledge an 98% google. At first it seemed like it should be a simple task.

By the way, does it not seem like another simple task to write an undo function? Previous commands can all be recalled. Just making things up, but some kind of backwards command parser?

Ps Not shure if I tested it with the 'B' option or not.

EDDY1 02-13-2015 11:50 PM

Quote:

In the directory that you need to remove files and folders newer than a certain day
You also have to be aware of the "Modification Date".
You can also check bash history to view commands previously used.
https://www.digitalocean.com/communi...on-a-linux-vps

josephj 02-14-2015 12:37 AM

@linux_walt - That would be nice, but the world isn't usually that symetrical. E.G. if you delete something in Linux (without using the trash can), it's gone. If you chmod a file, history won't tell you what permissions it had to start with so you would know what to change it back to. I'm sure there are lots of other similar situations.

The only true "undo" commands are rsync (and similar commands) when you use them to make frequent backups which you can restore things from after a problem.

orhank 02-17-2015 10:55 AM

Quote:

Originally Posted by abudy8 (Post 5316597)
Hi,

I created a user and when i logged in it took me to the $>
I was reading online and i stumbled with this command
cp -r /etc/skel/.* etc/skel/*
I was stupid enough to copy it
Now our home folder is full of files and my boss is not happy.

Is there a reverse to this command? or Can I just delete the files been copied?

Thanks

How did you manage to copy files to /etc if you are not root?

josephj 02-18-2015 02:54 AM

@orhank - he didn't. There's no leading slash in the destination. The files and directories were copied into the current directory which was probably the user's home directory. So it qualifies as a big mess rather than a big disaster. (So much better ;) )


All times are GMT -5. The time now is 10:29 AM.