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
0 comments:
Post a Comment