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