Basic User Command
Basic User Command
In above example, I am in /home/sssit directory. I have made a directory 'created' by passing command "mkdir created".
Now if i'll try to create a new file with the same file name 'created' that technically already exists, I'll get an error message.
You can also create multiple directories simultaneously. Look the example above, we have created multiple directories 'file1 file2
file3' .
Linux Directories mkdir -p
With the help of mkdir -p command you can create sub-directories of a directory. It will create parent
directory first, if it doesn't exist. But if it already exists, then it will not print an error message and will
move further to create sub-directories.
This command is most helpful in the case when you don't know whether a directory alredy exists or
not. For instance, in the above screenshot I wanted to create a 'docu' in 'created'. As you know, we
already have directory 'created'. Hence, without showing an error it will create 'docu'. You can see
the 'docu' directory above.
Now in the later part of the image if you'll see, I have created a directory 'envelope' with its sub-
directory 'letter'. As directory 'envelope' doesn't exists, it will first create 'envelope' and then its sub-
directory 'letter' without printing any error.
Hence this command is very useful to create a long file like "office/client/raj/date". With mkdir
command you have to create every file one by one. But mkdir -p command will create it at once.
Linux Directories mkdir -v
'mkdir -v' command will print a message with every new file created
In above example, I have created 'file1 file2 file3' and you can see the message for every
individual file.
If files already exist then it will give an error message as shown below.
Here, in place of you have to write the name of your file you want to create.
Basic user command of Linux
whoami
Syntax:
1.whoami
who
The who command gives the information about the users logged on to the system
Syntax:
2.who
who am i
This command displays the information about the current user only .
Syntax:
1.who am i
Look at the above snapshot, in our system current logged in user is sssit.
w
This command tells about the users who are logged in and what are they doing.
Syntax:
1. w
id
This command tells about your user id, primary group id, and a list of groups that belongs to you.
Linux uptime
The uptime command tells us how long a system has been running.
Syntax:
1.uptime
Look at the above snapshot, command "uptime" displays output in one line.
su to root
You can change the user to root when you know the root password.
Syntax: su root
su as root
The root user can become any existing user without knowing that user's password. Otherwise,
password is needed.
Example:
su - sssit
Linux Groups
Users can be listed in different groups. Group allow us to set permission on the group level instead of
setting the permission on individual level.
Every Linux distribution have a graphical tool to manage groups. Groups can be managed by
graphical tools, command line tools and by vi or vigr depending upon the user's experience. Only
experienced users should use vi or vigr to manage groups, since it will do proper locking or changes
in the file.
Groupadd
Look at the above snapshot, groups php, java, android and spring are created with groupadd
command.
Group File
The /etc/group file defines the group membership. A user can be a member of more than one group.
Syntax:
2./etc/group
gruopdel
The command groupdel will delete a group permanently from the system.
Syntax:
1.groupdel <group>
Example:
2.groupdel sql
Look at the above snapshot, group sql is deleted from the system.
Group File
The /etc/group file defines the group membership. A user can be a member of more than one group.
Syntax:
1./etc/group
Look at the above snapshot, first column indicates group name, second is the group's encrypted
password which may remain empty also, third is group identification (GID) and fourth is the list of
members. Fourth list is empty as these groups do not have members.
Groups
The group command tells about the group where current user belongs to.
Syntax:
2.groups
Linux Add User to Group
Linux allows us to add users to a specific user group. A user account can be added to more than one
group. For example, the users that have sudo rights can access the sudo commands to gain related
permission. Moreover, we can configure the file permission and other rights to a group.
Adding a user to a group is a straight forward process, all we need to execute the appropriate
command. We will walk through all the scenarios related to user and group, such as how to add,
delete, remove users to a group. Moreover, we will also learn how to list groups. First, understand
the Linux groups:
Linux Groups
Linux groups are the community of the users that have the right to administrate and organize the
users and file permission in a Linux system. The main motive of creating a group is to define the set
of permissions such as read and write permission or allowing the shared resources of groups.
is to allow the specific permission to limited users. For example, if we want to add any user to the
sudo group, the added user will inherit the sudo rights, and be able to run the sudo commands. If we
add a user to the docker group, then it will inherit the properties of the docker group and be able to
run the docker commands.
A user can be added to precisely one primary group. It is not necessary to add a user to a secondary
group, so a user can be added to zero or more secondary groups.
Add a Group
To create a new user group on a Linux system, execute the groupadd command, followed by the
group name. You will need the sudo access to gain the elevated permissions. Execute the command
as follows:
The above command will ask for the system administrative password, type the password. Consider
the below output:
How to add a user to a Group
Adding users to a group is a straight forward process. We can add users to a group by
using usermod command. To add a user to a group, execute this command, followed by the group
name and user name. The group name is the name of a group in which you want to add a particular
user.\
let's create two users, user1 and user2, execute the command as follows:
The above command will add the two users called user1 and user2. Consider the below output:
The -a option used to append the group; it is recommended to use this option when adding a new user
to a group. If you do not use the -a option, the user will be removed from any group not specified after -
G option.
If the usermod command executes successfully, it will not display any output, but in case of failure, it
will post warning messages such as user or group does not exist.