How create .gdbinit in home directory (Mac OS) - macos

l
Hello everybody,I need to create a .gdbinit file to use the command "go" on gdb.
Our prof told us to create it in home directory and it was simple.
On Linux all I needed was to being root.
Now with Mac I can't create the file even if I am root.
From command line if I type " touch .gdbinit " or if I create the file in a different directory and try to move it in home the result is always "Operation not supported".
Now I am very confused because I thought to be a god as root.
Maybe this is true on Linux,Mac is different.
However someone know how to create a .gdbinit file in home?
I work on Sierra 10.12.6

There is no reason why this shouldn't work:
cd
touch .gdbinit
Now check it exists:
ls -la .gdbinit

Related

How do I access my iCloud Drive folder from Terminal?

I'm running OS X Yosemite. I would like to save my code folder in iCloud Drive so that it's automatically backed up. I need to access files from the Terminal often, so how can I access iCloud Drive from the Terminal?
cd ~/Library/Mobile\ Documents/com\~apple\~CloudDocs/
I would just add a symbolic link either to this folder or to a Source subfolder in your home directory to make working with this easier.
For example:
ln -s ~/Library/Mobile\ Documents/com\~apple\~CloudDocs ~/iCloud
and/or
ln -s ~/Library/Mobile\ Documents/com\~apple\~CloudDocs/Source ~/Source
It´s in the Library Folder of the user. The folder-name is "MobileDocuments".
It's in ~/Library/Mobile\ Documents/com\~apple\~QuickTimePlayerX/Documents/....
How to find it? You can drag a file in the finder and drop the file to the terminal, then the file path would be displayed in the terminal.
This is an awful way to get the path, I'm very curious about how to reveal it more naturally and easily and gracefully.

How do I run .sh or .bat files from Terminal?

I have a pretty basic problem here, that has happened so haphazardly to me that up until now, I've just ignored it. I downloaded tomcat web server and "Murach's Java Servlets and JSP" book is telling me to navigate to the tomcat/bin directory and start the server my typing in Terminal
$ startup
However, I get the error
-bash: startup: command not found
The relevant files in this directory are startup.sh and startup.bat. Typing both of these returns the same error message
So my questions are, what are .bat and sh files, and how do I run these files? I've read several tutorials for different languages and software programs, and some times when the tutorial says execute a bunch of files in the command line, I get a "command not found" error. Sometimes it works, sometimes it doesn't. This is perplexing to me, so what are some common solutions to solving these sort of "command not found" Terminal problems?
The .sh is for *nix systems and .bat should be for Windows. Since your example shows a bash error and you mention Terminal, I'm assuming it's OS X you're using.
In this case you should go to the folder and type:
./startup.sh
./ just means that you should call the script located in the current directory. (Alternatively, just type the full path of the startup.sh). If it doesn't work then, check if startup.sh has execute permissions.
This is because the script is not in your $PATH. Use
./scriptname
You can also copy this to one of the folders in your $PATH or alter the $PATH variable so you can always use just the script name. Take care, however, there is a reason why your current folder is not in $PATH. It might be a security risk.
If you still have problems executing the script, you might want to check its permissions - you must have execute permissions to execute it, obviously. Use
chmod u+x scriptname
A .sh file is a Unix shell script. A .bat file is a Windows batch file.
Type bash script_name.sh or ./script_name in linux terminal. Before using ./script_name make you script executeable by sudo chmod 700 script_name and type script_name.bat in windows.
Drag-And-Drop
Easiest way for a lazy Mac user like me: Drag-and-drop the startup.sh file from the Finder to the Terminal window and press Return.
To shutdown Tomcat, do the same with shutdown.sh.
You can delete all the .bat files as they are only for a Windows PC, of no use on a Mac to other Unix computer. I delete them as it makes it easier to read that folder's listing.
File Permissions
I find that a fresh Tomcat download will not run on my Mac because of file permission restrictions throwing errors during startup. I use the BatChmod app which wraps a GUI around the equivelant Unix commands to reset file permissions.
Port-Forwarding
Unix systems protect access to ports numbered under 1024. So if you want to use port 80 with Tomcat you will need to learn how to do "port-forwarding" to forward incoming requests to port 8080 where Tomcat listens by default. To do port-forwarding, you issue commands to the packet-filtering (firewall) app built into Mac OS X (and BSD). In the old days we used ipfw. In Mac OS X 10.7 (Lion) and later Apple is moving to a newer tool, pf.
Based on IsmailS' comment the command which worked for me on OSX was:
sudo sh ./startup.sh
On windows type either startup or startup.bat
On unix type ./startup.sh
(assuming you are located in tomcat/bin directory)
Batch files can be run on Linux. This article explains how (http://www.linux.org/threads/running-windows-batch-files-on-linux.7610/).
Type in
chmod 755 scriptname.sh
In other words, give yourself permission to run the file. I'm guessing you only have r/w permission on it.
add #!bin/bash on top of the your .sh file
sudo chmod +x your .sh file
./your.sh file
these steps work~
My suggestion does not come from Terminal; however, this is a much easier way.
For .bat files, you can run them through Wine. Use this video to help you install it: https://www.youtube.com/watch?v=DkS8i_blVCA. This video will explain how to install, setup and use Wine. It is as simple as opening the .bat file in Wine itself, and it will run just as it would on Windows.
Through this, you can also run .exe files, as well .sh files.
This is much simpler than trying to work out all kinds of terminal code.
I had this problem for *.sh files in Yosemite and couldn't figure out what the correct path is for a folder on my Desktop...after some gnashing of teeth, dragged the file itself into the Terminal window; hey presto!!

Whats different when you executable a scripts in OSX?

I have a question I have been trying to fix for a while. I want to understand what's the difference between starting a script from the command line and making it executable and then running it from the Finder.
Because this is what I am experiencing;
I have a simple script called trash-files which contains this command:
trash ~/Downloads/*
When I run from the terminal it works as expected; however if I doubleclick the shell script in the finder I see this:
/Users/xx/Desktop/trash-files: line 1: trash: command not found
I hope anyone can tell me why this doesn't work as expected
trash is not a standard command in OS X. Is it something defined in your ~/.profile or a similar file? If so, these are not run for non-login shells, such as those created to run a script.
If you're using homebrew, you could run
brew install trash
which would install the necessary scripts to have the trash command work in the way you're expecting.
There is a folder in your home folder location called
.Trash
The "dot" in front of the folder name makes it hidden while searching for it in finder. You'll have to use Terminal to execute the following command:
cd ~/
ls -la
This will change the directory to the current logged in users home folder, then second command will list files and show hidden files. You can then run:
rm .Trash/*
This will remove everything inside the Trashcan on the dock.
So open TextEdit from the /Applications folder, go to "Format" and make it "Plain Text". Paste in the two lines below.
#!/bin/sh
rm ~/.Trash/*
Save the file as "emptyTrash.sh" (uncheck use txt extension). Save it to your Desktop or wherever you'd like. Then open Terminal, cd (change directory) to where the files is and run this command to make the script executable:
chmod +x emptyTrash.sh
Then you can execute the script by cd (changing directory) to path where the script is, and run:
./emptyTrash.sh
That's it.

where is ~\.vim folder in mac os? and how to install themes in gvim?

I downloaded color sample pack from http://vim.sourceforge.net/scripts/script.php?script_id=625
it says i should unzip and place it into ~/.vim but where is this folder? I tried unzip it to my usr/share/.vim folder but it is not working, I don't see themes added to gvim Edit>color scheme menu, and i tried "colorscheme sometheme", "color sometheme" in my gvimrc. Both not working for new themes
Isn't the ~/.vim should be the .vim folder in use/share? or I should create a new folder under home?
Note:there is a folder vim73 in my .vim, I guess this doesn't affect anything
thanks for any help!
First of all, open vim, and get help from :help colorscheme
:colo[rscheme] {name} Load color scheme {name}. This searches 'runtimepath'
for the file "colors/{name}.vim. The first one that
is found is loaded.
After reading the manual above.
Take the following steps maybe help you:
find runtimepath
:set runtimepath?
It will print out run-time paths:
runtimepath=~/.vim,/usr/share/vim/vimfiles,/usr/share/vim/vim71,/usr/share/vim/vimfiles/after,~/.vim/after
create directory called colors under one of them if not exist(for example: ~/.vim)
$ ls ~/.vim
ls: cannot access /root/.vim: No such file or directory <== we need create it!!!
$ mkdir -p ~/.vim/colors
copy your color.vim to your colors directory
$ cp /path/to/your/color.vim ~/.vim/colors
restart vim to use new colorscheme
:colorscheme color
(optional) put command above to ~/.vimrc file to make it permanent
In UNIX parlance, ~ represents your home folder which is /Users/<username> in Mac OS X.
You are supposed to put all your custom scripts/colorschemes/whatever in a .vim folder situated in your home folder. In Terminal.app, type each line (without the $) then hit Enter:
$ cd
to be sure you are in your home folder
$ mkdir .vim
here you'll have an error message if ~/.vim already exists; if you don't receive a message it means that the folder is created
$ cd .vim
to move into it
$ open .
to open a Finder window here. At this point you should follow specific indications.

How can I cd to an alias directory in the Mac OSX terminal

Is there a way to get into an alias directory from shell with the command "cd" ? It always returns that "htdocs" isn't a directory.
Edit: I made the shortcut with the OS GUI -> rightclicked the htdocs directory and chose "Alias..." (i'm using a german OS if it's not alias maybe it's called shortcut in english?) then i moved it to my home directory (because my terminal starts from there when i open it).
All i want is to open my terminal and type "cd htdocs" so that i can work from there.
you can make symbolic link to it.
ln -s EXISTING_PATH LINK_NAME
e.g.
ln -s ~/Documents/books ~/Desktop/
Reference
Enter into a directory through an alias in Mac OS X terminal
All i want is to open my terminal and type cd htdocs so that i can work from there.
The easier approach is probably to ignore the links and add the parent directory of your htdocs directory to the CDPATH environment variable. bash(1) will check the contents of the CDPATH environment variable when you type cd foo to find the foo directory in one of the directories listed. This will work no matter what your current working directory is, and it'll be easier than setting symbolic links.
If the path to your htdocs is located /srv/www/htdocs/, then you could use CDPATH=/srv/www. Then, cd foo would first look for /srv/www/foo/ and change to it if it exists; if not, then it would look for foo in the current working directory and change to it if it exists. (This might get confusing if you have multiple htdocs directories on your system; in that case, CDPATH=.:/srv/www would let you change into a child directory easily but still use the /srv/www/htdocs/ version if no ./htdocs directory is present.)
You can add the CDPATH=/srv/www line to your ~/.bashrc file so it works every time you start a terminal.
I personally use this to quickly work in the directory which is present deep inside one of my Volumes in my Mac.
Open your ~/.bash_profile, create an alias to the directory by adding this:
alias cdh="cd /Volumes/Haiku/haiku/src/apps/superprefs"
Save it, restart your terminal. Now on typing cdh in your terminal should change the working directory to the one mentioned as the alias.
I am not sure how OSX exposes Alias links but since you are using bash you can just create a variable in your .bashrc file.
On its own line put:
htdocs=YourDirectoryPath/
Once you have restarted bash you can just type cd $htdocs
There is a old hint on macworld to do this in a way that is integrated with BASH: Enable 'cd' into directory aliases from the Terminal
Plus, here is an answer that uses this solution on superuser.
You may be able to use osascript to do this -- this command seems to work:
cd "`osascript -e "on run aFile" -e "set aFile to POSIX file aFile as alias" -e "tell application "\""Finder"\"" to return POSIX path of ( ( original item of aFile ) as text ) " -e "end run" path_to_my_Finder_alias 2>/dev/null`"
Basically this command is running an AppleScript that finds the destination path of the argument (path_to_my_Finder_alias) in a subshell, then wraps it in double quotes, and changes the directory to it.
Maybe someone with a little more bash expertise can turn it into a bash alias or function.
try:
alias cdgo=`echo cd /root/go/`
cdgo will run, then get command "cd /root/go/" and enter, and it will change your directory in current terminal process
It works on my centos, no test with osx

Resources