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 |
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. |
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? |
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.
|
Quote:
Code:
history | grep "cp -r" | last Stop changing file permissions and/or groups immediately. |
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) |
I believe he meant
Code:
history | grep "cp -r" | tail |
I think It is working fine now.
Thank y'all |
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 |
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 looks like it would have done the trick. |
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. |
Quote:
You can also check bash history to view commands previously used. https://www.digitalocean.com/communi...on-a-linux-vps |
@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. |
Quote:
|
@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. |