Regex Assignment Day-3
Q.1 Create a folder /dummy/newfolder using the single command inside the Desktop
- assume both the folders are not present
mkdir -p Destop/dummy/newfolder
Q.2 You need to create the folder in the particular pattern as emp, emp2, emp3 .... till. emp100 [only with single line of code]
- Take its backup to the another folder inside the desktop folder
cd Desktop
mkdir emp{1..100}
cp -R emp{1..100} dummy
Q.3 Search for any file having:
{ am } any file with am in the middle of the filename
- search for any file & folder with second last word as {s} & starting words as {t}
- Search for any file that can start from character such as {A-Z or a..z, 0-9 }
- Find out any files inside the Desktop location created by the cloudera user.
ls *am*
ls t*s?
ls [A-Za-z0-9]*
find home/cloudera/Desktop -user cloudera
Q.4 How to create user with any name
- Create user with userid 11100
- Create a user with home-directory inside /home
- Creating a user and giving comment -> -c option
sudo useradd deepali
sudo passswd deepali27
New password:
Retype new password:
passwd: all authentication tokens updated succesfully.
sudo useradd -u 11100 user1
id -u user1
11100
sudo useradd -m user2
ls -la /home
sudo useradd -m -d /home/home user3
ls -la /home
sudo useradd -c "Hello there" usernew
grep usernew /etc/passwd
/*Comment will be displayed in the ouput*/
Q.5: What are group, primary & secondary group?
Group - A user- group can contain multiple users. All users belonging to a group will have the same Linux group permissions access to the file.
Primary group – Specifies a group that the operating system assigns to files that are created by the user. Each user must belong to a primary group.
Secondary groups – Specifies one or more groups to which a user also belongs. Users can belong to up to 15 secondary groups.
Q.6 Permission in Linux, values for each permission
Permissions:
Every file and directory in your UNIX/Linux system has following 3 permissions defined for all the 3 owners discussed above.
Read: This permission give you the authority to open and read a file. Read permission on a directory gives you the ability to lists its content.
Write: The write permission gives you the authority to modify the contents of a file. The write permission on a directory gives you the authority to add, remove and rename files stored in the directory.
Execute: In Windows, an executable program usually has an extension ".exe" and which you can easily run. In Unix/Linux, you cannot run a program unless the execute permission is set. If the execute permission is not set, you might still be able to see/modify the program code(provided read & write permissions are set), but not run it.
The characters are pretty easy to remember.
r = read permission
w = write permission
x = execute permission
- = no permission
-rw-rw-r--
The first part of the code is 'rw-'. This suggests that the owner 'Home' can:
File Permissions in Linux/Unix
Read the file
Write or edit the file
He cannot execute the file since the execute bit is set to '-'.
The second part is 'rw-'. It for the user group 'Home' and group-members can:
Read the file
Write or edit the file
The third part is for the world which means any user. It says 'r--'. This means the user can only:
Read the file