LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 02-13-2015, 11:30 AM   #1
abudy8
LQ Newbie
 
Registered: Feb 2015
Posts: 9

Rep: Reputation: Disabled
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
 
Old 02-13-2015, 11:50 AM   #2
camorri
LQ Guru
 
Registered: Nov 2002
Location: Somewhere inside 9.9 million sq. km. Canada
Distribution: Slackware 14.1, 14.2
Posts: 5,090

Rep: Reputation: 483Reputation: 483Reputation: 483Reputation: 483Reputation: 483
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.
 
Old 02-13-2015, 12:01 PM   #3
abudy8
LQ Newbie
 
Registered: Feb 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
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?
 
Old 02-13-2015, 12:23 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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.
 
Old 02-13-2015, 12:41 PM   #5
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,166
Blog Entries: 10

Rep: Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979
Quote:
Originally Posted by abudy8 View Post
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.
 
Old 02-13-2015, 01:11 PM   #6
abudy8
LQ Newbie
 
Registered: Feb 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
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)
 
Old 02-13-2015, 01:15 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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.
 
Old 02-13-2015, 03:07 PM   #8
abudy8
LQ Newbie
 
Registered: Feb 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
I think It is working fine now.

Thank y'all
 
Old 02-13-2015, 04:38 PM   #9
linux_walt
Member
 
Registered: Dec 2014
Location: Houston, TX
Distribution: Debian wheezy
Posts: 127

Rep: Reputation: 28
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

Last edited by linux_walt; 02-13-2015 at 05:51 PM.
 
Old 02-13-2015, 11:17 PM   #10
josephj
Member
 
Registered: Nov 2007
Location: Northeastern USA
Distribution: kubuntu
Posts: 110

Rep: Reputation: 53
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.
 
Old 02-13-2015, 11:56 PM   #11
linux_walt
Member
 
Registered: Dec 2014
Location: Houston, TX
Distribution: Debian wheezy
Posts: 127

Rep: Reputation: 28
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.

Last edited by linux_walt; 02-13-2015 at 11:57 PM.
 
Old 02-14-2015, 12:50 AM   #12
EDDY1
LQ Addict
 
Registered: Mar 2010
Location: Oakland,Ca
Distribution: wins7, Debian wheezy
Posts: 6,838

Rep: Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649
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

Last edited by EDDY1; 02-14-2015 at 12:57 AM.
 
Old 02-14-2015, 01:37 AM   #13
josephj
Member
 
Registered: Nov 2007
Location: Northeastern USA
Distribution: kubuntu
Posts: 110

Rep: Reputation: 53
@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.

Last edited by josephj; 02-14-2015 at 01:38 AM. Reason: clarification
 
Old 02-17-2015, 11:55 AM   #14
orhank
LQ Newbie
 
Registered: Dec 2012
Location: Istanbul, Turkey
Distribution: Ubuntu 12.04, Ubuntu 14.04, Solaris 10, Solaris 11, Windows 7 and 8.1
Posts: 21

Rep: Reputation: Disabled
Quote:
Originally Posted by abudy8 View Post
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?
 
Old 02-18-2015, 03:54 AM   #15
josephj
Member
 
Registered: Nov 2007
Location: Northeastern USA
Distribution: kubuntu
Posts: 110

Rep: Reputation: 53
@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 )
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Reversing rm /usr/lib command Trad Linux - General 8 09-11-2014 09:31 AM
Reversing Multilib mlangdn Slackware 3 02-05-2010 01:00 PM
reversing program greenthing Programming 3 02-27-2005 09:08 PM
reversing a number narendra_i Linux - Software 1 11-15-2003 10:25 AM
reversing videocard lackluster Linux - Hardware 1 11-16-2002 03:58 PM


All times are GMT -5. The time now is 08:49 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration