Restore dot files in home directory to default on Linux
Restore dot files in home directory to default on Linux
Introduction
We are human. We all make mistakes. Have you ever messed up with your dot files? I did. Luckily, I always have them backed up so that I can restore them when I need. It is a good idea to save your dot files somewhere. You can even put that on your Github. I was lucky, but how could I restore my dot files to default if there were no backups? Of course, we can go to Github and download a copy of dot files from someone else, but in this article, we will teach you how to restore your dot files to default locally.
How can we restore the dot files to default?
In Linux, there is a skeleton directory containing the sample dot files that will be copied to the new user’s home directory when it is created.
First, we need to find out where the skeleton directory is. Then we can copy the default dot files to our home directory. To find out where the skeleton directory is, we need to check the file /etc/default/useradd
which defines the default values for adding a new user.
Let’s take a look at how we are going to restore the dot files in actions!
Steps to restore the dot files
- Find out the skeleton directory in
/etc/default/useradd
.
noob@learnfromnoobs:~$ cat /etc/default/useradd
# Default values for useradd(8)
#
# The SHELL variable specifies the default login shell on your
# system.
# Similar to DHSELL in adduser. However, we use "sh" here because
# useradd is a low level utility and should be as general
# as possible
SHELL=/bin/sh
#
# The default group for users
# 100=users on Debian systems
# Same as USERS_GID in adduser
# This argument is used when the -n flag is specified.
# The default behavior (when -n and -g are not specified) is to create a
# primary user group with the same name as the user being added to the
# system.
# GROUP=100
#
# The default home directory. Same as DHOME for adduser
# HOME=/home
#
# The number of days after a password expires until the account
# is permanently disabled
# INACTIVE=-1
#
# The default expire date
# EXPIRE=
#
# The SKEL variable specifies the directory containing "skeletal" user
# files; in other words, files such as a sample .profile that will be
# copied to the new user's home directory when it is created.
# SKEL=/etc/skel
#
# Defines whether the mail spool should be created while
# creating the account
# CREATE_MAIL_SPOOL=yes
We can see from the following line that our skeleton directory is set to /etc/skel
. It also gives us great information about what skeleton directory is.
...
# SKEL=/etc/skel
...
- Look for the file we want to restore in the skeleton directory (
/etc/skel/
in our example).
noob@learnfromnoobs:~$ ls -la /etc/skel
total 20
drwxr-xr-x 2 root root 4096 Aug 5 2019 .
drwxr-xr-x 91 root root 4096 Apr 5 06:24 ..
-rw-r--r-- 1 root root 220 Apr 4 2018 .bash_logout
-rw-r--r-- 1 root root 3771 Apr 4 2018 .bashrc
-rw-r--r-- 1 root root 807 Apr 4 2018 .profile
- Copy the sample file we need to our home directory. Let’s pick
.profile
in our example.
$ cp /etc/skel/.profile ~/
Done! Your ~/.profile
is now back to default!
Conclusion:
In this article, we discussed how to restore dot files to default:
- Locate the skeleton directory in
/etc/default/useradd
. - Look for the file we want to restore in the skeleton directory.
- Copy the sample file we need to our home directory.
Of course, it is best to have your dot files backed up, so that you don’t have to restore to the default and start from scratch every time you messed up with your dot files.
I hope you enjoyed this article and learned something new.
Keep learning and have fun!