Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rlm22b

macrumors member
Original poster
Mar 8, 2008
38
0
Indiana
I recently decided that I wanted to learn more about Unix. I found this article and have been reading through it. It's pretty good thus far. I arrived at the part where they're discussing how to remove files and how you can customize terminal so that it prompts you before removal. I thought that would be good to have since I'm fairly new to Unix/Terminal. I inputted the command they gave but it will not work and I was wondering if anyone could help? Their discussion of the situation is below. Thanks in advance!

OSXFaqs.com said:
There is a hidden file in your home directory called '.tcshrc'. This is a configuration file used by the command line and is read each time a new Terminal is started up.

% cat ~/.tcshrc

will view it. You probably don't have one yet. We can make a new one, or add to the end of an existing one, to customise your command line experience.

If you would like the '-i' option permanently applied to cp, rm, and mv, type the following:

% echo "alias cp cp -i \\!\*" >> ~/.tcshrc
% echo "alias mv mv -i \\!\*" >> ~/.tcshrc
% echo "alias rm rm -i \\!\*" >> ~/.tcshrc

'echo' simply echoes what appears between the quotes. '>> ~/.tcshrc' says to add it to the end of the given file instead of echoing to the Terminal. We are adding lines to the '.tcshrc' file. Each is an alias that tells the command line to substitute 'cp', 'mv', and 'rm' with the text that follows.

Start a new Terminal by pressing cmd-N. When a new Terminal starts it reads the commands in '~/.tcshrc', in this case the three aliases. Now all three commands will be replaced with the '-i' versions given in the aliases, and thus always ask for confirmation before a file is overwritten or deleted.

% touch x y z
% rm x y z

If you wish to temporarily override '-i' when issuing a command, use option '-f'.

I guess I should have said specifically which commands weren't working.

I type:

% echo "alias cp cp -i \\!\*" >> ~/.tcshrc
% echo "alias mv mv -i \\!\*" >> ~/.tcshrc
% echo "alias rm rm -i \\!\*" >> ~/.tcshrc

and they are accepted with no errors but the changes never go into effect. I have opened new terminal windows and closed and reopened terminal.
 
Don't put the % sign at the beginning. No need to restart/log out or anything similar. This is Unix, not Windows. ;)

EDIT: Think I may be misreading the 2nd comment. So are the changes showing the .tcshrc or not? After rereading your post, I'm not sure if the changes aren't occuring in .tcshrc or if they aren't showing up for your commands.
 
Yes you'll need to log out and back in for the OS toy reread any config files
BUT
If you're using Leopard editing the .tcshrc file isn't going to affect anything. OS X hasn't used the tcsh shell in quite a while. Your changes should be made to the .bashrc file if anything.
 
Thank you all for the replies.

I tried to logout and log back in but that didn't work. I didn't use the %.

The changes are showing up in .tcshrc albeit one of the \'s before the ! isn't showing up for some reason.

I am using Leopard. .bashrc is a config file also? The .tcshrc file was not present in my home directly before I edited it with the commands. Nor was the .bashrc file. I tried:

% echo "alias cp cp -i \\!\*" >> ~/.bashrc

as well but it didn't work either.

I had an assigment for work to do on Matlab, which requires X11 to run. This was shot out as soon as the xterm window opened:

5129_913859600923_5258371_52352133_810130_n.jpg


Sorry I was too lazy to retype all of that and it wouldn't let me copy it. :)
 
Woo so many issues here..

That's because the bash shell uses .profile to store aliases.

Once you have the alias in the .profile, you can either open a new shell (which will inherit your alias) or source ~/.profile to re-read your .profile in your current shell. (or .bash_profile, but .profile is shorter. ;) )

As noted before, you're not typing the % symbol are you? That was just to note that it was a tcsh shell. Bash shells prompts end with $.

Alternately, you could just edit your .profile and add the alias in by hand.

And finally, in the bash shell, alias are written thusly:

alias shortcut="actual command"

e.g.,

alias lf="ls -laF"
 
Also, minor nit: in the case of the alias commands originally presented, you don't need to specify the token for the remaining command line arguments. In other words, the following, simpler alias command is sufficient:

Code:
% [b]alias rm rm -i[/b]

You only need to add those other tokens when fancier things are being done, say an alias that performs one command that does one thing and then pipes to another.
 
Come on folks, this isn't that hard.

Here is the command to use:

echo "alias q=\"quota -g\"" >> ~/.bashrc

The actual command line command would be:

alias q="quota -g"

But you have to use the "\" (escape character) to tell the system to not interpret the two middle quotes as closing the first quote.

Once you have the new alias in the .bashrc (or .bash_profile) file, you use the "source" command to get the shell to re-read the file. For example:

source .bashrc

Now the "q" command will execute "quota -g".

No need to log out or anything else....

S-
 
Hold on here folks, let's back up a minute for the OP:

That stuff in your original posting mentions ~/.tschrc. 'tsch' is a unix 'shell'. One of many unix shells. By default, Linux and OSX (and many other modern Unix OS) use the 'bash' shell. That means, ~/.tschrc is not looked at unless you changed your shell (don't unless you know what you are doing). I don't recommend following any guides that use "tcsh" or "csh" as the syntax can be different than using bash.

There are 2 configuration files you need to worry about when using bash:
~/.bashrc
~/.profile

There's also ~/.bash_profile, but you don't need to use it.

There is a difference in when one is read versus the other, but that is a more advanced topic. All you need to know now is that when you open up Terminal, ~/.profile is the file that is read and ~/.bashrc is NOT unless you force it to be read. There are other times when ~/.bashrc is read and not ~/.profile but you don't need to worry about that yet. If you want to learn more about this topic, try googling stuff about interactive shells vs non-interactive shells and login shells vs non-login shells. Or google "bashrc vs profile"

So, all this echo "alias ..." stuff goes in ~/.profile. You can do what many do and that is have .profile source .bashrc, but that is a more advanced topic as you should know when one is read vs the other if you start doing that.

So, put all of this alias stuff in your ~/.profile. If you change it, you have to re-read it. You can do this by either closing terminal and opening it back up or you can execute the following command:
$ source ~/.profile

The '$' is not typed. It represents your command prompt.

Now, all this echo "blah blah" >> ~/.profile stuff will work, but I recommend you get familiar with a command line text editor and start editing files directly so you can get more familiar with what is in them. There are lots to choose from. 'nano' should be installed by default and it is very easy to use.
 
Thank you all so very much for all your help thus far!

I entered:

$ echo "alias rm rm -i \\!\*" >> ~/.profile

No $ of course and the command was accepted.

However it still does not seem to be working. I opened a new terminal window and I also did the 'source ~/.profile' command. When I did the source command the the output from X11(below) when I started Matlab yesterday came up. And now is appearing at the beginning of all of my new Terminal windows.

-bash: alias: cp: not found
-bash: alias: cp: not found
-bash: alias: -i: not found
-bash: alias: !*: not found
-bash: alias: rm: not found
-bash: alias: rm: not found
-bash: alias: -i: not found
-bash: alias: !*: not found

Also, not sure if this is off topic. My IP address is showing up after a z and before ~ UserName$. What exactly does that mean? Or is it related to something I've done?
 
rlm22b,

Did you read what I wrote?? The bash shell does not use this format to set aliases:

alias q quota -g

It uses:

alias q="quota -g"

Until you get that right, nothing is going to work.

Look at my previous post again.

S-
 
It works!!! I did:

echo "alias rm=\"rm -i\"" >> ~/.profile

like you said Sidewinder and it finally went through. Though I am a little uncertain as to what the \ and ''s do exactly. It got rid of the erratic output at the beginning of each terminal window too thankfully. Thank you all for taking the time to help. I really appreciate it.

I guess my next task is to learn more about the different kinds of shells that msline mentioned.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.