// API callback
related_results_labels_thumbs({"version":"1.0","encoding":"UTF-8","feed":{"xmlns":"http://www.w3.org/2005/Atom","xmlns$openSearch":"http://a9.com/-/spec/opensearchrss/1.0/","xmlns$blogger":"http://schemas.google.com/blogger/2008","xmlns$georss":"http://www.georss.org/georss","xmlns$gd":"http://schemas.google.com/g/2005","xmlns$thr":"http://purl.org/syndication/thread/1.0","id":{"$t":"tag:blogger.com,1999:blog-1255024703457423340"},"updated":{"$t":"2023-10-27T23:44:13.497+05:30"},"category":[{"term":"awk one liners"},{"term":"perl one liners"},{"term":"different methods"},{"term":"sed one liners"},{"term":"Different ways of"},{"term":"Shell Scripting"},{"term":"commands"},{"term":"Perl"},{"term":"shells"},{"term":"awk"},{"term":"Basics"},{"term":"sed"},{"term":"Administration"},{"term":"Filesystem"},{"term":"bash"},{"term":"utilities"},{"term":"Oracle"},{"term":"find"},{"term":"VI editor"},{"term":"awk tutorial"},{"term":"join"},{"term":"sed tutorial"},{"term":"sqlplus"},{"term":"shell script"},{"term":"vim"},{"term":"Productivity"},{"term":"awk parse CSV"},{"term":"file permissions"},{"term":"grep command"},{"term":"inodes"},{"term":"ksh"},{"term":"python"},{"term":"Inodes FAQ"},{"term":"Linux Interview Questions and answers"},{"term":"date"},{"term":"env variable"},{"term":"how to"},{"term":"parse CSV file"},{"term":"perl arrays"},{"term":"perl hash"},{"term":"python3"},{"term":"sed regular expression"},{"term":"typeset"},{"term":"C programming"},{"term":"FTP"},{"term":"GNU date"},{"term":"PATH variable"},{"term":"Soft Skill"},{"term":"associative array"},{"term":"awk date functions"},{"term":"awk sed perl grep substring"},{"term":"awk sum column values"},{"term":"awk time"},{"term":"convert uppercase"},{"term":"date formatting"},{"term":"line count"},{"term":"lines below pattern"},{"term":"linux"},{"term":"mail"},{"term":"mathematical"},{"term":"paste command"},{"term":"perl foreach"},{"term":"perl function"},{"term":"perl split string"},{"term":"profile"},{"term":"ps command"},{"term":"sed insert line"},{"term":"sed replace"},{"term":"shell script duplicates"},{"term":"soft link"},{"term":"sort remove duplicates"},{"term":"source"},{"term":"special variable IFS"},{"term":"split file"},{"term":"timestamps"},{"term":"unix linux process"},{"term":"zero padding"},{"term":"CDPATH"},{"term":"CGI"},{"term":"CPAN module"},{"term":"CPU utilization"},{"term":"IFS"},{"term":"Linux shell scripting interview questions"},{"term":"NSE"},{"term":"Oracle table csv"},{"term":"SUID"},{"term":"XML"},{"term":"__DATA__"},{"term":"__END__"},{"term":"alpha vantage"},{"term":"array"},{"term":"awk concatenate values"},{"term":"awk delimiter square brackets"},{"term":"awk first record group"},{"term":"awk insert column"},{"term":"awk insert line"},{"term":"awk join with delimiter"},{"term":"awk join without delimiter"},{"term":"awk match exact word"},{"term":"awk match pattern specific column"},{"term":"awk max value"},{"term":"awk min value"},{"term":"awk mktime"},{"term":"awk pass parameters"},{"term":"awk pattern matching"},{"term":"awk perl sed change delimiter"},{"term":"awk perl sed print trailer record"},{"term":"awk print lines before pattern"},{"term":"awk read files alternatively"},{"term":"awk sed perl cut extract characters"},{"term":"awk sed perl insert line before pattern"},{"term":"awk sed perl print lines below pattern"},{"term":"awk sed perl reverse file order"},{"term":"awk sed perl reverse string"},{"term":"awk sed perl right padding"},{"term":"awk sed print first few characters"},{"term":"awk sed swap lines in file"},{"term":"awk special variables"},{"term":"awk split file and insert header"},{"term":"awk split files every n line"},{"term":"awk split files on pattern"},{"term":"awk strftime"},{"term":"awk sum group"},{"term":"awk systime"},{"term":"awk unique values"},{"term":"awk varying length delimiter"},{"term":"awk word delimiter"},{"term":"bash arithmetic"},{"term":"bash substring"},{"term":"bc"},{"term":"bc command examples"},{"term":"best practice"},{"term":"case insensitive search"},{"term":"char"},{"term":"comm"},{"term":"comm command examples"},{"term":"command line arguments"},{"term":"compare files"},{"term":"concatenate lines"},{"term":"concatenate variables"},{"term":"convert ascii to hex"},{"term":"convert csv file to query"},{"term":"convert lowercase"},{"term":"convert text to query"},{"term":"cp"},{"term":"cron"},{"term":"ctags"},{"term":"cut"},{"term":"database"},{"term":"date command"},{"term":"date conversion"},{"term":"date functions"},{"term":"delete"},{"term":"delete character"},{"term":"delete control-M"},{"term":"delete line"},{"term":"df command"},{"term":"du command"},{"term":"environment"},{"term":"epoch time"},{"term":"eulers project"},{"term":"exclude directory"},{"term":"expr command"},{"term":"extern"},{"term":"filename"},{"term":"find files only current directory"},{"term":"find files specific directory"},{"term":"find module location"},{"term":"find xargs"},{"term":"find2perl"},{"term":"fold"},{"term":"foreach"},{"term":"gawk"},{"term":"getopts"},{"term":"group count"},{"term":"heredoc"},{"term":"inode changes"},{"term":"insert line beginning"},{"term":"insert line end"},{"term":"iterators"},{"term":"join method"},{"term":"ksh arrays examples"},{"term":"ksh substring"},{"term":"leave directory"},{"term":"length"},{"term":"line number"},{"term":"lines above pattern"},{"term":"link count"},{"term":"links"},{"term":"linux command line options"},{"term":"linux date command"},{"term":"ln command"},{"term":"map"},{"term":"multiple delimiters"},{"term":"multiple pattern search"},{"term":"multiple queries"},{"term":"negative pattern search"},{"term":"omit directory"},{"term":"ord"},{"term":"pandas"},{"term":"parse text file"},{"term":"pass awk variables to shell"},{"term":"paste command join lines"},{"term":"paste command merge files"},{"term":"paste command multiple files"},{"term":"paste command standard input"},{"term":"paste read file alternatively"},{"term":"pattern match"},{"term":"pattern matching"},{"term":"performance"},{"term":"perl DATA handler"},{"term":"perl alias"},{"term":"perl append string"},{"term":"perl builtin function"},{"term":"perl date"},{"term":"perl delete string"},{"term":"perl dumper"},{"term":"perl each"},{"term":"perl eval"},{"term":"perl file find"},{"term":"perl file handling"},{"term":"perl find files"},{"term":"perl hash examples"},{"term":"perl insert line"},{"term":"perl insert string"},{"term":"perl join"},{"term":"perl qr"},{"term":"perl regular expression"},{"term":"perl replace string"},{"term":"perl sed print lines before pattern"},{"term":"perl subtring"},{"term":"perl sum digits"},{"term":"preserve timestamp"},{"term":"prime numbers"},{"term":"print hash"},{"term":"print header"},{"term":"print nth line"},{"term":"print range of lines"},{"term":"print trailer record"},{"term":"ps TIME"},{"term":"push"},{"term":"python file writing"},{"term":"python iterator"},{"term":"python list"},{"term":"python read file"},{"term":"remove duplicates"},{"term":"remove leading zeros"},{"term":"replace characters"},{"term":"replace line"},{"term":"replace string"},{"term":"replace word"},{"term":"retrieve filename"},{"term":"reverse file"},{"term":"review"},{"term":"rlogin"},{"term":"sed delete blank lines"},{"term":"sed delete header trailer"},{"term":"sed delete line before after pattern"},{"term":"sed delete line ranges"},{"term":"sed delete lines ending with"},{"term":"sed delete not containing pattern"},{"term":"sed hold space"},{"term":"sed pattern space"},{"term":"sed print line"},{"term":"sed sum"},{"term":"set options"},{"term":"setuid"},{"term":"shell script UUC"},{"term":"shell script change delimiter"},{"term":"shell script read files alternatively"},{"term":"shell script reverse string"},{"term":"shell script sum"},{"term":"shell script swap lines in file"},{"term":"shell script to insert line before pattern"},{"term":"shell variables"},{"term":"shift"},{"term":"shift command"},{"term":"sort"},{"term":"sort and merge"},{"term":"sort file numerically"},{"term":"sort find duplicates"},{"term":"sort multiple fields"},{"term":"sort reverse"},{"term":"special variables"},{"term":"split"},{"term":"split command"},{"term":"split line"},{"term":"split multiple files"},{"term":"ssh"},{"term":"string length"},{"term":"string reverse"},{"term":"substitution"},{"term":"sum file contents"},{"term":"swap columns"},{"term":"swap lines"},{"term":"sys module"},{"term":"sys.path"},{"term":"table to csv"},{"term":"tac command"},{"term":"tags"},{"term":"time command"},{"term":"time difference"},{"term":"tr"},{"term":"umask"},{"term":"unix"},{"term":"unix find"},{"term":"unix shell scripting interview questions"},{"term":"unix sort examples"},{"term":"unix time"},{"term":"update"},{"term":"values"},{"term":"wantarray example"},{"term":"while loop"},{"term":"while loop IFS"},{"term":"while read multiple delimiters"},{"term":"word count"},{"term":"write method"},{"term":"writelines method"},{"term":"xargs"},{"term":"year 2038"},{"term":"yes command"}],"title":{"type":"text","$t":"The UNIX School"},"subtitle":{"type":"html","$t":"Instructions\/Tutorials on Unix\/Linux commands, C Programming, Unix Administration , Oracle, PL SQL, Perl, Productivity tips soft skills for newbies and professionals."},"link":[{"rel":"http://schemas.google.com/g/2005#feed","type":"application/atom+xml","href":"https:\/\/www.theunixschool.com\/feeds\/posts\/default"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/1255024703457423340\/posts\/default\/-\/Administration?alt=json-in-script\u0026max-results=5"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.theunixschool.com\/search\/label\/Administration"},{"rel":"hub","href":"http://pubsubhubbub.appspot.com/"},{"rel":"next","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/1255024703457423340\/posts\/default\/-\/Administration\/-\/Administration?alt=json-in-script\u0026start-index=6\u0026max-results=5"}],"author":[{"name":{"$t":"Guru Prasad"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/07898245472802947101"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"generator":{"version":"7.00","uri":"http://www.blogger.com","$t":"Blogger"},"openSearch$totalResults":{"$t":"9"},"openSearch$startIndex":{"$t":"1"},"openSearch$itemsPerPage":{"$t":"5"},"entry":[{"id":{"$t":"tag:blogger.com,1999:blog-1255024703457423340.post-6185570358398753633"},"published":{"$t":"2012-08-21T15:55:00.002+05:30"},"updated":{"$t":"2012-08-21T15:55:50.221+05:30"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"Administration"},{"scheme":"http://www.blogger.com/atom/ns#","term":"file permissions"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Filesystem"}],"title":{"type":"text","$t":"What is the use of sticky bit in Linux?"},"content":{"type":"html","$t":"\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; \u0026nbsp; In an earlier article, we discussed the purpose of\u0026nbsp;\u003Ca href=\"http:\/\/www.theunixschool.com\/2010\/06\/what-is-suid.html\" target=\"_blank\"\u003ESUID\u003C\/a\u003E, an advanced file permision. In the same lines,\u0026nbsp;\u003Cb\u003ESticky bit\u003C\/b\u003E is also an advanced file permission used in Unix\/Linux or its flavors. This feature was originally meant for regular files and directories, though is now used only in directories in many Unix flavors. This permission, when applied on a directory, allows users to maintain 'their' files in directories which are shared with everybody. \u0026nbsp;\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u003C\/div\u003E\n\u003Ca name='more'\u003E\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u003Cb\u003E\u003Cu\u003E\/tmp:\u003C\/u\u003E\u003C\/b\u003E\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; \u0026nbsp; In any Unix flavor, directories are created at times with full permissions which are shared or accessed by everybody. Say, for example the '\/tmp' directory. \/tmp directory is accessible for each and every user, where the user can read, create\/write and remove files.\u0026nbsp;A careful look at the file permissions of the \/tmp directory shows 777 which according to file\u0026nbsp;\u003Ca href=\"http:\/\/www.theunixschool.com\/2010\/05\/file-permissions-vs-directory.html\" target=\"_blank\"\u003Epermission definitions of directory\u003C\/a\u003E, should allow every user even to edit or delete other user files.\u0026nbsp;However, any user will be able to edit or delete only the files created by himself, not the files created by other users. How is it possible?\u0026nbsp;This is where the 'sticky bit' comes in. Note the sticky bit present in the \/tmp directory:\u003C\/div\u003E\n\u003Cpre class=\"gpr1\"\u003E$ ls -ld \/tmp\ndrwxrwxrw\u003Cspan style=\"color: red;\"\u003Et\u003C\/span\u003E  27 root root 4096 Aug 17 18:48 \/tmp\n\u003C\/pre\u003E\n\u0026nbsp; This sticky bit allows users to edit and remove files only belonging to them alone, not by others users, at the same time allowing the other users to create their own files and maintain them.\u0026nbsp;\u003Cspan style=\"text-align: justify;\"\u003ETo simplify it, sticky bit on this \/tmp directory means \"\u003C\/span\u003E\u003Ci style=\"text-align: justify;\"\u003Eall permissions to the world but do not touch my files\u003C\/i\u003E\u003Cspan style=\"text-align: justify;\"\u003E\".\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E\u003Cu\u003ECase study:\u003C\/u\u003E\u003C\/b\u003E\u003Cbr \/\u003E\n\u0026nbsp; Let us create a scenario and try to understand this sticky bit in detail. For our simplicity, we consider 2 users: user1 and user2:\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E\u0026nbsp;1. User1 creates a directory, say \"test\" under the \/tmp and creates a file\u003C\/b\u003E, say 'file1':\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\"\u003E$ echo $USER\nuser1\n$ pwd\n\/tmp\n$ mkdir test\n$ chmod 777 test\n$ ls -ld test\ndrwxrwxrwx  2 user1 dba 4096 Aug 17 18:48 test\n$ cd test\n$ touch file1\n$ ls -l file1\n-rw-r--r--  1 user1 dba 0 Aug 17 18:48 file1\n\u003C\/pre\u003E\n\u003Cb\u003E2. User2 now tries to remove the file \u003C\/b\u003E\"file1\":\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\"\u003E$ echo $USER\nuser2\n$ pwd\n\/tmp\/test\n$ ls\nfile1\n$ rm file1\n$\n\u003C\/pre\u003E\nuser2 was able to remove the file since the 'test' directory has 777 permissions which means world editable. And hence anybody can create, edit or delete anybody's files in this 'test' directory.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E\u0026nbsp;3. user1 now applies the 'sticky bit' to control this mess\u003C\/b\u003E\u0026nbsp;and creates a file:\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\"\u003E$ pwd\n\/tmp\n$ chmod +t test\n$ ls -ld test\ndrwxrwxrw\u003Cspan style=\"color: red;\"\u003Et\u003C\/span\u003E  2 user1 dba 4096 Aug 17 18:48 test\n$ cd test\n$ touch file1\n$ ls\nfile1\n\u003C\/pre\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp;Did you think why can't user1 simply remove 'write' permission to others from the test directory? By removing the write permission, user1 will be successful in preventing the user2 from removing his files. However, this move will also prevent user2 from creating his own files in the test directory. Hence, the sticky bit which is equal to \"all permissions\", at the same time \"do not touch my files\".\u003C\/div\u003E\n\u003Cb\u003E\u003Cbr \/\u003E\u003C\/b\u003E\n\u003Cb\u003E4. user2 now tries to delete the file\u003C\/b\u003E 'file1':\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\"\u003E$ pwd\n\/tmp\/test\n$ ls\nfile1\n$ rm file1\nrm: cannot remove `file1': Operation not permitted\n$ mv file1 f1\nmv: cannot move `file1' to `f1': Operation not permitted\n\u003C\/pre\u003E\nAs seen, the file is no longer removable or renamable. The file 'file1' can now be edited only by the owner of the file 'user1' or by the root user.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E\u0026nbsp;5. The user 'user2' can still create files\u003C\/b\u003E, however,\u0026nbsp;and edit or remove files which he has created.\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\"\u003E$ touch file2\n$ ls -l\ntotal 12\n-rw-r--r--  1 user1 dba 0 Aug 17 18:52 file1\n-rw-r--r--  1 user2 vmw 8 Aug 17 18:53 file2\n$ cat \u0026gt; file2\nwelcome\n^C\n$ rm file2\n$\n\u003C\/pre\u003E\nuser2 was able to create a file 'file2' and he was able to delete the file created by himself.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp;P.S: Sticky bit on regular files, though unused today in Linux, was originally meant to speed up execution. This bit on regular files was meant to be set on executables. Executables with sticky bit set are maintained in the swap space itself, so that the next time the executable is required, it can directory be run from swap memory, instead of getting it from the hard disk.\u003C\/div\u003E\n"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.theunixschool.com\/feeds\/6185570358398753633\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.theunixschool.com\/2012\/08\/sticky-bit-use-purpose-linux.html#comment-form","title":"0 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/1255024703457423340\/posts\/default\/6185570358398753633"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/1255024703457423340\/posts\/default\/6185570358398753633"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.theunixschool.com\/2012\/08\/sticky-bit-use-purpose-linux.html","title":"What is the use of sticky bit in Linux?"}],"author":[{"name":{"$t":"Guru Prasad"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/07898245472802947101"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"0"}},{"id":{"$t":"tag:blogger.com,1999:blog-1255024703457423340.post-9034568168721449649"},"published":{"$t":"2012-07-10T16:14:00.000+05:30"},"updated":{"$t":"2020-07-11T10:20:25.678+05:30"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"Administration"},{"scheme":"http://www.blogger.com/atom/ns#","term":"commands"},{"scheme":"http://www.blogger.com/atom/ns#","term":"find"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Perl"}],"title":{"type":"text","$t":"find2perl - 10 examples to find files without find command"},"content":{"type":"html","$t":"\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; \u0026nbsp; In our earlier articles on the find command, we discussed how to \u003Ca href=\"http:\/\/unix-school.blogspot.com\/2010\/08\/find-files-modified-in-last-x-days-and.html\" target=\"_blank\"\u003Efind files modified before X hours, X mins or X seconds\u003C\/a\u003E. find command options mtime, mmin, newer, etc. are used to get the desired list of files.\u0026nbsp;\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; \u0026nbsp;\u003Cb\u003E How to find the files modified before X mins or X seconds in a system which does not support the 'newer' option or the 'mmin' options of the find command?\u003C\/b\u003E\u0026nbsp;\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; \u0026nbsp; \u0026nbsp;The answer for this \u003Cb\u003Efind2perl\u003C\/b\u003E. This is a tool which comes in-built along with perl installation. Hence, any Unix flavor in which perl is present should have the find2perl utility present in it. Perl has some modules for finding files which is as good as the Unix find. This utility creates a perl script which uses the File::Find module to find files, and gives an output which is nothing but a perl script equivalent of the Unix find command. On running this script, the desired list of files could be retrieved.\u0026nbsp;\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u003Cbr \/\u003E\n\u003Ca name='more'\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u003Cspan style=\"background-color: white;\"\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp;The syntax of find2perl is exactly like the find command. Many of the options present in the find command is also present with the find2perl command. Let us see some examples on how to use find2perl:\u0026nbsp;\u003C\/span\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E\u0026nbsp;1. find all files with the .txt extension\u003C\/b\u003E:\n\n\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ find2perl . -name \"*.txt\" \u0026gt; f1\n\u003C\/pre\u003E\nf1 contains the perl script generated by the find2perl utility. On executing the file f1, the files will be retrieved and displayed.\n\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ chmod 755 f1\n$ .\/f1\n\u003C\/pre\u003E\n\u003Cb\u003E2. find the files whose inode number\u003C\/b\u003E is 9962606\n\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ find2perl . -inum 9962606 \u0026gt; f1\n$ .\/f1\n\u003C\/pre\u003E\n\u0026nbsp; \u0026nbsp; \u0026nbsp;As shown, the options provided to the find2perl are exactly like the find command.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E3. To find files modified in the last 1 day\u003C\/b\u003E:\n\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ find2perl . -mtime -1 \u0026gt; f1\n$ .\/f1\n\u003C\/pre\u003E\n1 indicates 1 day. -1 indicates files modified in the last one day. +1 indicates files modified before 1 day.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u003Ci\u003E\u0026nbsp;\u003C\/i\u003EUnlike the Unix find command,\u0026nbsp;\u003Ci\u003Efind2perl does not support the mtime, atime, ctime \u003C\/i\u003Eoptions. Still, using find2perl, we can find files modified in the last x minutes using the mtime switch itself, however, we need to edit the intermediate file generated by the find2perl. Its a kind of hacking the intermediate file and customizing it for our purpose. This will be a 3 step process:\u003Cbr \/\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u003Cspan style=\"background-color: white;\"\u003ERun the find2perl command and re-direct the output to a file.\u003C\/span\u003E\u003C\/li\u003E\n\u003Cli\u003EEdit the file and remove the word \"int\" and save the file.\u003C\/li\u003E\n\u003Cli\u003ERun the file to execute the script.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003C\/div\u003E\n\u003Cb style=\"background-color: white;\"\u003E\u0026nbsp;4. To find files modified in the last 1 hour\u003C\/b\u003E\u003Cspan style=\"background-color: white;\"\u003E:\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ find2perl . -mtime -1\/24 \u0026gt; f1\n\u003C\/pre\u003E\nOpen the generaeted file f1. In the line containing the statement: \u003Ci\u003E(int(-M _) \u0026lt; 1\/24)\u003C\/i\u003E\ndelete the word \"\u003Ci\u003Eint\u003C\/i\u003E\". Save the file f1. And execute the file now.\n\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ .\/f1\n\u003C\/pre\u003E\n1 in the mtime option indicates 1 day, and hence 1\/24 indicates 1 hour.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E\u0026nbsp;5. To find files modified before 1 hour\u003C\/b\u003E:\n\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ find2perl . -mtime +1\/24 \u0026gt; f1\n\u003C\/pre\u003E\nRemove the word \"int\" as in the example 4 in the file f1 and save it.\u003Cspan style=\"background-color: white;\"\u003ERun the file f1.\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ .\/f1\n\u003C\/pre\u003E\nThe only change here is in place of -, we have +.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E\u0026nbsp;6. To find files modified in the last 5 hours\u003C\/b\u003E:\n\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ find2perl . -mtime -5\/24 \u0026gt; f1\n\u003C\/pre\u003E\nRemove the word \"int\" as in the example 4 in the file f1 and save it. Run the file f1.\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ .\/f1\n\u003C\/pre\u003E\nThe change here is: For 5 hours, simply multiply the duration for one hour by 5.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E7. To find all files modified in the last 40 mins\u003C\/b\u003E:\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ find2perl . -mtime \"-40\/(24*60)\" \u0026gt; f1\n\u003C\/pre\u003E\nRemove the word \"int\" as in the example 4 in the file f1 and save it.\u003Cspan style=\"background-color: white;\"\u003ERun the file f1.\u003C\/span\u003E\n\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ .\/f1\u003C\/pre\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp;As said earlier, the number in mtime indicates number of days. Hence, to get to the hour level, say for 1 hour: 1\/24. Similarly, to get to the minute level, say 1 minute: 1\/(24*60). Now, for 40 minutes, multiply it by 40, and hence we get: 40\/(24*60).\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E8. Similarly, to find files modified exactly 40 minutes back\u003C\/b\u003E:\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ find2perl . -mtime \"40\/(24*60)\" \u0026gt; f1\n\u003C\/pre\u003E\nRemove the word \"int\" as in the example 4 in the file f1 and save it.\u003Cspan style=\"background-color: white;\"\u003ERun the file f1.\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ .\/f1\u003C\/pre\u003E\n\u003Cspan style=\"background-color: white;\"\u003E\u0026nbsp; \u0026nbsp; All we did is removing the negative sign in the mtime option.\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cb style=\"background-color: white;\"\u003E\u0026nbsp; \u0026nbsp;\u0026nbsp;\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cb style=\"background-color: white;\"\u003E9. To find all files modified in the last 2000 seconds\u003C\/b\u003E\u003Cspan style=\"background-color: white;\"\u003E :\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ touch -d \"2000 seconds ago\" tmpFile\n$ find2perl . -newer tmpFile \u0026gt; f1\n$ .\/f1\n\u003C\/pre\u003E\n\u0026nbsp; \u0026nbsp; This is the same way as we did in an example of \u003Ca href=\"http:\/\/unix-school.blogspot.com\/2010\/08\/find-files-modified-in-last-x-days-and.html\" target=\"_blank\"\u003Efind files modified in X hours and X mins and X seconds.\u003C\/a\u003E A temporary file is created whose time stamp is 2000 seconds before the current time. find2perl tries to find all files which are newer than the tmpFile, in other words, all files modified after the file tmpFile is created.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E10. To find files modified in the last 2000 seconds without using the newer option\u003C\/b\u003E\u003Cspan style=\"background-color: white;\"\u003E:\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cspan style=\"background-color: white;\"\u003E\u0026nbsp; \u0026nbsp; In case, your Unix system does not contain the \"-d\" option in the touch command, you will not be able to use the above approach. However, you can still use the -mtime instead of -newer for this requirement:\u003C\/span\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ find2perl . -mtime \"-2000\/(24*60*60)\" \u0026gt; f1\n\u003C\/pre\u003E\nAs above, remove the word \"int\" as in the example 4 in the file f1 and save it. Run the file f1.\n\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ .\/f1\u003C\/pre\u003E\nNote: \u0026nbsp;Though we discussed the find2perl to use in case of not having the mtime option, the same holds good for all the 3 time stamps: mtime, ctime and atime."},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.theunixschool.com\/feeds\/9034568168721449649\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.theunixschool.com\/2012\/07\/find2perl-10-examples-to-find-files.html#comment-form","title":"0 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/1255024703457423340\/posts\/default\/9034568168721449649"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/1255024703457423340\/posts\/default\/9034568168721449649"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.theunixschool.com\/2012\/07\/find2perl-10-examples-to-find-files.html","title":"find2perl - 10 examples to find files without find command"}],"author":[{"name":{"$t":"Guru Prasad"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/07898245472802947101"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"0"}},{"id":{"$t":"tag:blogger.com,1999:blog-1255024703457423340.post-1778858839679732039"},"published":{"$t":"2012-04-17T21:25:00.000+05:30"},"updated":{"$t":"2020-07-11T09:57:28.748+05:30"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"Administration"},{"scheme":"http://www.blogger.com/atom/ns#","term":"CDPATH"},{"scheme":"http://www.blogger.com/atom/ns#","term":"env variable"},{"scheme":"http://www.blogger.com/atom/ns#","term":"shells"}],"title":{"type":"text","$t":"What is CDPATH ?"},"content":{"type":"html","$t":"\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; \u0026nbsp; Has it happened to you wherein you logged in to an account or to an environment and simply printed the command, say \"cd log\" and your directory gets changed to some log directory. The interesting part is: The log directory is not there in the directory from where you fired the cd command. It was somewhere also, however the cd command switched to it correctly. The question now is: \u0026nbsp;If the \"log\" directory is not present in the location from where we are giving the \"cd\" command, how did we reach the log directory? \u0026nbsp;The answer to this question is most probably \u0026nbsp;the \u003Cb\u003ECDPATH \u003C\/b\u003Eenvironment variable would have been set.\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E1. What is CDPATH?\u003C\/b\u003E\u003Cbr \/\u003E\n\u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp;CDPATH is an environment variable. It looks exactly like the PATH variable containing with many different paths concatenated using ':'.\u003Cbr \/\u003E\n\u003Ca name='more'\u003E\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cb\u003E2. What is the use of CDPATH ?\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp;Say, for example, some directories present in an \"X\" directory are being accessed frequently by the user. Every time the user wants to traverse to any of these directories present in \"X\", \u0026nbsp;he mostly traverses by giving the absolute path which is little time consuming if you have to find it. How nice will it be if we can do \"cd\" to the particular directory as if that directory which you are looking for is right under your current directory. This is what the CDPATH achieves.\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; \u0026nbsp; Normally, when the cd command is given, it checks for the directory name in the current directory and throws error if not found, else traverses to the directory. If the CDPATH is set, the \"cd\" command starts finding the directory in the list of directories present in the CDPATH variable and then makes the directory switch appropriately.\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E3. How to set the CDPATH variable?\u003C\/b\u003E\u003Cbr \/\u003E\n\u0026nbsp; \u0026nbsp; \u0026nbsp;Setting the CDPATH variable is exactly like setting the PATH variable. For example:\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ export CDPATH=\".:\/home\/guru:\/usr\"\n\u003C\/pre\u003E\n\u0026nbsp; \u0026nbsp; \u0026nbsp;This above command will hold good till the session is closed. In order to make this change permanent, we need to put this command in the appropriate \u003Ca href=\"http:\/\/unix-school.blogspot.com\/2011\/07\/what-is-profile-file.html\" target=\"_blank\"\u003E\u003Cb\u003Eprofile file\u003C\/b\u003E\u003C\/a\u003E. The CDPATH command in this example is set with 3 components: The current directory followed by \/home\/guru and the \/usr.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u0026nbsp; Let us try to test this CDPATH variable. Currently, we are in \/home\/guru. There are 3 directories present under it.\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ pwd\n\/home\/guru\n$ ls -l | grep ^d\ndrwxr-xr-x+ 1 guru None       0 Feb  9 20:18 C\ndrwxr-xr-x+ 1 guru None       0 Apr 15 13:56 bin\ndrwxr-xr-x+ 1 guru None       0 Apr 15 18:35 perl\n\u003C\/pre\u003E\nNow, let us try to switch to the perl directory. And hence we will be in \/home\/guru\/perl. The switch to \"perl\" directory happened because the CDPATH contains the dot(.) at first place, and perl is under current directory(.)\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ cd perl\n$ pwd\n\/home\/guru\/perl\n\u003C\/pre\u003E\nNow, let us try to switch to the bin directory which is under home whereas we are actually now under perl.\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ cd bin\n$ pwd\n\/home\/guru\/bin\n\u003C\/pre\u003E\n\u0026nbsp; \u0026nbsp; This is how the CDPATH works. This is highly useful when you have some frequently traversed directories in the environment.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E4. How to find the value of the CDPATH variable?\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ echo $CDPATH\n.:\/home\/guru:\/usr\n\u003C\/pre\u003E\n\u003Cb\u003E5. If CDPATH is set, will the cd command still search in the current directory by default before referring to the CDPATH?\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; \u0026nbsp; \u0026nbsp; No. Once the CDPATH is set, the cd command will search only in the directories present in the CDPATH variable only. Hence, it is the responsibility of the user to make sure that the current directory is also present in the CDPATH variable. \u003Cbr \/\u003E\nNote: This point holds good when only the directory name is specified with cd. cd when given with absolute or relative path does not refer to the CDPATH command.\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E6. Can the current directory be anywhere in the CDPATH variable?\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; \u0026nbsp; \u0026nbsp; As such, there is no rule to put the current directory in specific place. However, it SHOULD always be the first component of the CDPATH. It is because if it is not there in first position, the default functioning of the cd command which is to switch to the required directory under current directory may not work. Hence, the cd command should always be made to search for the directory first in the current directory, and then only in the other directories present in the CDPATH variable.\u003C\/div\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.theunixschool.com\/feeds\/1778858839679732039\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.theunixschool.com\/2012\/04\/what-is-cdpath.html#comment-form","title":"1 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/1255024703457423340\/posts\/default\/1778858839679732039"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/1255024703457423340\/posts\/default\/1778858839679732039"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.theunixschool.com\/2012\/04\/what-is-cdpath.html","title":"What is CDPATH ?"}],"author":[{"name":{"$t":"Guru Prasad"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/07898245472802947101"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"1"}},{"id":{"$t":"tag:blogger.com,1999:blog-1255024703457423340.post-1802122049177582427"},"published":{"$t":"2012-03-14T20:52:00.000+05:30"},"updated":{"$t":"2020-07-11T09:45:44.457+05:30"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"Administration"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Filesystem"},{"scheme":"http://www.blogger.com/atom/ns#","term":"inodes"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Inodes FAQ"},{"scheme":"http://www.blogger.com/atom/ns#","term":"links"},{"scheme":"http://www.blogger.com/atom/ns#","term":"ln command"}],"title":{"type":"text","$t":"Soft Links \u0026 Hard Links - All about Inodes - Part 2"},"content":{"type":"html","$t":"\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp;In one of our earlier articles, we discussed about the inode structure and its properties under the title \u003Ca href=\"http:\/\/unix-school.blogspot.com\/2011\/06\/inode-all-about-inodes.html\" target=\"_blank\"\u003E\u003Cb\u003EAll about Inodes\u003C\/b\u003E\u003C\/a\u003E. In continuation to the same, in this article, we will see about the links in UNIX: hard links and soft links, and their relationship with Inodes. We will learn them in the way of questions and answers.\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Ca name='more'\u003E\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cb\u003E1. What are links in Unix?\u003C\/b\u003E\u003Cbr \/\u003E\n\u0026nbsp; \u0026nbsp; A link in UNIX is a pointer to a file. Like pointers in any programming languages, links in UNIX are pointers pointing to a file or a directory . Creating links is a kind of shortcuts to access a file. The two different types of links in UNIX are:\u003Cbr \/\u003E\n\u003Cul\u003E\n\u003Cli\u003ESoft Links or Symbolic Links\u003C\/li\u003E\n\u003Cli\u003EHard links\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E2. How to create Soft links and hard links? And how do we access them?\u003C\/b\u003E\u003Cbr \/\u003E\n\u0026nbsp; \u0026nbsp; \u0026nbsp;Say, you have a file named \"file1\" with the following contents:\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ cat file1\nwelcome\n\u003C\/pre\u003E\n.\u0026nbsp; \u0026nbsp;To create a hard link of file1:\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ ln file1 file2\n\u003C\/pre\u003E\n\u0026nbsp; \u0026nbsp;To create a soft link of file1:  \u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ ln -s file1 file3 \n\u003C\/pre\u003E\n\u0026nbsp; \u0026nbsp; Once the links are created, the linked files contain the same content as of the original file. See below\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ cat file2\nwelcome\n$ cat file3\nwelcome\u003C\/pre\u003E\nNote: Soft links can be created on non-existent files as well.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E3. \"file2\" and \"file3\" being the linked files, can I say which is a soft link \u0026amp; which is hard link?\u003C\/b\u003E\u003Cbr \/\u003E\n\u0026nbsp; \u0026nbsp;Yes. When you do the listing of the files with \"-li\" option:\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ ls -li\ntotal 20\n9962464 -rw-r--r-- 2 guru users 8 Mar \u0026nbsp;9  file1\n9962464 -rw-r--r-- 2 guru users 8 Mar \u0026nbsp;9  file2\n9962471 lrwxrwxrwx 1 guru users 5 Mar \u0026nbsp;9  file3 -\u0026gt; file1\u003C\/pre\u003E\n\u0026nbsp; \u0026nbsp;If you notice file3, it shows \"-\u0026gt;\" towards file1. This indicates file3 is a soft-link of file1. \u0026nbsp;In case of file2, if you notice the inode numbers of file1 and file2, they are the same. Same inode number indicates file1 and file2 are hardlinks. Also note, the link count of these files is 2.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E4. file1 and file2 are of the same size. In case of the file \"file3\", the file size is being shown as 5. How is it 5?\u003C\/b\u003E\u003Cbr \/\u003E\n\u0026nbsp; \u0026nbsp; \u0026nbsp; The file size of a soft linked file is the length of the filename of the original file. In this case, the original file \"file1\" is of length 5. In a soft linked file, the location where the file content is to be stored, the file name of the original file gets stored, and hence the file size is so.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E5. file1 and file2 are hardlinks? Can we say which is the original file and which is the hard-linked file?\u003C\/b\u003E\u003Cbr \/\u003E\n\u0026nbsp; \u0026nbsp; No. We cannot say which is the original file and which one was the hard-linked file. Once a hard-link is created, it is like 2 files pointing to the same location. In fact, once a hard link is created on a file, using the term 'original file' is actually incorrect.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E6. Will deleting the file \"file1\" make \"file2\" and \"file3\" inaccessible?\u003C\/b\u003E\u003Cbr \/\u003E\n\u0026nbsp; \u0026nbsp;On deleting the file \"file1\", the soft linked file \"file3\" will become inaccessible. However, the hard linked file \"file2\" can still be accessed.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E7. How is it possible that while deleting the original file, still the hard linked file is accessible, and the soft linked file is not?\u003C\/b\u003E\u003Cbr \/\u003E\n\u0026nbsp; \u0026nbsp; Let us look into the inode structure of the hard and soft links to understand this in detail.\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E                             _______        ________\n         FIle1--------\\_____|inode  |______| welcome|\n                       _____|_______|      |________|\n         File2--------\/      9962464\n\n\u003C\/pre\u003E\n\u0026nbsp; \u0026nbsp; \u0026nbsp; \u003Cb\u003EFig 1:\u003C\/b\u003E Hard Link representation(Files pointing to inodes, in turn pointing to data location)\u003Cbr \/\u003E\n\u0026nbsp;\u0026nbsp; \u0026nbsp; \u003Cbr \/\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; \u0026nbsp;File1 and File2 are hardlinks. As we know, they both have the same inode number(9962464) and hence they both point to the same inode structure. One of the parameters in the inode tells the location of the file contents, and hence the contents are accessed by both the files.\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; \u0026nbsp;Now, say we try to delete the file \"File2\". When the file is deleted, only the link connecting of File2 to the inode structure gets disconnected. However, the inode and the file contents and the link of File1 are still in tact, and hence the file is still accessible.\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u0026nbsp; \u0026nbsp; However, the same is not the case with the soft link. In case of soft link:\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E                       _______        ________\n         FIle1--------|       |______| welcome|\n                      |_______|      |________|     \n                       9962464\n                       _______        ________\n         FIle3--------|       |______| File1  |\n                      |_______|      |________|\n                       9962471 \n\u003C\/pre\u003E\n\u0026nbsp; \u0026nbsp; \u0026nbsp;\u003Cb\u003EFig 2\u003C\/b\u003E: Soft Link Representation \u0026nbsp;(Files pointing to inodes, in turn pointing to data location)\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; \u0026nbsp;File1 and File3 both have different inode numbers. These different inode numbers point to different data locations. File1 location points to the contents of the file. However, if you see the content location of File3, it contains \"File1\" which is nothing but the original file from which the soft link is formed. Now, when File3 is accessed, through its inode metadata, it gets the name \"File1\" and searches for \"File1\" and reaches to the content of \"File1\". Hence, once the \"File1\" is deleted, \"File3\" becomes dangling meaning it points to something which does not exist. And so, the soft link becomes inaccessible.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u0026nbsp; \u0026nbsp;For these same reasons, we can create a soft link on an non-existent file, however, the same is not possible for hard links.\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E8. Soft links can span across Filesystems whereas hard links can be created only within a file system. Why so?\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; \u0026nbsp;Hard link refers to its file using the inode number. Inode numbers are specific within a file system. This means a file \"f1\" in filesystem \"X\" can have the same inode number as of a file \"f2\" in filesystem \"Y\". This is very much possible. For this reason, hard links cannot be shared across file systems.\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; However, the same is not true for soft links. Soft links refer to the files using the file name as seen in the earlier case. Hence, a soft links can be accessed across the file systems.\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E9. Does soft links and hard links work only at the file level? Does it work at the directory level as well?\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; \u0026nbsp; \u0026nbsp;Hard links work only at the file level. However, soft links works at the directory level as well. This particular use of soft links, to create links at the directory level, serves us a shortcut for many frequently used directories.\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E10. Summarizing, what are all the differences between soft and hard links?\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cu\u003ESoft Links:\u003C\/u\u003E\u003Cbr \/\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp;Soft Links can be created across file systems.\u003C\/li\u003E\n\u003Cli\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp;Soft link has a different inode number than the original file.\u003C\/li\u003E\n\u003Cli\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp;On deleting the original file, soft link cannot be accessed.\u0026nbsp;\u003C\/li\u003E\n\u003Cli\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp;Soft link needs extra memory to store the original file name as its data.\u003C\/li\u003E\n\u003Cli\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp;Source file need not exist for soft link creation.\u003C\/li\u003E\n\u003Cli\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp;Can be created on a file or on a directory.\u003C\/li\u003E\n\u003Cli\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp;Access to the file is slower due to the overhead to access file.\u0026nbsp;\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cu\u003EHard Links:\u003C\/u\u003E\u003Cbr \/\u003E\n\u003Cul\u003E\n\u003Cli\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp;Hard links can be created only within the file system.\u003C\/li\u003E\n\u003Cli\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp;Hard links have the same inode number as the original file.\u003C\/li\u003E\n\u003Cli\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp;On deleting the original file, hard linked file can still be accessed.\u003C\/li\u003E\n\u003Cli\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp;Hard links do not need any extra data memory to save since it uses links\u003C\/li\u003E\n\u003Cli\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp;Source file should exist.\u003C\/li\u003E\n\u003Cli\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp;Can be created only on files, not on directories.\u003C\/li\u003E\n\u003Cli\u003E\u0026nbsp; \u0026nbsp; \u0026nbsp;Access\u0026nbsp; to the file is faster compared to soft link.\u003C\/li\u003E\n\u003C\/ul\u003E\n\u003Cbr \/\u003E\nVery soon, we will have one more part on Inodes!!!\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv\u003E\n\u003C\/div\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.theunixschool.com\/feeds\/1802122049177582427\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.theunixschool.com\/2012\/03\/soft-links-hard-links-all-about-inodes.html#comment-form","title":"7 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/1255024703457423340\/posts\/default\/1802122049177582427"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/1255024703457423340\/posts\/default\/1802122049177582427"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.theunixschool.com\/2012\/03\/soft-links-hard-links-all-about-inodes.html","title":"Soft Links \u0026 Hard Links - All about Inodes - Part 2"}],"author":[{"name":{"$t":"Guru Prasad"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/07898245472802947101"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"thr$total":{"$t":"7"}},{"id":{"$t":"tag:blogger.com,1999:blog-1255024703457423340.post-436509605523261124"},"published":{"$t":"2011-08-18T20:22:00.000+05:30"},"updated":{"$t":"2020-04-25T12:43:00.558+05:30"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"Administration"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Productivity"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Shell Scripting"}],"title":{"type":"text","$t":"A Shell Script to do shell scripting faster"},"content":{"type":"html","$t":"\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; \u0026nbsp;Shell Scripting is all about automating a particular task, doing a task a bit faster than what it takes to do manually. However, when we write a shell script, if we notice properly, the amount of time we take to get it done is little more. In other words, can we think of ways in which we can write and test a shell script faster?\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; Typically, when we write a shell script, we open the editor, write something, save and close it. Run the script. Depending on the output or some error thrown, open the file again, edit something, save and close it. Run the script, and this goes on and on and on. The focus here is the amount of time you spent on saving the file every time, running it, and again opening the file and repeating this whole process umpteen times. In some cases, while running, we get error, and by the time we re-open the file, we forget what the error is. Now, again run the script and see the error again and re-open it. The amount of time we spend here is pretty high.\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Ca name='more'\u003E\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; Sometimes, what people do is, they keep 2 terminals open, edit and save the file in one terminal, and keep running the script in the other. This is a good time saver, but let us see what can be done to save the maximum amount of time to write and test a script.\u003C\/div\u003E\n\u003Cbr \/\u003E\nThe method which we are going to discuss to make this process faster involves two steps:\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E1\u003C\/b\u003E. \u0026nbsp;Map a key in \u003Cb\u003Evi \u003C\/b\u003Eto save and close a file.\u003Cbr \/\u003E\n\u003Cb\u003E2\u003C\/b\u003E. Write a shell script which will open the file(which is a shell script), and run the script.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nLets discuss those 2 points in detail:\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E1\u003C\/b\u003E. Let us map the function key F2 in vi to do a save a close. The following is the line which we should add in the .exrc or the .vimrc file. Once the below line is added, on pressing F2 inside vi, the file will get saved and quit vi.\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003Emap #2 :wq!^M\n\u003C\/pre\u003E\nNote: ^M is put using the following sequence: Ctrl+V+M\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u0026nbsp;#2 refers to the function key F2. The above setting will work if your Unix flavor is Solaris or Linux. If it is HP-UX, \u0026nbsp;refer this link:\u0026nbsp;\u003Ca href=\"http:\/\/unix-school.blogspot.com\/2010\/01\/mapping-function-keys-f1-in-vi.html\"\u003EMapping function keys in vi\u003C\/a\u003E\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E2\u003C\/b\u003E. Write a small script, \u0026nbsp;with the following contents. I name this script as \u003Ci\u003Eworkon\u003C\/i\u003E:\u003Cbr \/\u003E\n\u003Cpre class=\"gpr1\" style=\"border: 2px groove; margin: 20px; overflow: auto; padding: 6px;\"\u003E$ cat workon\n#!\/usr\/bin\/bash\n\nif [ ! -f $1 ]; then\n\u0026nbsp; echo \"#!\/usr\/bin\/bash\" \u0026gt; $1\nfi\n\nwhile [ 1 ];\ndo\n\u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp; vi $1\n\u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp; chmod 755 $1\n\u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp; .\/$1\n\u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp; read dummy\ndone\u003C\/pre\u003E\n\u003Cbr \/\u003E\nWhat this script does is simple: It accepts a file name as argument, which is a shell script in our case. If the file is empty, adds the she bang line and gets it ready. Else simply opens the file. On closing the file, runs the script and the output is displayed. On pressing any key, it takes you back to vi again. And the cycle repeats.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\nNow, lets write a sample script, test.sh.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E1\u003C\/b\u003E. Invoke the \u003Ci\u003Eworkon \u003C\/i\u003Escript with the test.sh as its argument:\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"http:\/\/3.bp.blogspot.com\/-oBHJqogvqf0\/TkPbp-GcBsI\/AAAAAAAACpg\/WOHOqzrHM0E\/s1600\/wo1.jpg\" imageanchor=\"1\" style=\"clear: left; float: left; margin-bottom: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" src=\"https:\/\/3.bp.blogspot.com\/-oBHJqogvqf0\/TkPbp-GcBsI\/AAAAAAAACpg\/WOHOqzrHM0E\/s1600\/wo1.jpg\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E\u003Cbr \/\u003E\u003C\/b\u003E\n\u003Cb\u003E\u003Cbr \/\u003E\u003C\/b\u003E\n\u003Cb\u003E2\u003C\/b\u003E. On invoking \u003Ci\u003Eworkon\u003C\/i\u003E, the below screen will be opened. As you see, the she bang line gets added automatically since its a new file:\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"http:\/\/3.bp.blogspot.com\/-dVNzC-57J7g\/TkPcWPuRE1I\/AAAAAAAACpk\/BHthH7vpf1Q\/s1600\/wo2.JPG\" imageanchor=\"1\" style=\"clear: left; float: left; margin-bottom: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" src=\"https:\/\/3.bp.blogspot.com\/-dVNzC-57J7g\/TkPcWPuRE1I\/AAAAAAAACpk\/BHthH7vpf1Q\/s1600\/wo2.JPG\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E\u003Cbr \/\u003E\u003C\/b\u003E\n\u003Cb\u003E\u003Cbr \/\u003E\u003C\/b\u003E\n\u003Cb\u003E3. \u003C\/b\u003ELet us edit the file and put some contents in it:\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"http:\/\/3.bp.blogspot.com\/-clGkncdNr2g\/Tk0bKauONSI\/AAAAAAAACpo\/xMhosP7iOZE\/s1600\/we3.JPG\" imageanchor=\"1\" style=\"clear: left; float: left; margin-bottom: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" src=\"https:\/\/3.bp.blogspot.com\/-clGkncdNr2g\/Tk0bKauONSI\/AAAAAAAACpo\/xMhosP7iOZE\/s1600\/we3.JPG\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E\u003Cbr \/\u003E\u003C\/b\u003E\n\u003Cb\u003E\u003Cbr \/\u003E\u003C\/b\u003E\n\u003Cb\u003E\u003Cbr \/\u003E\u003C\/b\u003E\n\u003Cb\u003E4.\u003C\/b\u003E Press F2 to save and run the file. As seen below, the output is displayed:\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"http:\/\/2.bp.blogspot.com\/-d6jx_xaOJbM\/Tk0bWYztIjI\/AAAAAAAACps\/8KZK5KYr_rQ\/s1600\/wo4.JPG\" imageanchor=\"1\" style=\"clear: left; float: left; margin-bottom: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" src=\"https:\/\/2.bp.blogspot.com\/-d6jx_xaOJbM\/Tk0bWYztIjI\/AAAAAAAACps\/8KZK5KYr_rQ\/s1600\/wo4.JPG\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003E\u003Cbr \/\u003E\u003C\/b\u003E\n\u003Cb\u003E\u003Cbr \/\u003E\u003C\/b\u003E\n\u003Cb\u003E5.\u003C\/b\u003E Press 'Enter' to edit the file again, and the cycle repeats:\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\n\u003Ca href=\"http:\/\/1.bp.blogspot.com\/-SjeLBLz8ZRg\/Tk0cE32hEqI\/AAAAAAAACpw\/v8V6Tdr4Ay0\/s1600\/wo5.JPG\" imageanchor=\"1\" style=\"clear: left; float: left; margin-bottom: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" src=\"https:\/\/1.bp.blogspot.com\/-SjeLBLz8ZRg\/Tk0cE32hEqI\/AAAAAAAACpw\/v8V6Tdr4Ay0\/s1600\/wo5.JPG\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u0026nbsp; \u003Cbr \/\u003E\n\u003Cbr \/\u003E\nIn this way, we can write and test a shell script much much faster.\u003Cbr \/\u003E\n\u003Cbr \/\u003E\n\u003Cb\u003EGeneric \u003Ci\u003Eworkon \u003C\/i\u003Escript:\u003C\/b\u003E\u003Cbr \/\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\nThe next question, can we customize this \u003Ci\u003Eworkon \u003C\/i\u003E\u0026nbsp;script even more?\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\nFor example, if you are a developer, at a given point of time, you might be writing a C\/C++ program, or a Java program or a shell script or a perl script or a python script or a PL\/SQL script and so on.When we write a C program, on pressing F2, we would like it to get compiled and the program be run, and the same holds good for \u0026nbsp;Java programs as well. Like the she bang line added automatically for a shell script, we would also like the same to get added for a Perl or Python script. Similarly, for a PL\/SQL script, we would like the SET statements to get added automatically.\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u003Cbr \/\u003E\u003C\/div\u003E\n\u003Cdiv style=\"text-align: justify;\"\u003E\n\u0026nbsp; The below shown program is the customised \u003Ci\u003Eworkon\u003C\/i\u003E\u0026nbsp;program which I use. Hope it might be useful for you too. You might customize it further to suit your needs:\u003C\/div\u003E\n\u003Cscript src=\"https:\/\/gist.github.com\/guruprasadpr\/9a5c62254a917efaa4904aaf6ab38d06.js\"\u003E\u003C\/script\u003E\n\nEnjoy the world of automation!!!\u003Cbr \/\u003E\n\u003Cbr \/\u003E"},"link":[{"rel":"replies","type":"application/atom+xml","href":"https:\/\/www.theunixschool.com\/feeds\/436509605523261124\/comments\/default","title":"Post Comments"},{"rel":"replies","type":"text/html","href":"https:\/\/www.theunixschool.com\/2011\/08\/shell-script-to-do-shell-scripting.html#comment-form","title":"2 Comments"},{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/1255024703457423340\/posts\/default\/436509605523261124"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/1255024703457423340\/posts\/default\/436509605523261124"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.theunixschool.com\/2011\/08\/shell-script-to-do-shell-scripting.html","title":"A Shell Script to do shell scripting faster"}],"author":[{"name":{"$t":"Guru Prasad"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/07898245472802947101"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/3.bp.blogspot.com\/-oBHJqogvqf0\/TkPbp-GcBsI\/AAAAAAAACpg\/WOHOqzrHM0E\/s72-c\/wo1.jpg","height":"72","width":"72"},"thr$total":{"$t":"2"}}]}});