Use of seq — Linux command

Use of seq (sequence) command in Linux. It will print the numbers in sequence as we requested.

Usage of the same is pretty easy and all we have to do is enter the option to print out / display the numbers

1.  Display of numbers from 1 to 5

$ seq [OPTION]
$ seq 5
-- It will print numbers starting from 1 to 5
1
2
3
4
5

2.  Display of numbers from 1 to 9 with an incremental difference of 2

$ seq 1 2 9
1
3
5
7
9

3. Change the display  format (with separator) of numbers from 50 to 100

$ seq -s,, 1 10
1,2,3,4,5,6,7,8,9,10

4.  Change the format as following

$ seq -f "%02g" 1 10
001
002
003
004
005
006
007
008
009
010

5. We can use ‘seq’ command with other tools also

$ expr seq -s " + " 111  121`
--The seperator between two numbers is "+" and will list all the numbers between
111 to 121 and will add of them
Total is 1276

$  touch seq -f "file%02g" 10 100
-- It will create the file names starting with file10 to file100
Output
file10 file19 file29 file39 file49 file59 file69 file79 file89 file99
file100 file20 file30 file40 file50 file60 file70 file80 file90
file11 file21 file31 file41 file51 file61 file71 file81 file91
file12 file22 file32 file42 file52 file62 file72 file82 file92
file13 file23 file33 file43 file53 file63 file73 file83 file93
file14 file24 file34 file44 file54 file64 file74 file84 file94
file15 file25 file35 file45 file55 file65 file75 file85 file95
file16 file26 file36 file46 file56 file66 file76 file86 file96
file17 file27 file37 file47 file57 file67 file77 file87 file97
file18 file28 file38 file48 file58 file68 file78 file88 file98
 

AWK – Linux text processor

Summary:

AWK –  is the text processor and original from AT&T and it is excellent tool for processing rows and columns and it is always quit easy to report

Structure of the program is as follows,

#awk ‘{print}’ filename ===> “AWK”  is the command followed by pattern and action on the file  For Example

#awk ‘{print}’ /etc/passwd ==> It will print all the characters from the file /etc/passwd

#awk ‘/[0-9]/ {print }’ /etc/passwd ==> It will print all the numerical characters from the file /etc/passwd

 

 

Environment Path in Ubuntu

Summary:

If we would like to add our additional path to your our current profile and not for all other users in a Ubuntu Machine, then we need to put it at the end of the ~/.profile

For example (Assume that we are adding variable path in /opt directory)

PATH="/opt/varpath:$PATH"
PATH="$PATH:/opt/varpath"

it will have the highest priority and executables in that location will override all others. If you add your path on the right, it will have the lowest priority and executables from the other locations will be preferred.

sudo cp /etc/environment /etc/environment.bak
sudo nano /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
Also Refer the link: https://askubuntu.com/questions/500775/permanent-path-variable

GREP – Global Regular Expression Print

</head

GREP – Global Regular Expression Print

The name grep comes from a command used in one of the early Unix editors. The command searched for a regular expression, and printed it out

  1. Search particular word in the file provided

     grep

grep

2.  Search for lower and upper case ( Not case sensitive)

     grep -i  or  –ignore-case

grep1

3.  Printing lines that do not match required pattern

  grep -v  or –ignore-case

grep2

4.  Printing recursively a pattern throughout the directory

 grep -r –recursive

grep3

5.  Obtain patterns from FILE, one per line

    grep -f note  or   grep –file=note

grep4.png

6.   Use PATTERN as the pattern

grep -e “pattern” –regexp “pattern”

grep5

7.    show the line numbers in the output

grep -n . note ## show the line number in s every line in file ‘note’

grep6.png

8.  Select only those matches that exactly match the whole line

grep -x  –line-regexp

grep7

9.  Select only those matches that exactly match the whole word

grep -w  –word-regexp

grep8

10.  print a count of matching lines for each input file

grep -c . note | grep –count . note

grep9.png

11. colors are defined by the environment variable GREP_COLORS.

grep -i suresh –color=auto

grep10

12. Select files without match and with match

grep -L, –files-without-match  &&  grep -l –files-with-match

grep11.png

13.  Do not Show the output — suppress the output

grep -q -l suresh note |  grep –quiet -l suresh note

grep12

14.  Suppress error messages about nonexistent or unreadable files

grep -s –no-messages

grep13.png

15.  With file to display

grep -H 

grep14.png

16.  –no-filename

grep -h

grep15.png

——————————————————— $$$$————————————————————————

find – search for files in a directory hierarchy

Find command is used to find the files in the default working directory or in the specified directory.

 

1. To find the the files or directories in the /tmp directory which are accessed in last 2 minutes

# find  /tmp -amin 2

2. To find the the files or directories in the /tmp directory which are  created in last 2 minutes

# find /tmp -cmin 2

3. To find the the files or directories in the /tmp directory which are modified in last 2 minutes

# find /tmp -mmin 2

4. To find the the files or directories in the /tmp directory which are accessed in last 2 days

# find /tmp -atime +2

5. To find the the files or directories in the /tmp directory which are created in last 2 days

# find /tmp -ctime +2

6. To find the the files or directories in the /tmp directory which are modified in last 2 days

# find /tmp -mtime +2

7. To find the the files or directories in the /tmp directory where file’s status was last changed more recently than file  was  modified.

# find -cnewer /tmp/

8. To find the the empty files or directories in the /tmp directory

# find /tmp -empty

9. To inverse the previous mentioned command

# find /tmp -ctime 2 -false

10. To find the the executable files or directories in the /tmp directory

# find /tmp -executable

11. To find the files or directories in the /tmp directory having  specified file system

# find /tmp -fstype ext4

12. To find the files or directories created by specified UID of the user name)

# find /tmp -uid 0
# find /tmp -uid 1001

13. To find the files or directories created by specified the user name

# find /tmp -user suresh1

14. To find the files or directories created by specified group’s users

# find /tmp -group root

15. To find the files or directories created by specified group’s GID

# find /tmp -gid 1001

16. To find the files or directories & match is case insensitive

# find /tmp -iname abC
/tmp/abc
# find /tmp -iname ABc
/tmp/abc

17. To find the  soft links of files or directories & match is case insensitive

# find /tmp -ilname ABC

18. To find the  files or directories by using inode number

# find /tmp -inum 17882759

19. To find the  files or directories by name

# find /tmp -name filename

20.  To find the file or directories having more than 2 symbolic links

# find . -links 2

21 . No group corresponds to file’s numeric group ID

# find . -nogroup

22.  No user corresponds to file’s numeric user ID.

# find . -nouser

23. File’s permission bits are exactly mode (octal or symbolic)

# find . -perm g=w
# find . -perm /220
# find . -perm /u+w,g+w
# find . -perm /u=w,g=w

24. All of the permission bits mode are set for the file.

# find . -perm a+rwx
# find . -perm -444 -perm /222 ! -perm /111

25. Matches files which are readable

# find . -readable

26. Find and Delete Files 

# find . -name "*.bak" -delete

27.  Find file based on size

  • `b’ for 512-byte blocks (this is the default if no suffix is used)
  • `c’ for bytes
  • `w’ for two-byte words
  • `k’ for Kilobytes (units of 1024 bytes)
  • `M’ for Megabytes (units of 1048576 bytes)
  • `G’ for Gigabytes (units of 1073741824 bytes
# find . -size 2b
# find . -size 3c
# find . -size 2w
# find . -size 4k
# find . -size 5M
# find . -size 2G

28.  Find the files based on their type

  1. b block (buffered) special
  2. c character (unbuffered) special
  3. d directory
  4. p named pipe (FIFO)
  5. f regular file
  6. l symbolic link;
  7. s socket
# find . -type b
# find . -type f

29.  File was last accessed n days

# find . -used 1

30.  Matches files which are writable. 

# find . -writable

31.  Find the files and execute cmd following with

# find /tmp -type f -exec ls -l {} \;

32. If the file names `/dev/stdout’ and `/dev/stderr’ are handled

# find . -fprint abc1
# find . -fprint0 abc

33. Find the files in   /tmp folder by name core and delete action to be taken

# find /tmp -name temp1 -type f -print | xargs /bin/rm -f

34. Find the files in   /home directory of the user logged in, by name “.bashrc”

# find ~ -name .bashrc
# find $HOME -name .bash_profile

_____________________________________________ _____________________________________________

Linux: groupmod

After creating the groups, we can modify by following command: groupmod <<groupname>>

  • Modify the group id (gid)
$ sudo groupmod -g 1003 group3
$ grep -i group3 /etc/group
  group3:x:1013:
  • Modify the group name
$ sudo groupmod -n new_group_name group3
$ tail -1 /etc/group
  new_group_name:x:1013:
  • Set the password for a group using crypt
 $ sudo groupmod -p $(openssl passwd -crypt myPassword) group2
 $ grep group2 /etc/gshadow
   group2:45kGUVUKpqfaMY::

Linux: Creating Groups

  • Check the which group of the user logged in  and other users associated with
   $ groups
     buser test cephuser
  •  Create the group along with  GID
    $ sudo groupadd -g 2002 group1
  •  Create group along with random GID

       It overrides etc/login.defs defaults (GID_MIN, GID_MAX)

   $ sudo groupadd -K GID_MIN=800 -K GID_MAX=1200 group3
  • Create password protected group # It is visible to others, hence not recommended, later you can apply password to protect the group already created.

# To check the password enabled, run $ cat /etc/gshadow

   $ sudo groupadd -p P@ssw0rd group4
  • Create system  group:  Group will be created with system GID value
   $ sudo groupadd -r group4

Linux Classes: usermod

For creating users, please refer document : useradd command (centos / Redhat )

  •  Add existing user to multiple groups:
  $ sudo usermod -a -G 1001 1002 1003 user1
  •  Update the comment column of user: user1 details
   $ sudo usermod -c "Guest User1 of RHEL System" user1
  • Update the home directory of the user: user1
  $ sudo usermod -d /filesystem user1
  • Update the expiry date of password of user: user1  (yyyy-mm-dd format)
  $ sudo usermod -e 2018-08-30 user1
  • Change the name of the user / change the login  name of the user
  $ sudo usermod -l updated_user2 user1
  • To lock the user: user1
  $ sudo usermod -L user1

Above commands, experimented in CentOS7.5 Operating system. Same commands will work in RHEL also

Linux : Creating Users and Groups

Apart from root user, while installing RHEL or CentOS Linux operating system, we can create the users and set the passwords as well. Remember following commands to create and modify both users and groups.

Following files will be modified while executing above mentioned commands

  1. /etc/passwd (User account information)
  2. /etc/shadow (Secure user account information)
  3. /etc/group (Group account information)
  4. /etc/gshadow (Secure group account information)
  5. /etc/default/useradd (Default values for account creation)
  6. /etc/skel/ (Directory containing default files)
  7. /etc/login.defs (Shadow password suite configuration)

Firstly,  we will see how the command useradd will function, it is a part of package –  shadow-utils.x86_64  . To know the options used along with useradd command, just run following command

  1. man useradd
USERADD(8) System Management Commands USERADD(8)

NAME
useradd - create a new user or update default new user information
SYNOPSIS
useradd [options] LOGIN
useradd -D
useradd -D [options]
DESCRIPTION
When invoked without the -D option, the useradd command creates a new
user account using the values specified on the command line plus the
default values from the system. Depending on command line options, the
useradd command will update system files and may also create the new
user's home directory and copy initial files.

By default, a group will also be created for the new user (see -g, -N,
-U, and USERGROUPS_ENAB).

OPTIONS
The options which apply to the useradd command are:

-b, --base-dir BASE_DIR
The default base directory for the system if -dHOME_DIR is not
specified. BASE_DIR is concatenated with the account name to
define the home directory. The BASE_DIR must exist otherwise the
home directory cannot be created.

If this option is not specified, useradd will use the base
directory specified by the HOME variable in /etc/default/useradd,
or /home by default.

-c, --comment COMMENT
Any text string. It is generally a short description of the login,
and is currently used as the field for the user's full name.

-d, --home-dir HOME_DIR
The new user will be created using HOME_DIR as the value for the
user's login directory. The default is to append the LOGIN name to
BASE_DIR and use that as the login directory name.

-D, --defaults
See below, the subsection "Changing the default values".

-e, --expiredate EXPIRE_DATE
The date on which the user account will be disabled. The date is
specified in the format YYYY-MM-DD.

If not specified, useradd will use the default expiry date
specified by the EXPIRE variable in /etc/default/useradd, or an
empty string (no expiry) by default.

-f, --inactive INACTIVE
The number of days after a password expires until the account is
permanently disabled. A value of 0 disables the account as soon as
the password has expired, and a value of -1 disables the feature.

If not specified, useradd will use the default inactivity period
specified by the INACTIVE variable in /etc/default/useradd, or -1
by default.

-g, --gid GROUP
The group name or number of the user's initial login group. The
group name must exist. A group number must refer to an already
existing group.

If not specified, the behavior of useradd will depend on the
USERGROUPS_ENAB variable in /etc/login.defs. If this variable is
set to yes (or -U/--user-group is specified on the command line), a
group will be created for the user, with the same name as her
loginname. If the variable is set to no (or -N/--no-user-group is
specified on the command line), useradd will set the primary group
of the new user to the value specified by the GROUP variable in
/etc/default/useradd, or 100 by default.

-G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
A list of supplementary groups which the user is also a member of.
Each group is separated from the next by a comma, with no
intervening whitespace. The groups are subject to the same
restrictions as the group given with the -g option. The default is
for the user to belong only to the initial group.

-h, --help
Display help message and exit.

-k, --skel SKEL_DIR
The skeleton directory, which contains files and directories to be
copied in the user's home directory, when the home directory is
created by useradd.

This option is only valid if the -m (or --create-home) option is
specified.

If this option is not set, the skeleton directory is defined by the
SKEL variable in /etc/default/useradd or, by default, /etc/skel.

If possible, the ACLs and extended attributes are copied.

-K, --key KEY=VALUE
Overrides /etc/login.defs defaults (UID_MIN, UID_MAX, UMASK,
PASS_MAX_DAYS and others).

Example: -K PASS_MAX_DAYS=-1 can be used when creating system
account to turn off password ageing, even though system account has
no password at all. Multiple -K options can be specified, e.g.: -K
UID_MIN=100-K UID_MAX=499

-l, --no-log-init
Do not add the user to the lastlog and faillog databases.

By default, the user's entries in the lastlog and faillog databases
are resetted to avoid reusing the entry from a previously deleted
user.

-m, --create-home
Create the user's home directory if it does not exist. The files
and directories contained in the skeleton directory (which can be
defined with the -k option) will be copied to the home directory.

By default, if this option is not specified and CREATE_HOME is not
enabled, no home directories are created.

The directory where the user's home directory is created must exist
and have proper SELinux context and permissions. Otherwise the
user's home directory cannot be created or accessed.

-M, --no-create-home
Do not create the user's home directory, even if the system wide
setting from /etc/login.defs (CREATE_HOME) is set to yes.

-N, --no-user-group
Do not create a group with the same name as the user, but add the
user to the group specified by the -g option or by the GROUP
variable in /etc/default/useradd.

The default behavior (if the -g, -N, and -U options are not
specified) is defined by the USERGROUPS_ENAB variable in
/etc/login.defs.

-o, --non-unique
Allow the creation of a user account with a duplicate (non-unique)
UID.

This option is only valid in combination with the -u option.

-p, --password PASSWORD
The encrypted password, as returned by crypt(3). The default is to
disable the password.

Note: This option is not recommended because the password (or
encrypted password) will be visible by users listing the processes.

You should make sure the password respects the system's password
policy.

-r, --system
Create a system account.

System users will be created with no aging information in
/etc/shadow, and their numeric identifiers are chosen in the
SYS_UID_MIN-SYS_UID_MAX range, defined in /etc/login.defs, instead
of UID_MIN-UID_MAX (and their GID counterparts for the creation of
groups).

Note that useradd will not create a home directory for such an
user, regardless of the default setting in /etc/login.defs
(CREATE_HOME). You have to specify the -m options if you want a
home directory for a system account to be created.

-R, --root CHROOT_DIR
Apply changes in the CHROOT_DIR directory and use the configuration
files from the CHROOT_DIR directory.

-s, --shell SHELL
The name of the user's login shell. The default is to leave this
field blank, which causes the system to select the default login
shell specified by the SHELL variable in /etc/default/useradd, or
an empty string by default.

-u, --uid UID
The numerical value of the user's ID. This value must be unique,
unless the -o option is used. The value must be non-negative. The
default is to use the smallest ID value greater than or equal to
UID_MIN and greater than every other user.

See also the -r option and the UID_MAX description.

-U, --user-group
Create a group with the same name as the user, and add the user to
this group.

The default behavior (if the -g, -N, and -U options are not
specified) is defined by the USERGROUPS_ENAB variable in
/etc/login.defs.

-Z, --selinux-user SEUSER
The SELinux user for the user's login. The default is to leave this
field blank, which causes the system to select the default SELinux
user.

Changing the default values
When invoked with only the -D option, useradd will display the current
default values. When invoked with -D plus other options, useradd will
update the default values for the specified options. Valid
default-changing options are:

-b, --base-dir BASE_DIR
The path prefix for a new user's home directory. The user's name
will be affixed to the end of BASE_DIR to form the new user's home
directory name, if the -d option is not used when creating a new
account.

This option sets the HOME variable in /etc/default/useradd.

-e, --expiredate EXPIRE_DATE
The date on which the user account is disabled.

This option sets the EXPIRE variable in /etc/default/useradd.

-f, --inactive INACTIVE
The number of days after a password has expired before the account
will be disabled.

This option sets the INACTIVE variable in /etc/default/useradd.

-g, --gid GROUP
The group name or ID for a new user's initial group (when the
-N/--no-user-group is used or when the USERGROUPS_ENAB variable is
set to no in /etc/login.defs). The named group must exist, and a
numerical group ID must have an existing entry.

This option sets the GROUP variable in /etc/default/useradd.

-s, --shell SHELL
The name of a new user's login shell.

This option sets the SHELL variable in /etc/default/useradd.

NOTES
The system administrator is responsible for placing the default user
files in the /etc/skel/ directory (or any other skeleton directory
specified in /etc/default/useradd or on the command line).

CAVEATS
You may not add a user to a NIS or LDAP group. This must be performed
on the corresponding server.

Similarly, if the username already exists in an external user database
such as NIS or LDAP, useradd will deny the user account creation
request.

Usernames may only be up to 32 characters long.

CONFIGURATION
The following configuration variables in /etc/login.defs change the
behavior of this tool:

CREATE_HOME (boolean)
Indicate if a home directory should be created by default for new
users.

This setting does not apply to system users, and can be overridden
on the command line.

GID_MAX (number), GID_MIN (number)
Range of group IDs used for the creation of regular groups by
useradd, groupadd, or newusers.

The default value for GID_MIN (resp. GID_MAX) is 1000 (resp.
60000).

MAIL_DIR (string)
The mail spool directory. This is needed to manipulate the mailbox
when its corresponding user account is modified or deleted. If not
specified, a compile-time default is used.

MAIL_FILE (string)
Defines the location of the users mail spool files relatively to
their home directory.

The MAIL_DIR and MAIL_FILE variables are used by useradd, usermod, and
userdel to create, move, or delete the user's mail spool.

If MAIL_CHECK_ENAB is set to yes, they are also used to define the MAIL
environment variable.

MAX_MEMBERS_PER_GROUP (number)
Maximum members per group entry. When the maximum is reached, a new
group entry (line) is started in /etc/group (with the same name,
same password, and same GID).

The default value is 0, meaning that there are no limits in the
number of members in a group.

This feature (split group) permits to limit the length of lines in
the group file. This is useful to make sure that lines for NIS
groups are not larger than 1024 characters.

If you need to enforce such limit, you can use 25.

Note: split groups may not be supported by all tools (even in the
Shadow toolsuite). You should not use this variable unless you
really need it.

PASS_MAX_DAYS (number)
The maximum number of days a password may be used. If the password
is older than this, a password change will be forced. If not
specified, -1 will be assumed (which disables the restriction).

PASS_MIN_DAYS (number)
The minimum number of days allowed between password changes. Any
password changes attempted sooner than this will be rejected. If
not specified, -1 will be assumed (which disables the restriction).

PASS_WARN_AGE (number)
The number of days warning given before a password expires. A zero
means warning is given only upon the day of expiration, a negative
value means no warning is given. If not specified, no warning will
be provided.

SYS_GID_MAX (number), SYS_GID_MIN (number)
Range of group IDs used for the creation of system groups by
useradd, groupadd, or newusers.

The default value for SYS_GID_MIN (resp. SYS_GID_MAX) is 101
(resp. GID_MIN-1).

SYS_UID_MAX (number), SYS_UID_MIN (number)
Range of user IDs used for the creation of system users by useradd
or newusers.

The default value for SYS_UID_MIN (resp. SYS_UID_MAX) is 101
(resp. UID_MIN-1).

UID_MAX (number), UID_MIN (number)
Range of user IDs used for the creation of regular users by useradd
or newusers.

The default value for UID_MIN (resp. UID_MAX) is 1000 (resp.
60000).

UMASK (number)
The file mode creation mask is initialized to this value. If not
specified, the mask will be initialized to 022.

useradd and newusers use this mask to set the mode of the home
directory they create

It is also used by login to define users' initial umask. Note that
this mask can be overridden by the user's GECOS line (if
QUOTAS_ENAB is set) or by the specification of a limit with the K
identifier in limits(5).

USERGROUPS_ENAB (boolean)
Enable setting of the umask group bits to be the same as owner bits
(examples: 022 -> 002, 077 -> 007) for non-root users, if the uid
is the same as gid, and username is the same as the primary group
name.

If set to yes, userdel will remove the user's group if it contains
no more members, and useradd will create by default a group with
the name of the user.

Options:

  1.    If  No group is required, while creating a user
      $ sudo useradd testuser4 -L
      $ grep testuser4 /etc/group
        
      $ grep testuser4 /etc/passwd     

useradd_with_l

2.  Create user and specify a base home directory : b, –base-dir BASE_DIR

     Create a base home directory, for demonstration, creating as /house

      $ sudo mkdir /house
      $ sudo useradd testuser5 -b /house
      $ ls /house
        testuser5

3.  Create a user and specify a base home directory : b, –base-dir BASE_DIR

          The new user will be created using HOME_DIR as the value for the
user’s login directory. The default is to append the LOGIN name to
BASE_DIR and use that as the login directory name.

$ sudo useradd testuser -d /house/testuser_home
$ ls /house
  testuser_home

4. Create a user and set expiry date to change the login password

$ sudo useradd testuser -e 2018-09-15
$ chage -l testuser
  last password change                           : Sept 15, 2018
  Password expires                               : never
  Password inactive                              : never
  Account expires                                : never
  Minimum number of days between password change : 0
  Maximum number of days between password change : 99999
  Number of days of warning before password expires : 7

5. Create a user and set the number of days after a password expires until the account is permanently disabled. A value of 0 disables the account as soon as
the password has expired, and a value of -1 disables the feature

$ sudo useradd testuser -f 30
$ tail -1 /etc/shadow
  testuser:!!:17789:0:99999:7:100::

6.  Create a user along with specified group ID (GID)

$ sudo useradd webclient -g 1001
$ tail -1 /etc/passwd
  webclient:x:1043:1001::/home/webclient:/bin/bash

7.  Create a user and join multiple supplementary groups

$ sudo useradd webclient -G 1001,1002,1003,1004,1005
$ grep -i 1001 /etc/group
smbuser:x:1001:webclient

8.  -k, –skel SKEL_DIR : The skeleton directory, which contains files and directories to be copied in the user’s home directory, when the home directory is created by useradd.

$ mkdir /scale
$ cp .[^.]* /etc/skel /scale
$ cd /scale
$ mkdir temp1 temp2 temp3 temp4 
$ sudo useradd webclient -k /scale -m
$ cd /home/webclient
$ls -la
.bash_logout .bash_profile .bashrc .mozilla temp1 temp2 temp3 temp4

9.  -m –create-home: Create the user’s home directory if it does not exist.

$ sudo useradd -m testuser8
$ ls /home/
  testuser8

10. -M, –no-create-home
Do not create the user’s home directory, even if the system wide
setting from /etc/login.defs (CREATE_HOME) is set to yes.

$ sudo useradd -M testuser
$ cd /home
$ ls -la
. ..

11.  N, –no-user-group
Do not create a group with the same name as the user, but add the
user to the group specified by the -g option or by the GROUP
variable in /etc/default/useradd.

$ sudo useradd testuser -o -u 1000
$ cat /etc/passwd | grep 1000
  Administrator:x:1000:1000:administrator:/home/administrator:/bin/bash
  testuser:x:1000:1004::/home/testuser:/bin/bash

12. -p, –password PASSWORD
The encrypted password, as returned by crypt(3). The default is to
disable the password. and it’s not recommended because the password (or
encrypted password) will be visible by users listing the processes

$ sudo useradd testuser -p P@ssw0rd
$ tail -1 /etc/shadow
  testuser1:P@ssw0rd:17789:0:99999:7::
~~ Password is visible by users and hence it is supported

13.  -r, –system:  Create a system account.

$ sudo useradd testuser1 -r
$ tail -1 /etc/passwd
  testuser2:x:988:982::/home/testuser2:/bin/bash

14.  -s, –shell SHELL

$ useradd user1 -s /sbin/nologin
$ grep user1 /etc/passwd
  user1:x:1005:1005::/home/user1:/sbin/nologin
$ su user1
  This account not available

15. -u  –uid UID

$ useradd user1 -u 1050
$ grep -i user1 /etc/passwd
 user1:x:1050:1050::/home/user1:/bin/bash

More details about usermod, please check this article: https://winlinuxtips.wordpress.com/2018/09/15/linux-classes-usermod/

Using “dd” command in Linux

What is dd command ?

dd is nothing but Data Duplicator and useful for copying and converting the data
Significance of dd is , we can copy entire MBR (Master Boot Record) and can also be used
preparing boot images

Syntax of dd command:

dd if=<source> of=<destination> [Options]

if=input-file, of=output-file

I. If we would like to copy entire disk, we can do achieve by following command

First mount another disk, while cloning the the disk, we can compress the file using  gzip utility

#mount /dev/sdb1 /mnt
#cd /mnt
#dd if=/dev/sda conv=sync,noerror bs=64k | gzip -c > complete.gz
#ls
complete.gz
# du -h complete.gz
5.2G

II. Copy only /home directory

#dd if=/home | gzip -c > home.gz

III. Creating image file

# dd if=/dev/sda | gzip -c >/tmp/sdadisk.img.gz

Later, we can restore from image, we have created.

# gzip -dc /tmp/sdadisk.img.gz | dd of=/dev/vda