Thursday, 31 August 2017

Unix Shell Scripting Tutorial - page 5

Unix Shell Scripting Tutorial - page 5

Question: What are the directory structure of unix?
  1. /: This is the root directory which should contain only the directories.
  2. /bin: Executable files are located here.
  3. /dev: Device drivers
  4. /etc: configuration files, valid user lists, groups, ethernet and hosts etc
  5. /lib: shared library files and sometimes other kernel-related files.
  6. /boot: files for booting the system.
  7. /home: home directory for users and other accounts
  8. /mnt: Used to mount other temporary file systems like CD/pendrive
  9. /proc: Contains all processes marked as a file by process number.
  10. /tmp: Holds temporary files used between system boots.
  11. /user: Used for miscellaneous purposes.
  12. /var: Typically contains log and print files.
  13. /sbin: Contains binary (executable) files.
  14. /kernel: kernel files



Question: How to create a new Group?
groupadd mynewgroup



Question: How to modify group name?
groupmod -n new_modified_group_name old_group_name



Question: How to delete group?
groupdel new_modified_group_name



Question: How to add a existing user to a group?
usermod -a -G mynewgroup username

-G Its for secondary group.
-g Its for primary group.


Question: How to change a User's Primary Group?
usermod -g groupname username  



Question: How to list groups of loggined user?
groups



Question: How to list groups of other user?
groups username



Question: How to Create a New User and Assign a Group?
useradd -G examplegroup username



Question: How to assign a user multiple groups?
usermod -a -G group1,group2,group3 username



Wednesday, 30 August 2017

Unix Shell Scripting Tutorial - page 4

Unix Shell Scripting Tutorial - page 4

Question: What are man pages?
Unix's version of Help files are called man pages.


Question: Can we perform regular expression in unix?
Yes, We can do.
We can do using sed.
Full form of SED is stream editor.
For Example(s)
cat /etc/passwd | sed -n '1,3p'

REGEX_DATE='^\d{2}[/-]\d{2}[/-]\d{4}$'
echo "$1" | grep -P -q $REGEX_DATE
echo $?



Question: What are character meaning in regular expression?
  1. ^a: Start with a
  2. a$: End with a
  3. .: Match any single character.
  4. *: Match zero OR more occurances.
  5. [abcd]: Any character from a,b,c and.
  6. \: Skip the effects of special character.
  7. [a-z]: Match a-z any character.
  8. [a-z0-9]: March a-z OR 0-9 any character.
  9. [[:alnum:]]: Alphanumeric [a-z A-Z 0-9]
  10. [[:alpha:]]: Alphabetic [a-z A-Z]
  11. [[:blank:]]: Blank characters (spaces or tabs)
  12. [[:cntrl:]]: Control characters
  13. [[:digit:]]: Numbers [0-9]
  14. [[:graph:]]: Any visible characters (excludes whitespace)
  15. [[:lower:]]: Lowercase letters [a-z]
  16. [[:print:]]: Printable characters (non-control characters)
  17. [[:space:]]: Whitespace
  18. [[:punct:]]: Punctuation characters
  19. [[:upper:]]: Uppercase letters [A-Z]
  20. [[:xdigit:]]: Hex digits [0-9 a-f A-F]



Question: Can we execute multiple command in single statement?
Yes, We can execute multiple commands in single statement.
For Example
sed -e 'command1' -e 'command2'  -e 'command3'  -e 'command4' 



Question: What are the most comman commands?
  1. cat filename: Displays a filename.
  2. cd dirname: Moves you to the identified directory.
  3. cp file1 file2: Copies one file/directory to the specified location.
  4. file filename: Identifies the file type
  5. head filename: Shows the beginning of a file
  6. less filename:
  7. ls dirname: Display the content of directory.
  8. mv file1 file2: Rename a file
  9. tail filename: Display the end of file
  10. touch filename: Create a blank file.
  11. whereis filename: Display the location of file
  12. :
Question: What is use of df command?
Its used to display the disk space usages.
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/xvda1      20509288 15036052   5372988  74% /
devtmpfs         2015996       64   2015932   1% /dev
tmpfs            2024996        0   2024996   0% /dev/shm
/dev/xvdf      103081248 44579524  53258844  46% /var/lib/mysql
/dev/xvdg      103081248 89393356   8445012  92% /mnt



Question: What is use of du command?
Its used to display how much space is taking by each directory.


Question: What mount command used for?
mount point is a directory to access your data (files/folders) which is stored in your disks.


Question: What unmount command used for?
To unmount (remove) the file system from your system.
For Example
umount /dev/cdrom



Question: What are the different type of users in unix?
  1. Root User: It is super admin who have all the access and no need to any further permission.
  2. System accounts: It have access of system-specific components like mail accounts and the sshd accounts.
  3. User accounts: User accounts provide interactive access to the system. Users are typically assigned to these accounts and usually have limited access files and directories.



Question: What are the main administrator files?
  1. /etc/passwd: Keeps the user account and password info.
  2. /etc/shadow: Holds the encrypted password.
  3. /etc/group: It have group information.
  4. /etc/gshadow: secure group account information