terminal

How to Batch Rename Files in a macOS Terminal?

て烟熏妆下的殇ゞ 提交于 2019-12-17 08:01:27
问题 I have a folder with a series of files named: prefix_1234_567.png prefix_abcd_efg.png I'd like to batch remove one underscore and the middle content so the output would be: prefix_567.png prefix_efg.png Relevant but not completely explanatory: How can I batch rename files using the Terminal? Regex to batch rename files in OS X Terminal 回答1: In your specific case you can use the following bash command ( bash is the default shell on macOS): for f in *.png; do echo mv "$f" "${f/_*_/_}"; done

How do I make this file.sh executable via double click?

随声附和 提交于 2019-12-17 08:00:07
问题 First off I'm using Mac. Next, I need to execute this "file.sh" we will call it. Everytime I need to execute it I have to open Terminal and type: cd /Users/Jacob/Documents/folderWithFileInIt bash file.sh This is okay, but I feel like it would be a lot quicker if I make the file execute on double click, don't you think? So my question is, how do I make this file executable via double click? My ideas were either: a) type something like chmod into terminal and change permissions? b) make a file,

(Mac) -bash: __git_ps1: command not found

爱⌒轻易说出口 提交于 2019-12-17 07:58:49
问题 I'm trying to change my command promt in terminal. I keep getting the error: -bash: __git_ps1: command not found I've tried it just by typing it into the terminal as is: __git_ps1 . I've also tried it out in the .bash_profile if [ -f ~/.git-completion.bash ]; then source ~/.git-completion.bash export PS1='[\W]$(__git_ps1 "(%s)"): ' fi As you might be able to see/tell, yes, I do have the auto-completion installed and it does work great! I came across this question: " PS1 env variable does not

Prevent Gnome Terminal From Exiting After Execution [duplicate]

梦想的初衷 提交于 2019-12-17 07:39:31
问题 This question already has answers here : Avoid gnome-terminal close after script execution? (7 answers) Closed 4 years ago . How do you prevent gnome-terminal from exiting after its given command has exited? I'm calling gnome-terminal from a cronjob, in order to create a terminal accessible to the user. The terminal is initially given a specific program to run. e.g. gnome-terminal --tab -e "/usr/bin/myprog" This works fine, except that when "myprog" exits, so does the gnome-terminal. How do I

How can I check if a Java program's input/output streams are connected to a terminal?

本小妞迷上赌 提交于 2019-12-17 06:13:11
问题 I would like a Java program to have different default settings (verbosity, possibly colored output where supported) depending on its use. In C, there is an isatty() function which will return 1 if a file descriptor is connected to a terminal, and 0 otherwise. Is there an equivalent for this in Java? I haven't seen anything in the JavaDoc for InputStream or PrintStream. 回答1: System.console() will return the console your application is connected to if it is connected, otherwise it returns null

Unable to show a Git tree in terminal

孤人 提交于 2019-12-17 05:15:34
问题 Killswitchcollective.com's old article, 30 June 2009, has the following inputs and outputs git co master git merge [your_branch] git push upstream A-B-C-D-E A-B-C-D-E-F-G \ ----> \ your branch C-D-E G I am interested how you get the tree like-view of commits in your terminal without using Gitk or Gitx in OS/X. How can you get the tree-like view of commits in terminal? 回答1: How can you get the tree-like view of commits in terminal? git log --graph --oneline --all is a good start. You may get

Open a new prompt/terminal window from Java

时光毁灭记忆、已成空白 提交于 2019-12-17 05:11:56
问题 I want to open a new terminal window, which will run a certain command upon opening. It preferably needs to be a real native window, and I don't mind writing different code for linux/osx/windows. I'm assuming an emulated terminal would work, as long as it supports everything a real terminal would do and isn't just printing lines of output from a command. 回答1: Opening an actual terminal window will definitely require different code for each OS. For Mac, you want something like: Runtime

OS X Terminal UTF-8 issues

℡╲_俬逩灬. 提交于 2019-12-17 04:55:35
问题 Okay, so I finally got myself a MacBook Air after 15 years of linux. And before I got it my big concern was UTF-8 support because no matter if I get files sent to me from windows or mac-clients theres always issues with encoding, while on ubuntu I can be sure that all output no matter what program will produce perfect utf-8 encoded data. And now on my second day (today) with OS X Im tearing my hair of by frustration. Why? When I open Nano and type some swedish characters like ÅÄÖ in it, it

How to terminate process from Python using pid?

回眸只為那壹抹淺笑 提交于 2019-12-17 04:54:58
问题 I'm trying to write some short script in python which would start another python code in subprocess if is not already started else terminate terminal & app (Linux). So it looks like: #!/usr/bin/python from subprocess import Popen text_file = open(".proc", "rb") dat = text_file.read() text_file.close() def do(dat): text_file = open(".proc", "w") p = None if dat == "x" : p = Popen('python StripCore.py', shell=True) text_file.write( str( p.pid ) ) else : text_file.write( "x" ) p = # Assign

How to terminate process from Python using pid?

◇◆丶佛笑我妖孽 提交于 2019-12-17 04:54:34
问题 I'm trying to write some short script in python which would start another python code in subprocess if is not already started else terminate terminal & app (Linux). So it looks like: #!/usr/bin/python from subprocess import Popen text_file = open(".proc", "rb") dat = text_file.read() text_file.close() def do(dat): text_file = open(".proc", "w") p = None if dat == "x" : p = Popen('python StripCore.py', shell=True) text_file.write( str( p.pid ) ) else : text_file.write( "x" ) p = # Assign