dot (.) in Linux



dot (.) can be used many ways in Linux. Here are some uses of dot in Linux

  dot (.) as file name


When working with filenames, a leading dot is the prefix of a "hidden file". To show hidden file in listing use command ls –al



Example

$ ls -al

total 14
drwxrwxr-x 2 ved    ved    1024   Aug 09 20:54 ./
drwx------ 52 ved    ved    3072   Aug 09 20:51 ../
-rw-r--r-- 1 ved    ved    4046   Jun 10 22:04 date.sh      
-rw-r--r—1    ved    ved    4072   May 25 13:58 backup.sh
-rw-r--r-- 1 ved    ved    8077   Dec 07 2000   linux.txt
-rw-rw-r-- 1 ved    ved    0      Aug 29 20:54 .hidden_text

Here file starting with dot is .hidden_file. This file is hidden in Linux. So you can use . before the filename to hide that file.


dot in Linux


Dot (.) is used for indicating present and Parent directory


 Single dot (.) is used to represent the present directory, double dot (..) represent parent directory.


In above example  single . represents the current directory and double dot .. represents the parent directory.

One more example is here

$ pwd
/home/ved/Documents

$ cd .
$ pwd
/home/ved/Documents

$ cd ..
$ pwd
/home/ved/


In copying file

. used in copying file in current directory

$ cp /home/user/Documents/linux.txt  .

It copies the file linux.txt to present directory.

$ cp /home/user/Documents/linux/*  .

It copies all files inside linux directory to present directory.


  In regular expression

In regular expression dot is used to search a character. It matches a single character.

Example
Ls –l | grep ab.cd

It shows the file or directory which first two characters is ab and last two character is cd, in place of dot any character can be there.




No comments: