Thursday, April 2, 2015

Removing Files and directories in ubuntu

Removing Files


rm file    Removes a file

rm -r dir    Removes a dir(directory) and 
     all files in it.

rm -f file    Force removal.

* nano filename (opens a file or creates if there is no such file)
In this post we have created two files in target directory
1.this-week-target (Spelling mistake bare with me)


Explaining the screenshot (screenshot @ bottom)

As I opened my terminal I'm at my home directory.

cd Desktop 

changed my directory to Desktop(it's D )

mkdir target

It creates a new directory called target

cd target

It changes my current directory to target.So now i'm in the target directory.

nano this-week-target

It creates a file called this-week-target in target folder.

So you need to type some info.Now to save the file you need to press (ctrl+o) and hit enter.
Now press ctrl+x to get back to normal terminal.

To create a file [nano filename --> fill the file with some info --> ctrl+o --> hit enter--->ctrl+x]
nano blog-taarget creates another file

now ls command shows there are two files in target directory.

cat blog-taarget 

The above command shows the content of the file..

rm blog-taarget removes the file

now you can give ls and see there is only one file in target directory.

Now I want to remove the target directory also.Since target directory is on Desktop,I'll change my directory to Desktop.

cd .. (cd followed by two dots)

The above command takes me to the previous directory.

Now to remove the target directory and all files inside it we use

rm -r target

rm -r means remove recursively...
So be careful while using rm -r.
now ls on Desktop you will not see the target directory.


Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.

No comments:

Post a Comment