0% found this document useful (0 votes)
14 views17 pages

Basic User Command

The document provides an overview of Linux commands, particularly focusing on directory management commands such as 'pwd' for displaying the current directory, 'mkdir' for creating directories, and variations like 'mkdir -p' for creating parent directories without errors. It also explains user and group management commands, including adding users to groups and the distinction between primary and secondary groups. Additionally, it covers basic user commands like 'whoami', 'who', and 'uptime' for system information.

Uploaded by

laita nikam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views17 pages

Basic User Command

The document provides an overview of Linux commands, particularly focusing on directory management commands such as 'pwd' for displaying the current directory, 'mkdir' for creating directories, and variations like 'mkdir -p' for creating parent directories without errors. It also explains user and group management commands, including adding users to groups and the distinction between primary and secondary groups. Additionally, it covers basic user commands like 'whoami', 'who', and 'uptime' for system information.

Uploaded by

laita nikam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Linux Directories

What are Commands


A command is an instruction given to our computer by us to do whatever we want. In Mac OS, and Linux it is
called terminal, whereas, in windows it is called command prompt. Commands are always case sensitive.
Commands are executed by typing in at the command line followed by pressing enter key.
This command further passes to the shell which reads the command and execute it. Shell is a method for the
user to interact with the system. Default shell in Linux is called bash (Bourne-Again Shell).

There are two types of shell commands:


•Built-in shell commands: They are part of a shell. Each shell has some built in commands.
•External/Linux commands: Each external command is a separate executable program written in
C or other programming languages.

Linux pwd Command


Linux pwd (print working directory) command displays your location currently you are working on. It
will give the whole path starting from the root ending to the directory.
Syntax:
1.pwd

Let's see an example of pwd command.


Open your terminal and type pwd, press enter key. You can see your directory path
Linux mkdir | Linux Create Directory
Now let's learn how to create your own directory with the help of command prompt.
The mkdir stands for 'make directory'. With the help of mkdir command, you can create a new directory wherever you want in
your system. Just type "mkdir <dir name> , in place of <dir name> type the name of new directory, you want to create and
then press enter.

Syntax: mkdir <dirname>

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.

To make multiple directories


Syntax:
1.mkdir <dirname1> <dirname2> <dirname3>

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.

mkdir -pv/ mkdir -vp


Both the commands 'mkdir -pv' and 'mkdir -vp' are same. By combining -p you can create a long
list files together like "office/client/raj/date/day"with a printed message for each file.
Linux Directories mkdir -m=MODE
With the help of this command, you can access the permission on the directory you are creating.
Access means to give the authority to read(r), write(w), and execute(x). You can access the
permission in different ways to your directory.
•For full access, command will be

1. "mkdir -m=rwx <file>"


2. or
3."mkdir -m 777 <file>".
For read and write, command will be
4."mkdir -m=rw <file>"

•For read only/ write only/ eecute only, command will be

1."mkdir -m=r <file>"/ "mkdir -m=w <file>"/ "mkdir -m=x <file>"/

Here, in place of you have to write the name of your file you want to create.
Basic user command of Linux
whoami

It tells you about the system's username.

Syntax:
1.whoami

Look at the above snapshot, 'sssit' is our system's username.

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.

From the left, it shows,

• currrent system time


• duration for which system has been running (system is running since 18 minutes)
• number of users logged in (2 users are logged in)
• system load average CPU load for past 1, 5 and 15 minutes.
Here, system load averages are the processes which are either in runnable or in uninterruptable state.
A runnable process may be either a running one using CPU or waiting to use CPU. An uninterruptable
process is waiting for some I/O access.
Linux su Commands
The su command allows you to run a shell as another user.
Syntax: su <username>

Example: su jtp (create user )

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

The groupadd command creates or add a group in our system.


Syntax:
1.groupadd <groupName>

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.

Types of Linux Groups


In Linux-based system, there are two types of groups, which are:
•Primary group
•Secondary or supplementary group
Primary group: When we create a file through a specific user account, by default, the filegroup is
set to the user's primary group. It will provide the same name as the file user group as the user
account name. The primary group stores the user information in /etc/passwd file.

Secondary or supplementary group: The main motive to create a secondary group

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:

sudo groupadd jtpGroup

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:

sudo useradd user1


sudo useradd user2

The above command will add the two users called user1 and user2. Consider the below output:

To add the user to a group, execute the following command:

sudo usermod -a -G jtpGroup user1


The above command will add the user1 to jtpGroup. 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.

You might also like