I was following a Git course on Udacity and we made some changes to our bash profiles.
Somehow my .bash_profile is now recognized as a Unix executable file rather than a TextEdit document. I can still use it as before, but it bothers me that this change has happened. More than anything I would also like to know what is going on under the hood.
Where on my computer (I'm running MacOS) is the data stored that this is an executable? It doesn't have a file extension so how does the computer know? I changed its 'open with' field found in the 'get info' window but it still identifies as an executable.
in unix each file has permission bits which you can see with ls -l. In this case the 'x' bit has been set which means the file is executable. To revert the file back simply execute chmod -x on the file and it will unset the 'x' permission flag making the file a text file.
Related
-bash: export: /Users/deboadebayo/Desktop/Coding/:/opt/anaconda3/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin':
not a valid identifier
The above message is the error message I receive every time I open my terminal. I did create a backup of my bash profile. But essentially now I can no longer navigate anywhere I want to go using command line requests.
Any help would be much appreciated
If you have a backup, use an absolute path to the mv and cp commands to rename your broken file and restore the backup, both without depending on path lookup.
/bin/mv .bash_profile .bash_profile.broken
/bin/cp .bash_profile.backup .bash_profile
Close the current terminal window and open a new one, which should use your working, original .bash_profile to initialize PATH. Now you try to make the correct modification to your PATH.
oops. The easiest way to fix it would be to launch an editor with an absolute path. $PATH only specifies the locations in which the shell will search if told to execute a program relative (or no) path specified. The which program can search the path and shows the first executable found:
$ which vim
/usr/bin/vim
So if you're a vim user, you should be able to run /usr/bin/vim at the command line, and the path won't be relevant. Then you can fix your file in the editor. Looks like my osx machine also has nano if you'd prefer that editor. I don't think I installed it so it probably came shipped with osx I'm guessing:
$ which nano
/usr/bin/nano
If you want to revert to your backup, use cp, but specify it from its absolute position, /bin/cp:
$ /bin/cp first.txt second.txt
Obviously you'll want to change the file names on that one for it to work for you.
Currently I am in Mac OSX and when I try to find what my PATH is via Terminal, I get:
> echo $PATH
/Users/User1/google-cloud-sdk/bin:/usr/local
/bin:/usr/local/sbin:/usr/local/bin:
/usr/bin:/bin:/usr/sbin:/sbin:
/Library/TeX/texbin:/opt/X11/bin:
/Applications/Wireshark.app/Contents/MacOS
I would like to remove google-cloud-sdk, wireshark, and tex from PATH, but have no idea how to do it. When I look inside my etc/profile file, none of these apps are listed. Is there a way to clean up by $PATH? Thanks.
I just found the Wireshark path file in :
/etc/paths.d/
Go to your home directory. If you open a fresh Terminal window/session, this will probably have you in your home directory.
Type,
ls -al
This should give you a list of the files in your home directory, including invisible files. Check there is a file called .bash_profile. The "." means it is an invisible file.
If that exists (as it should) type:
nano .bash_profile
This will open this file in the text editor program called "nano". In this file you should find statements like:
export PATH="/Library/Frameworks ....
There should be similar PATH statement for the options you want to remove.
Delete those lines and then exit nano by ^O for writing out, and you need to print Y to save. Then ^X to exit nano.
I have been using the gvim command :w to save and it works fine saving it to the desktop. However with the vim program, when I use the command :w, I cannot find where the saved file is located.
It should save to whatever directory you started writing it in (you can see that in the command line). You can also use your computer's file search to locate it and then inspect for the file path.
As said by others: by default it saves in the directory where you started it. But if you aren't aware in which directory you started, then a way to find out is to use the :pwdcom in vim. This will output the current directory. That's where vim will store the file.
C:\Users\"windows user"\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\LocalState\rootfs\home\"WSL user"
Adding another answer to get the filename as well.
As mentioned by Cary and Jeen, vim saves your file to the directory from where it is started. You can get the directory where it is saved using :pwd.
If you are interested to get name of the file, it can be done by ctrl + g when your laststatus=1, which is the default value.
I usually set laststatus=2 which always show the filename.
I just started reading the Well-Grounded Rubyist, and I am just beginning to use Ruby in my terminal on my Mac.
I'm on the very first lesson, creating a Celsius to Farenheit converter in a text editor. I've saved the code as an .rb file by using Textmate (my text editor). The file name is c2f.rb. The file is saved in a folder on my desktop titled "Rubycode".
I am having difficulty running the .rb file in the terminal however. I've tried many different methods of trying to call the file, including using:
cd /Users/rexrose/Desktop/Rubycode/c2f
and many others.
Any thoughts on what exactly, I'm supposed to type into terminal in order to call the c2f file?
Thanks in advance.
I just started reading Well-Grounded Rubyist.
That's a very good book. I consider it more of an intermediate level book than a beginner book, but no matter.
I've tried many different methods of trying to call the file,
including using
cd /Users/rexrose/Desktop/Rubycode/c2f
The cd command means "change directories" and you cannot change directories to a file. Instead, you have to change directories to the directory containing the file:
$ cd /Users/rexrose/Desktop/Rubycode
Then you can execute your program contained in the file c2f.rb like this:
$ ruby c2f.rb
Here are some Terminal tips:
1) You can use ~ instead of /Users/YourUserName, so you can save some typing by doing this:
$ cd ~/Desktop/Rubycode
Typing '~' instead of '/Users/YourUserName' will become second nature.
2) Using the cd command with no arguments:
$ cd
will take you to your home directory, i.e. /Users/YourUserName
3) You should change your prompt to indicate what directory you are currently in. To do that, create a file called .bash_profile in your home directory(/Users/YourUserName). Check to see if it exists first:
$ cd
$ ls -al
The command ls -al will show all the files in a directory, including hidden files, which are files whose name begins with a .. If a file named .bash_profile exists, open it; if it doesn't exist, create it. Put this in .bash_profile:
PS1="\w$ "
To get Terminal to recognize the changes, you can either Quit Terminal and relaunch it, or do this:
$ source .bash_profile
Then open a new Terminal widow.
You can also add 'aliases' to .bash_profile. For instance, in my .bash_profile I have the alias 'r' for 'ruby', so that I can execute a ruby program like this:
$ r my_program.rb
In .bash_profile you make an alias like this:
alias r="ruby"
4) Tab completion in Terminal:
You might have noticed that you can type part of a file name, then hit tab and Terminal will complete the file name. Using tab completion, I can execute my ruby program like this:
$ r my_pr<tab>
In fact, I name my practice ruby programs so that I can use tab completion to the greatest effect. I have files named 1.rb, 2.rb, 3.rb, and then I execute one of them by simply typing:
$ r 1<tab>
And in fact, you may not even have to type that! If you hit the up arrow key on your keyboard, Terminal will display the previous command, and if you hit the up arrow key again, you will see the command before that. So you can scroll up to a previous command, then hit return to execute it--without having to type anything.
You should endeavor to use tab completion for each of the file names in a path. For example, if you are cd'ing to /Users/YourUserName/dir1/dir2, you should do this:
$ cd /Use<tab>/YourUser<tab>/di<tab>/di<tab>
The reason you should use tab completion for each filename(by the way in Unix filename is a general term for both directory names and file names) is because when the name won't tab complete, then you are in the wrong directory or you are trying a filename that doesn't exist in that directory. So instead of having to type out the whole path '/Users/YourUserName/dir1/dir2' and then finding out about the error when you hit return, the tab completion will let you know immediately when there is an error(because the filename won't tab complete)--saving you some typing.
5) Because you will probably be using Terminal for mostly ruby programs for awhile, you can set up things so that Terminal will automatically open up in your directory Users/rexrose/Desktop/Rubycode. Put this in .bash_profile:
cd "/Users/rexrose/Desktop/Rubycode" (Here you cannot use ~)
6) Occasionally, you may have to type a long file name that exists on your computer into the command line:
$ cd /Library/SomeLongName/AnotherLongName34832o222/142582dir/some_file.txt
Instead of having to type all that at the command line, you can locate the file in Finder first. Then if you drag the file onto the Terminal window, the file name will be entered at the point of the cursor.
Finally, a better way to organize your files might be to put them in directories below your home directory, like this:
~$ mkdir ruby_programs
~$ cd ruby_programs
~/ruby_programs$ mate 1.rb
First things first: cd stands for "Change directory".
Normally the terminal should open in "~", which is the home directory where most of your things are. In OS X it will be /Users/[username]. It's also possible possible that in OS X, it will save the location of the last session. I also recommend, since you're starting to install, "Iterm2", which is a nice terminal to use. It supports multiple tabs, etc.
Ruby, the interpreter, is the command "ruby". To call a script you have to call Ruby with a filename:
ruby /Users/rexrose/Desktop/Rubycode/c2f/c2f.rb
That is almost the equivalent of:
cd /Users/rexrose/Desktop/Rubycode/c2f/
ruby c2f.rb
It's almost equivalent, but for now the difference shouldn't bother you. Let say that the second way to call the script is more favorable than the first.
Now, the second thing: If you want to try things in Ruby, you can start an interactive shell. The command is "irb".
Type irb and Enter and then you can type Ruby code. If you want to leave, press CTRL+C multiple times.
The last thing, I recommend installing "RVM". It will save you time and pain, I hope. If you want to install Ruby gems, it will not mess with the Ruby already present with the system. That's my personal opinion but I believe lots of people will agree. Even if Ruby comes with OS X, you should install a different Ruby for development. It will make sure that if something goes wrong in dev, it will not mess the Ruby OS X might be using.
I can't figure out how to add a directory to the system path. I found out that the command is something like this:
export PATH=$PATH:/my_path/to/my_dir
Example
I run the terminal in the path where my installation directory is located. In this case I'm talking about Play Framework. And I type:
export PATH=$PATH:/to/play20
It looks like nothing happens. In fact, when I type the command "play" (to execute the framework) I get:
-bash: play: command not found
Can someone please give me a decent step-by-step guide?
Execute the command “/to/play20/play help”. If this gives the expected output (help for the play command), then the executable is available, and the problem is in the shell path. If it does not give the expected output, then the executable is not working.
In the former case, ensure you are running the bash shell. (This is the default for recent versions of Mac OS X, but it may be changed for specific accounts.) To do this temporarily, execute the command “bash”. (When you want to exit the temporary shell, execute the command “exit”.) Then execute the export command again. (When the export command works, it changes the variable without displaying any output, so this is normal.) Check the spelling in the export command carefully.
In the latter case, execute “ls -ld /to/play20/play”. If you get a message that the file does not exist, then the executable is not installed correctly, and I cannot help you further. If the file is present, then it is not executable for some reason. This might be because you do not have permission to access it (especially permission to execute it, marked by “x” in certain places in the initial field of the ls output that may contain hyphens, “r”, “w”, and a few other letters) or that it is a symbolic link to a file that does not exist (indicated by an “l” in the first character of the ls output for the file). Lack of permission can be fixed by the chmod command, assuming you have appropriate permissions for changing permissions on the system. If the file is a symbolic link to another file, you may have a bad installation, or the target file may have permission issues (or be another symbolic link, and so on).