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 use who use c-shell, however, have to deal with aliasing.
Below are a few “functions” that i have in my .cshrc file which save me a lot of time.
Swap 2 files
alias swap 'mv !:1 tmp.1 | mv !:2 !:1 | mv tmp.1 !:2'
Use: mturner@prospero: swap file1.f file2.f
Result: The filenames have been swapped for these 2 files
Move and go
alias mvg 'mv !:1 !:2 && cd !:2'
Use: mturner@prospero: mvg file1.f ~/Desktop
Result: file1.f will be moved to the specified directory, and you are automatically cd’ed to the specified directory
Copy and go
alias cpg 'cp !:1 !:2 && cd !:2'
Use: mturner@prospero: cpg file1.f ~/Desktop
Result: Same as “move and go” but the file is copied, instead of moved
Find a file
alias findit 'find . -iname "!:1" -print'
Use: mturner@prospero: findit file1.f
Result: 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.
Extract any common archive format
alias extract 'eval "if (!* =~ *.tar.gz) then \
tar xvzf !* \
else \
if(!* =~ *.tar.bz2) tar xvjf !* \
if(!* =~ *.bz2) bunzip !* \
if(!* =~ *.rar) unrar x !* \
if(!* =~ *.gz) gunzip !* \
if(!* =~ *.tar) tar xvf !* \
if(!* =~ *.tbz2) tar xvjf !* \
if(!* =~ *.tgz) tar xvzf !* \
if(!* =~ *.zip) unzip !* \
if(!* =~ *.Z) uncompress !* \
if(!* =~ *.7z) 7z x !* \
endif"'
Use: mturner@prospero: extract archive1.tar.gz
Result: This alias will determine the compression technique used to create an archive, and then issue the corresponding command to uncompress the archive. UKUVCTS75QWV
[…] by Admin on Apr.25, 2011, under Uncategorized For those of you that read my other post about useful .cshrc functions, you know that I like to automate as many processes as possible. If there is something redundant […]
hi there!, I enjoy the producing a whole lot! portion we all keep in contact much more about ones submit with AOL? My partner and i call for an expert with this residence to end our difficulty. Could possibly be that is certainly a person! Looking onward to be able to expert an individual. Unbelievably beneficial thank you, It is my opinion your own viewers is likely to want far more things similar to this keep up the nice hard work.