{"id":2558,"date":"2017-09-29T22:27:08","date_gmt":"2017-09-29T22:27:08","guid":{"rendered":"http:\/\/blog.paranoidprofessor.com\/?p=2558"},"modified":"2017-09-29T22:27:08","modified_gmt":"2017-09-29T22:27:08","slug":"command-line-fun-finding-mistakes","status":"publish","type":"post","link":"https:\/\/blog.paranoidprofessor.com\/index.php\/2017\/09\/29\/command-line-fun-finding-mistakes\/","title":{"rendered":"command line fun &#8211; finding mistakes"},"content":{"rendered":"<p>I knew that I had mistyped but it was too late. \u00a0I tried to exit out of vi in a hurry and accidentally exited but saved the file under a new name. \u00a0This wouldn&#8217;t have been so bad if the new name didn&#8217;t consist of a single control character.<\/p>\n<p>My fears were confirmed when I did a directory listing. \u00a0Not only did it make an annoying sound but you could see in the file listing that the files were no longer lined up.<\/p>\n<p><a href=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2563\" src=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic1.png\" alt=\"\" width=\"691\" height=\"407\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic1.png 691w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic1-300x177.png 300w\" sizes=\"(max-width: 691px) 100vw, 691px\" \/><\/a><\/p>\n<p>This isn&#8217;t the first time that my fingers got the better of me, so I simply ran the ls command and asked that it display the inode number of each of the files. \u00a0Normally that would have been fine but my control character, perhaps ^H, was actually removing the previous character displayed.<\/p>\n<p><a href=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic2.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2564\" src=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic2.png\" alt=\"\" width=\"691\" height=\"407\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic2.png 691w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic2-300x177.png 300w\" sizes=\"(max-width: 691px) 100vw, 691px\" \/><\/a><\/p>\n<p>This means that my inode number was any one of ten possible values. \u00a0There are other ways to try and determine exactly what inode number a file is but before trying that I simply did a long listing using ls.<\/p>\n<p><a href=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic3.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2565\" src=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic3.png\" alt=\"\" width=\"941\" height=\"447\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic3.png 941w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic3-300x143.png 300w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic3-768x365.png 768w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/a><\/p>\n<p>This actually did show that my inode number was 540. \u00a0I am actually a bit surprised that you cannot use this information directly to delete the file with the rm command (on Solaris, also on Linux?)<\/p>\n<p>This information however can be used in conjunction with both the find and rm commands to delete this tiny mistake.<\/p>\n<p>Instead of the familiar -name option for the find command there is a somewhat less used \u00a0 -inum option. \u00a0As this option name implies, it will look only for files that have this inode number.<\/p>\n<p><a href=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic4.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2566\" src=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic4.png\" alt=\"\" width=\"601\" height=\"407\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic4.png 601w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic4-300x203.png 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/a><\/p>\n<p>Once it is possible to find the actual file it is a simple matter of using the -exec option of find to remove the file.<\/p>\n<p>find . -inum 540 -exec rm {} \\;<\/p>\n<h2>Extra credit method<\/h2>\n<p>There is another way to find an inode number using just variations of the find command.<\/p>\n<p><a href=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic5.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2567\" src=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic5.png\" alt=\"\" width=\"941\" height=\"447\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic5.png 941w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic5-300x143.png 300w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2017\/09\/mistake-pic5-768x365.png 768w\" sizes=\"(max-width: 941px) 100vw, 941px\" \/><\/a><\/p>\n<p>find . -name &#8220;*&#8221;\u00a0 -ls<\/p>\n<p>This will just do a directory listing of the files under the current working directory and run a similar directory listing at the same time. \u00a0Deleting the file is done using the same find and remove as described above.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I knew that I had mistyped but it was too late. \u00a0I tried to exit out of vi in a hurry and accidentally exited but saved the file under a new name. \u00a0This wouldn&#8217;t have been so bad if the &hellip; <a href=\"https:\/\/blog.paranoidprofessor.com\/index.php\/2017\/09\/29\/command-line-fun-finding-mistakes\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[20],"tags":[17,39],"_links":{"self":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/2558"}],"collection":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/comments?post=2558"}],"version-history":[{"count":5,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/2558\/revisions"}],"predecessor-version":[{"id":2628,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/2558\/revisions\/2628"}],"wp:attachment":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/media?parent=2558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/categories?post=2558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/tags?post=2558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}