Linux touch command

Blogs ❯❯ Linux

Image could not load

Image on pixabay

What is touch Command in Linux ?

Linux में touch command operating system के लिए एक standard program है, जिसका use करके file के timestamp create , change और modify करने के लिए किया जाता है। इसका अलावा इसका use नई file को create करने के लिए भी किया जाता है।

Linux में, हर एक file timestamp से associate होती होती है, और हर file last access time , last update time की जानकारी store करती करती है। इसलिए, जब भी हम कोई नई file बनाते हैं, या पहले से बनी हुई किसी exist file को access या update करते हैं, तो उस file का timestamp automatically update हो जाता है।

***

इस blog में, हम Linux touch command के कुछ useful practical examples को देखेंगे। touch command UNIX/LINUX operating system के लिए एक standard program है, जिसका use करके file के timestamp create , change और modify करने के लिए किया जाता है।

Linux touch command options

touch command के examples को देखने से पहले , उसके options के बारे मने जान लेते हैं। touch command के options देखने के लिए simply अपने terminal पर touch --help command fire करें -

command run करने पर आपको touch command के सभी options description के साथ मिल जायेंगे।

:~$ touch --help
Usage: touch [OPTION]... FILE...
Update the access and modification times of each FILE to the current time.

A FILE argument that does not exist is created empty, unless -c or -h
is supplied.

A FILE argument string of - is handled specially and causes touch to
change the times of the file associated with standard output.

Mandatory arguments to long options are mandatory for short options too.
  -a                     change only the access time
  -c, --no-create        do not create any files
  -d, --date=STRING      parse STRING and use it instead of current time
  -f                     (ignored)
  -h, --no-dereference   affect each symbolic link instead of any referenced
                         file (useful only on systems that can change the
                         timestamps of a symlink)
  -m                     change only the modification time
  -r, --reference=FILE   use this file's times instead of current time
  -t STAMP               use [[CC]YY]MMDDhhmm[.ss] instead of current time
      --time=WORD        change the specified time:
                           WORD is access, atime, or use: equivalent to -a
                           WORD is modify or mtime: equivalent to -m
...and some..other info

Linux create empty file

touch filename , command run करने पर आपके current directory में zero-byte की एक empty file file create हो जायगी।

:~$ touch myfile.txt

ls command run करके आप देख file create हुई है या नहीं -

:~$ ls
myfile.txt

Linux create multiple files

Well done, अब एक साथ कई files को create करके देखते है, multiple files को create करने के लिए touch के बाद options में आपको सभी files के name single space के बाद लिख देने हैं।

touch file1 file2 file

Example

:~$ touch myfile2.txt myfile3.txt myfile4.txt
:~$ ls
myfile.txt  myfile2.txt  myfile3.txt  myfile4.txt
What is ls?

Linux में ls command का use directories या directory contents को list करने के लिए किया जाता है।

learn more about ls ...

अब touch command के साथ use होने वाले parameters (options) को समझ का तरय करेंगे हैं।

touch -a

touch -a command का use किसी file के access time को change करने के लिए use किया है।

For example कुछ time पहले create की गयी myfile.txt का access time change करने का try करेंगे -

~$ ls -lu
total 0
-rw-rw-r-- 1 ubuntu ubuntu 0 Oct  3 16:53 myfile.txt

किसी file के last access time को show करने के लिए ls -lu command का use किया जाता है। अब myfile.txt का access time change करते हैं।

:~$ touch -a myfile.txt
~$ ls -lu
total 0
-rw-rw-r-- 1 ubuntu ubuntu 0 Oct  3 16:58 myfile.txt

ध्यान रहे अगर targeted file नहीं मिली तो , तो new file create हो जायगी।

touch -m

touch -m command का use किसी file के modification time को change करने के लिए use किया है। किसी file का modification time देखने के लिए ls -l command का use किया जाता है -

~$ ls -l
total 0
-rw-rw-r-- 1 ubuntu ubuntu 0 Oct  3 16:46 myfile.txt

Now run command

~$ touch -m myfile.txt
:~$ ls -l
total 0
-rw-rw-r-- 1 ubuntu ubuntu 0 Oct  3 17:03 myfile.txt
Change Both Modification and Access Time

आप Modification और Access Time दोनों को एक साथ change करने के लिए touch -am command का use भी कर सकते हैं।

:~$ ls -l
total 0
-rw-rw-r-- 1 ubuntu ubuntu 0 Oct  3 17:03 myfile.txt
:~$ ls -lu
total 0
-rw-rw-r-- 1 ubuntu ubuntu 0 Oct  3 16:58 myfile.txt
:~$ touch -am myfile.txt
:~$ ls -l
total 0
-rw-rw-r-- 1 ubuntu ubuntu 0 Oct  3 17:07 myfile.txt
:~$ ls -lu
total 0
-rw-rw-r-- 1 ubuntu ubuntu 0 Oct  3 17:07 myfile.txt

Tip : Create n number of files

अगर आप एक साथ किसी particular number तक file generate करना चाहते हैं तो simply नीचे दिए गए syntax के according command run करें।

touch filename{start..end}

For Example -

:~$ touch testfiles{1..10}
:~$ ls
testfiles1  testfiles10  testfiles2  testfiles3  testfiles4  testfiles5  testfiles6  testfiles7  testfiles8  testfiles9

और ठीक इसी तरह आप , numbers की जगह किसी particular letter का use भी कर सकते हैं।

:~$ touch myfile_{a..h}
:~$ ls
myfile_a  myfile_b  myfile_c  myfile_d  myfile_e  myfile_f  myfile_g  myfile_h

Note* numbers और letters को आप mix करके use नहीं करके सकते हैं।

I Hope, touch command के बारे में यह blog आपको पसंद आया होगा। :)

Recent Blogs

Loading ...

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook