{"id":24,"date":"2011-04-18T08:22:00","date_gmt":"2011-04-18T08:22:00","guid":{"rendered":"http:\/\/mattdturner.com\/wordpress\/?p=24"},"modified":"2011-04-26T14:16:27","modified_gmt":"2011-04-26T20:16:27","slug":"some-useful-cshrc-functions","status":"publish","type":"post","link":"http:\/\/mattdturner.com\/wordpress\/2011\/04\/some-useful-cshrc-functions\/","title":{"rendered":"Some Useful .cshrc Functions"},"content":{"rendered":"<p><span style=\"line-height: 24px;\"><span style=\"font-family: inherit;\">If you use the command line a lot, there are numerous common commands that can be automated to save time.<\/span><\/span><\/p>\n<p>Like what? Well, how about swapping the names of 2 files; or maybe unarchiving any filetype.<\/p>\n<p>People who use bash are lucky, bash allows you to actually create functions in the .bashrc file. Those of use who use c-shell, however, have to deal with aliasing.<\/p>\n<p>Below are a few \u201cfunctions\u201d that i have in my .cshrc file which save me a lot of time.<\/p>\n<h3 style=\"margin-bottom: -20px;\"><span style=\"font-family: inherit;\">Swap 2 files<\/span><\/h3>\n<p><span style=\"font-family: inherit;\"><br \/>\n<code>alias swap 'mv !:1 tmp.1 | mv !:2 !:1 | mv tmp.1 !:2'<\/code><br \/>\nUse:\u00a0<code>mturner@<strong>prospero: <\/strong>swap file1.f file2.f<\/code><br \/>\nResult: The filenames have been swapped for these 2 files<\/span><\/p>\n<h3 style=\"margin-bottom: -20px;\"><span style=\"font-family: inherit;\">Move and go<\/span><\/h3>\n<p><span style=\"font-family: inherit;\"><br \/>\n<code>alias mvg 'mv !:1 !:2 &amp;&amp; cd !:2'<\/code><br \/>\nUse:\u00a0<code>mturner@<strong>prospero: <\/strong>mvg file1.f ~\/Desktop<\/code><br \/>\nResult: file1.f will be moved to the specified directory, and you are automatically cd\u2019ed to the specified directory<br \/>\n<\/span><!--more--><\/p>\n<h3 style=\"margin-bottom: -20px;\"><span style=\"font-family: inherit;\">Copy and go<\/span><\/h3>\n<p><span style=\"font-family: inherit;\"><br \/>\n<code>alias cpg 'cp !:1 !:2 &amp;&amp; cd !:2'<\/code><br \/>\nUse:\u00a0<code>mturner@<strong>prospero: <\/strong>cpg file1.f ~\/Desktop<\/code><br \/>\nResult: Same as \u201cmove and go\u201d but the file is copied, instead of moved<\/span><\/p>\n<h3 style=\"margin-bottom: -20px;\"><span style=\"font-family: inherit;\">Find a file<\/span><\/h3>\n<p><span style=\"font-family: inherit;\"><br \/>\n<code>alias findit 'find . -iname \"!:1\" -print'<\/code><br \/>\nUse:\u00a0<code>mturner@<strong>prospero:<\/strong> findit file1.f<\/code><br \/>\nResult: The alias will search the current folder, as well as all sub-directories, for a file named file.f. The search is NOT case-sensitive.<\/span><\/p>\n<h3 style=\"margin-bottom: -20px;\">Extract any common archive format<\/h3>\n<p><code>alias extract 'eval \"if (!* =~ *.tar.gz) then \\<br \/>\ntar xvzf !* \\<br \/>\nelse \\<br \/>\nif(!* =~ *.tar.bz2) tar xvjf !* \\<br \/>\nif(!* =~ *.bz2) bunzip !* \\<br \/>\nif(!* =~ *.rar) unrar x !* \\<br \/>\nif(!* =~ *.gz) gunzip !* \\<br \/>\nif(!* =~ *.tar) tar xvf !* \\<br \/>\nif(!* =~ *.tbz2) tar xvjf !* \\<br \/>\nif(!* =~ *.tgz) tar xvzf !* \\<br \/>\nif(!* =~ *.zip) unzip !* \\<br \/>\nif(!* =~ *.Z) uncompress !* \\<br \/>\nif(!* =~ *.7z) 7z x !* \\<br \/>\nendif\"'<\/code><\/p>\n<p>Use:\u00a0<code>mturner@<strong>prospero:<\/strong> extract archive1.tar.gz<\/code><br \/>\nResult: This alias will determine the compression technique used to create an archive, and then issue the corresponding command to uncompress the archive. \u00a0 \u00a0\u00a0<span style=\"color: #222222; line-height: 16px;\"><span style=\"font-family: inherit; font-size: xx-small;\">UKUVCTS75QWV<\/span><\/span><\/p>\n<div class=\"zemanta-pixie\" style=\"margin-top: 10px; height: 15px;\"><a class=\"zemanta-pixie-a\" title=\"Enhanced by Zemanta\" href=\"http:\/\/www.zemanta.com\/\"><img decoding=\"async\" class=\"zemanta-pixie-img\" style=\"border: none; float: right;\" src=\"http:\/\/img.zemanta.com\/zemified_e.png?x-id=f33a7d5f-3311-431b-9850-fa14f74e89ed\" alt=\"Enhanced by Zemanta\" \/><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you use the command line a lot, there are numerous common commands that can be automated to save time. Like what? Well, how about swapping the names of 2 files; or maybe unarchiving any filetype. People who use bash are lucky, bash allows you to actually create functions in the .bashrc file. Those of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,11,20],"tags":[35,63,58,59,62,61,60,57],"class_list":["post-24","post","type-post","status-publish","format-standard","hentry","category-command-line","category-mac","category-scripting","tag-alias","tag-archive-format","tag-bzip2","tag-c-shell","tag-command-line-interface","tag-gzip","tag-tar-file-format","tag-zip","no-thumb"],"_links":{"self":[{"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts\/24"}],"collection":[{"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/comments?post=24"}],"version-history":[{"count":2,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts\/24\/revisions"}],"predecessor-version":[{"id":69,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts\/24\/revisions\/69"}],"wp:attachment":[{"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/media?parent=24"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/categories?post=24"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/tags?post=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}