Tcsh notes
From raju
get the last word of the previous command
Use !$ to get the last word of the previous command, !* to get all arguments of the previous command. For example
> cat junk.txt abc aBc aBC >grep abc junk.txt abc >grep aBc !$ grep aBc junk.txt aBc >grep -i !* grep -i aBc junk.txt abc aBc aBC
tags | word designators
Machine hangs after logging in
Issue:- After logging into a Linux machine via ssh, the connection hangs after successful login.
Using username "XXXX".
Authenticating with public key "YYYYYYYYYY"
Last login: Fri Sep 26 22:58:42 2014 from ZZZ.ZZZ.ZZZ.ZZZ
If I press ctrl-c, I am logged in. Same thing happens if I try to exit (the exit command succeeds, but the connection is not closed until I press ctrl-c).
I am running tcsh shell on the Linux machine. The problem persists even after moving ~/.cshrc
=> mv .cshrc .cshrc_raju_20140925
Solution:- Fixed the issue by (re)moving .history file
=> mv .history .history_raju_20140925
Further Reading:
- man tcsh -> section on "Startup and shutdown"
Colors in ls
Add the following lines to ~/.cshrc
set color alias ls 'ls -F --color'
Then source it.
source ~/.cshrc
Running ls after this will display colors.
Further Reading:
- "Unix Power Tools" 3rd edition, section 8.6
which is also available at http://docstore.mik.ua/orelly/unix3/upt/ch08_06.htm
set environment variable
Create a script
=> cat host.tcsh set host=`hostname` set username=`whoami` setenv hu ${username}@${host}
source it
=> source host.tcsh
Test it
=> echo $hu rajulocal@hogwarts
check if a file exists
if ( -f file.txt ) then echo "$foo exists" else echo "$foo does not exist"
Weird characters when reverse searching
<CTRL-r>, right arrow results in weird characters - http://unix.stackexchange.com/questions/158913/tcsh-i-search-back-character-glitch
The solution is to use ESC to end the search. For example control-r, some characters to reverse search in the command history, escape key.
String manipulation
http://xwfaivre.blogspot.com/2011/07/csh-string-manipulation-length.html describes it well.