Awesome to work in CLI [Not for Masters but for Beginners] – Part III

Hope my last two post gave some basics of Linux/CLI for your knowledge. From Part III I m l trying to demonstrate some file operations which is very common in CLI, stuff like making new directories/files, coping, moving and removing . Lets hit it from level 0. So fire up your Terminal/Konsole & start working with me.

Lets start by making a new directory named D1.

 

Making a New Directory

Making a New Directory

 

You must be familiar with ‘mkdir’ because we have used it before. In a moment when we have to create more than one directory, its not a must to create them one by one. See the example.

Making More Than One Directory

Making More Than One Directory

I have created 3 more new folders/directories namely D2,D3 and D4 just entering a single command. Like that you can add more arguments with mkdir. It saves lot of time.

             Now try to make changes in our newly made directories. Its not working huh? it happens because of its default permission pattern. Check it out by giving ls -l. Now  I m assigning full rights to all, by giving 777 with chmod (chmod 777 directory_name  see cli-partI for help) for my convenience. Now I m creating another directory named as D5 and configure its permission to 777. But in a single step,

 

Creating ang Changing Permision

Creating ang Changing Permision

See, I didnt use chmod command. -m is to set the permission mode.    

Now I need another directory D6, with a subdirectory named sub1. this is how  I m making it,

Creating Subdirectories

Creating Subdirectories

Tryout this with -m argument.

Ok, now its time to make files. You can use touch command for this purpose. touch command enables the user to change access, modification time for a given file and create files. Here, I m creating files inside of D1 directory.

 

touch

touch

I have created 5 different files with different extensions. use stat command to get more info about a specific file.

stat

stat

Notice the Access time. I can change it to my present time with -a argument.

-a argument

-a argument

Like that I can also change the Modify time to my present time with -m argument.

-m argument

-m argument

 

User can also assign date/time for his/her request. I m changing the date into 2009/jan/15 and time into 12.48.10. Here we go,

 

Changing Date/Time for User Request

Changing Date/Time for User Request

 

 

Coping is another file operation. In CLI cp is used for this. cp can be used with many arguments and it can be done in many ways . Here I m coping D1 and its content into D2,

cp

cp

Now I m coping only the content of D1 into D3,

Coping Only the Content

Coping Only the Content

And watch this,

-i with cp

-i with cp

-i prompt you before overwriting a file    

This is not all with cp command. It can work with many other arguments.

Moving is another important file operation. You can perform it in the same way we  copied files and directories. But you have to give mv command instead of giving cp.  mv is also used to rename files and directories.

Renaming a File/Directories

Renaming a File/Directories

In the above example, I have renamed directory D5 as D10.

rm command is to remove files and directories. Usually this 1st example is called as ‘interactive Remove’.

 

Removing Files

Removing Files

Above, I have entered into D1 directory. Then removed the file named ‘file2.odt’. Here, its important to using -i argument because it prompt the user before deleting any files or directories. You can also force to delete write protected files by giving the -f argument instead of giving -i.   

Notice: Be careful with using rm command because it can destroy your important data.   

use -fr argument with rm command to delete/remove directories.

Removing Directories

Removing Directories

I have delete ‘D4’ by following the above method.

This post is getting longer and longer. So I should stop from here. I ll give you more awesome CLI tips from another post, Remember this Blog is dedicated to GNU/Linux beginners. So stick with dushan888.wordpress.com.

 

 ……….Later……….

 

 

Advertisements

4 Responses to “Awesome to work in CLI [Not for Masters but for Beginners] – Part III”

  1. someone Says:

    nice stuff mate

  2. yasith Says:

    nice article. keep it up! it kind of ‘revamped’ my brain on these things.

  3. DK Says:

    root@localhost# touch file1{1….1000}.txt

    using this you able to create muliple files

    have fum

  4. DK Says:

    sorry i shld be like this 😀

    root@localhost# touch file1{1..1000}.txt

    using this you able to create muliple files

    have fum


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: