0

I have searched for a similar question here, but found nothing related.

In Linux, the dot (.) refers to the directory itself. The touch command creates a file, if it does not exist.

But what does touch . (dot as argument) do?

I have checked the GNU touch documentation and the LINFO information about dot, but found nothing related.

I have tried this command in my Fedora and it seems that nothing is changed.

  • atime might have changed – 炸鱼薯条德里克 Oct 29 '18 at 2:33
  • @神秘德里克, thank. That clears things. Now I see it in ls output. Now I consider voting this question for deletion. But maybe there is another thing apart from that that touch does? – Silv Oct 29 '18 at 2:39
  • You can strace it. I believe it doesn't do too much work – 炸鱼薯条德里克 Oct 29 '18 at 2:41
  • Hm, I did not know about strace tool. Thanks. – Silv Oct 29 '18 at 2:43
1

From the GNU touch documentation:

touch changes the access and/or modification timestamps of the specified files.

So, if the file exists, then touch modifies it's timestamps. We can check this:

$ stat .
File: '.'
Size: 40              Blocks: 0          IO Block: 4096   directory
Device: 11h/17d Inode: 2338759     Links: 2
Access: (0755/drwxr-xr-x)  Uid: ( 1000/ chronos)   Gid: ( 1000/ chronos)
Context: u:object_r:tmpfs:s0
Access: 2018-10-29 08:06:16.918056344 +0530
Modify: 2018-10-29 08:06:15.484056316 +0530
Change: 2018-10-29 08:06:15.484056316 +0530
Birth: -

Now we run touch . and then:

$ stat .
File: '.'
Size: 40              Blocks: 0          IO Block: 4096   directory
Device: 11h/17d Inode: 2338759     Links: 2
Access: (0755/drwxr-xr-x)  Uid: ( 1000/ chronos)   Gid: ( 1000/ chronos)
Context: u:object_r:tmpfs:s0
Access: 2018-10-29 08:06:29.131056579 +0530
Modify: 2018-10-29 08:06:29.131056579 +0530
Change: 2018-10-29 08:06:29.131056579 +0530
Birth: -

Note how the Access:, Modify: and Change: fields have changed.

  • Thanks for listings and the stat utility, I did not know about it. :) – Silv Oct 29 '18 at 2:52
1

The short description in man touch says

change file timestamps

which is what it does in this case - it updates the modified timestamp of the current directory to the current time.

  • Thanks. Obvious. That is a kind of information that I always miss when reading about touch (because I do not know what I would like to change the time for). – Silv Oct 29 '18 at 2:44
-3

touch [dot] create hidden file with this name (.) you can check attached image enter image description here

  • 1
    This is just not true. . exists in every directory, as a reference to itself. – l0b0 Oct 29 '18 at 2:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.