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.
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.
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,
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,
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.
I have created 5 different files with different extensions. use stat command to get more info about a specific file.
Notice the Access time. I can change it to my present time with -a argument.
Like that I can also change the Modify time to my present time with -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,
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,
Now I m coping only the content of D1 into D3,
And watch this,
-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.
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’.
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.
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.