Creating users, files,and directories by Linux commands

Day 3

Uptill now you have learn about how to give permission to any files for users.I hope you have get that how to give ,change permissions to any files.So let move towards new point that is creating users and files …..

We have seen that Linux is powerful operating system for mutltiuser. So we need to create and delete different users as they add to any organisation.The organization give that user username and password.By using it the user can easily login to Linux machine and do his work.

Creating users ( adding and removing ) :

We used useradd command to add new user. Only the root user has permission to create users because he is super user of Linux machine. The root user is created when we install the Linux OS on system.So he is responsible to handle everything in the system.

For adding the user we have syntax as follows

Command : useradd username

Example : useradd harry

If want to add user into a group then first we need to create group by groupadd command.To add a user into a group then follow steps given below,

Step 1: create a user and give a password to user.

# useradd username

#passwd username

Step 2: Create a group using groupadd command or you can also add a user into existing group.

Command : #groupadd groupname

Example : #groupadd TechLinux

Step 3: add user into that group,we used -G option for group.The command as follows.

#useradd -G groupname username

E.g.#useradd -G TechLinux harry

That’s it , these are very simple steps to add user into a group.

Creating Files by commands

  • Using touch command

We have list of commands but we can used most commonly used commands .So for creating files we used touch,cat commands. The syntax is as follows….

#touch filename

E.g.# touch myfile

We can create a multiple files by touch command.The syntax as shown below

#touch filename1 filename2

#touch myfile1 myfile2

There is another way to create multiple files the command is shown below,

# touch filename { numbers..}

For example we want to create a list files into /home /harry/data directory the command for this is

# touch /home/harry/data/file{1..10}

It will create file1,file2,…….,file10 files into data directory. We can give absolute path , relative path. I will explain this concept in next post or later.

  • Using cat command

We can also create file by using cat command but different between these two commands is cat command also show the contents of files on command line.But only we can display text files , executable files like ,”.c ” ,”.java”,”.py” programming files will display junk . Following command show creating files using cat

On command prompt just type the cat command ,followed by the >(the right chevron) character and the filename

# cat > myfile

When we press enter the command line will wait for user input. After giving input or putting lines ,just press [ctrl+d] to end the input system and save the file . We can also used this command for concatenation.

Rules for Naming filename :

We have some rules to create files like how long the file name, character,numbers included in file name.So Following are some general rules for naming files

  1. 255 characters are allowed,you can used Upper case or lower case
  2. File name in Linux are case sensitive like Beta.c, BETA.c, beta.c are three different files.
  3. We can used special symbols like, #,@,$,¢,£,€ but they are very hard to used.
  4. File name contains any character except root directory because it is reserved as seperater between files and directories.That is we cannot used null character.
  5. A file name should be unique in one directory means it will not be same directory with same filename. For example, We have directory /home/harry ,we cannot create a file data into data directory.

Creating directories :

We can create directories into Linux files system.A directory is folder in which contains a set of files. For creating directory we used mkdir command

# mkdir [ directory name ]

# mkdir mydirectory

We can also create directory under directories by – d option,the command as shown below

# mkdir – d [parent directory/child directory]

# mkdir – d /data/mydata

Here for we again used absolute path and relative path. We will discuss following..

Absolute , Relative Pathname

Absolute pathname:

The pathname starts with ‘/’ which represents root directory ,the file lacation must be with respect to / called absolute pathname

The pathname starts with root directory and end as respected directory.For example we have script directory in user harry’s home’s directory the pathname will be as shown below

/home/harry/script

It is very difficult to remember the absolute pathname.But still sometimes we need to used absolute pathname.

Relative path

Relative pathname is used a rudimentary form of relative pathnames .Either it uses the current or parent directory as reference ,specify path relative to it.

For example we don’t know where the mydata is located then instead of providing absolute path , we used realtive path to find path of that directory.

In next post, we will learn about Deleting, Copying, Moving, Renaming Files and Sorting Data

Leave a comment