for f in **/*.ts; do mv “$f” “${f%.ts}.js”; done
Category: Terminal
Remove duplicate lines from text file
This will keep the first instance of a duplicate:
sort for_db.txt | uniq > for_db_no_duplicates_2.txt
This will remove all duplicates (including the first occurence):
sort for_db.txt | uniq -u > for_db_no_duplicates_2.txt
Kill port already in use
Replace <PortNumber> with the port that is already in use
$ lsof -i :<PortNumber>
Find the PID in the result from above and replace <PID> with that.
$ kill -9 <PID>
Rename files to lowercase in Terminal
$ cd into folder with files
Run the following command from the Terminal:
$ for f in *; do mv “$f” “`echo $f | tr “[:upper:]” “[:lower:]”`”; done
Open Terminal shortcut
- Open Automator.app and choose “Quick Action”.
- Set “Workflow receives current” to “no input” (last item in dropdown menu).
- Under Actions > Library > Utilities; drag “Run AppleScript” into the Workflow Builder area.
- Type in:
on run {input, parameters} tell application "Terminal" reopen activate end tell end run
- Save the file as something like: “Open Terminal”, and quit the Automator.app.
- In System Preferences > Keyboard > Keyboard Shortcuts > Services; select “General” and scroll to the end of the list; under General. Here you’ll should see “Open Terminal” (or whatever you called it when saving the Quick Action in Automator.app) …
- Click the “Add shortcut button” and type your preferred shortcut (Cmd + Alt + x).
Launch Sublime Text 2 and 3 from the Terminal
Run this line for Sublime Text 2:
ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl2
Use like:
subl2 .
Run this line for Sublime Text 3:
ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl3
Use like:
subl3 .
Add git branch to Terminal
Put the following in your .bash_profile
parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' } export PS1="\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] "
Create folder structure in Terminal
mkdir -p folder/nested_folder/{nested_folder_1,nested_folder_2,nested_folder_3}
Creates the following folder structure:
folder/ nested_folder/ nested_folder_1 nested_folder_2 nested_folder_3