In the previous part I just explained 3 commands that will help you to navigate through files and folders in your system.In this section let us discuss how to perform some actions like create, rename, remove folders using command line.
Creating a folder using the command:
The command used to create a folder is mkdir .Open up the terminal and type :
mkdir myfolder
A new folder named myfolder will be there in your home directory.You can make folders anywhere in your system.But you must mention the directory address for your folder with folder name otherwise the folder will be created in the current directory.
Eg: to make a folder in the directory /tmp use the following command.
mkdir /tmp/myfolder
Extra note : Normally your system will not display any message after creation of the folder. If you add the parameter -v to the mkdir command you will get a message after the creation of the folder (eg: mkdir myfolder -v)
Removing a file or folder
The Linux kernel consider folder and file as same .You can remove any file or folder using the command rm .
the usage of the command is rm [option] <file> .
Here are the important options you might use.
-f (forcefully removes file with no prompting)
-v (Explains what is being done)
-r (Removes files recursively in a directory.It is used when the folder contains subfolders.)
I just mentioned the syntax above. But you need just a single command to remove a folder that is
rm -rf /tmp/myfolder
here '-rf' is the option with the command which says that files will be removed recursively and forcefully. And /tmp/myfolder will be the folder we want to delete.
Showing posts with label Terminal Dictionary. Show all posts
Showing posts with label Terminal Dictionary. Show all posts
Thursday, 23 February 2012
Monday, 16 January 2012
Know the amount of available Disk Space in Linux
We are already
know that the Linux shell is the powerful tool which is capable of
doing any jobs related with Linux OS .Read more about Linux terminalclick here .Here in this
post I am going to tell about a simple command which is used to know
the free space available in the hard disk partitions with in no time.
To get started open up the terminal and :
- Type df you can see the list of partitions with available free space listed.
- Type df -a to get a detailed listing of free space. this Include in the listing file-systems that have a size of 0 blocks, which are omitted by default.
- Type df -h to get a listing more optimized .Here size is listed in MBs .-h stands for human readable form .
To get the detailed syntax information
use the command man df. This
will list all the possibilities of the command.
Labels:
Basics,
Terminal Dictionary
Wednesday, 14 December 2011
Searching strings with grep command
Let me discuss a situation- I have
saved all of my contacts information as separate files and put it in
a folder called contacts. I have to find the file which contain the
name Mr. John. I get started with opening each files in my text
editor and ctr+f to find john..it was too difficult since I have
about 300 files to search. But working a little smart I found john in
2 minutes..How ? The grep command .
Grep is a command-line text-search utility originally written for Unix. The name comes from the ed command g/re/p (global / regular expression / print). The grep command searches the given file for lines containing a match to the given strings or words. grep displays the matching lines by default.
How to use grep command :
1.Searching for a string in a file
Grep is a command-line text-search utility originally written for Unix. The name comes from the ed command g/re/p (global / regular expression / print). The grep command searches the given file for lines containing a match to the given strings or words. grep displays the matching lines by default.
How to use grep command :
1.Searching for a string in a file
$ grep train vehicles.txt
the above usage will print all the
lines containing the text train from vehicles.txt
2 .Searching in multiple files
of same type :
$ grep train *.txt
the above command will print all the
lines with text 'train' from all the text files in that folder
3. Searching by ignoring case
sensitivity (with parameter -i)
$ grep -i train vehicles.txt
the above command will search all the
'train' sequences wihtout matching the cases.
4 . Word search
$ grep -w train vehicles.txt
and train do not not match) may be accomplished with the -w option flag
5. Count lines when words are matched
$ grep -c 'word' /directory
grep can count the number of times that the pattern has been matched for each file using -c (count) option.
6.Search recursively in an entire directory
$ grep -r 'word' /directory
You can search recursively i.e. read
all files under each directory for a string .
Labels:
Terminal,
Terminal Dictionary
Subscribe to:
Posts (Atom)