Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash_profile multiple line alias

Tags:

bash

macos

I'd like to run a command called "showfiles" which would run the command "defaults write com.apple.finder AppleShowAllFiles TRUE" and "killall Finder" How do I go about doing this?

like image 261
daviesgeek Avatar asked May 03 '26 08:05

daviesgeek


2 Answers

I'm not sure why the && option @gahooa suggested wouldn't work, but there is yet another option: create a shell function:

showfiles() {
    defaults write com.apple.finder AppleShowAllFiles TRUE
    killall Finder
}
like image 182
Gordon Davisson Avatar answered May 04 '26 23:05

Gordon Davisson


There are a couple ways of doing this...

Option 1:
Put a script in your ~/bin directory

echo "defaults write com.apple.finder AppleShowAllFiles TRUE" > ~/bin/showfiles
echo "killall Finder" >> ~/bin/showfiles
chmod +x ~/bin/showfiles

Option 2:
Create an alias with AND to join the commands together:

alias showfiles='defaults write com.apple.finder AppleShowAllFiles TRUE && killall Finder'

Note: this will only run the second command if the first is successful.

like image 40
gahooa Avatar answered May 04 '26 21:05

gahooa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!