Note all of the "dot" . Unix Scp tips Assumption is HostA has ssh setup. 1) Say you want to copy a file from Hajek to hostA login hajek cd to folder you want to copy a file scp filename username@hostA.com:. (This will copy the file to your home dir on HostA machine) Copy a folder cd to a directory which contain the folder scp -r folder username@hostA.com:. This will create a new folder if the folder is not made yet. 2) Now you want to copy a file from hostA to Hajek while you are login Hajek a) Copy a file from your home directory in hostA scp username@hostA.com:filename . scp -r username@hostA.com:folder . (copy whole folder) b) Copy a file from a folder in hostA scp username@hostA.com:/folder_dir/filename . scp -r username@hostA.com:/folder/dir . (copy whole dir)
For Graphical sftp,
SSH Secure File Trans..." to open sftp;Quick Connect". A window titled "Connect
to Remote Host" will popup. Enter the Host Name and User Name. Then
click the "Connect" button.
To highlight multiple items, hold ctrl key when you use mouse to highlight items.
For command-line sftp, type
sftp username@hostname
to open connection to hostname. Once the connection is setup, the prompt
"sftp>" will wait for your input. Type
help
to get a list of commands available. For example,
| Command | Description |
|---|---|
put abc.txt | copy the file "abc.txt" in the
current directory to the home directory of the remote host your computer is connecting to.
|
get def.txt | copy the file "def.txt" in the home
directory of the remote host to the current directory of your computer. |
Not like ftp, sft does not have commands "mput" and
"mget". So each time you can copy only one file.
The following table lists sftp commands obtained by typing the command "help".
cd path Change remote directory to 'path' lcd path Change local directory to 'path' chgrp grp path Change group of file 'path' to 'grp' chmod mode path Change permissions of file 'path' to 'mode' chown own path Change owner of file 'path' to 'own' help Display this help text get remote-path [local-path] Download file lls [ls-options [path]] Display local directory listing ln oldpath newpath Symlink remote file lmkdir path Create local directory lpwd Print local working directory ls [path] Display remote directory listing lumask umask Set local umask to 'umask' mkdir path Create remote directory put local-path [remote-path] Upload file pwd Display remote working directory exit Quit sftp quit Quit sftp rename oldpath newpath Rename remote file rmdir path Remove remote directory rm path Delete remote file symlink oldpath newpath Symlink remote file version Show SFTP version !command Execute 'command' in local shell ! Escape to local shell ? Synonym for help
pwd (This normally give you answer "/home/faculty/username" ) Assume A is the folder you want to copy content over to new B folder. mkdir B (A nd B folder are both in /home/faculty/username level folder) cd B tar cvf - . | ( cd ../A ; tar xvf - ) or tar cvf - . | ( cd /home/faculty/username/A ; tar xvf - )
In short: recursive copy files/link and retain permision/date
mkdir newdir cd dir-to-be-tar tar cvf - . | (cd newdir ; tar xvf -)
Example: Transfer a folder from Hajek to Unixlab.
Login Unixlab first, cd to a folder you want to transfer stuff over.
ssh unixlab mkdir public_html/spring201 (If you need to make a new folder) cd public_html/spring2010 ssh www.stat.ubc.ca "cd /home/faculty/username/folder_to_be_transfer ; tar cf - . " | tar -xvf -
According to the GNU Midnight Commander User's Guide, the Midnight Commander is a directory browser/file manager for Unix-like operating systems. It has a user-friendly graphic interface. You can use it to
Currently, the servers Pascal, Fisher, and Pearson install this software. To run the software, type
mc
FAQ about mc can be found at http://cvs.gnome.org/lxr/source/mc/FAQ?raw=1. The article " The LO Newbie Tests Mouseless (Midnight) Commander" tells a little about the history of the Midnight Commander. An introduction to Midnight Commander can be found at http://www.linuxgazette.com/issue23/wkndmech_dec97/mc_article.html.
The following figure and table show how to convert file formats.
| Conversion | Software | free of charge? | available from dept? |
|---|---|---|---|
| LaTeX ->DVI | latex | free | Yes |
| LaTeX -> PDF | pdflatex | free | Yes |
| LaTeX -> html | latex2html | free | Yes |
| LaTeX -> word docs | Word2Tex | $$ | No |
| word docs -> LaTeX | Tex2Word | $$ | No |
| HTML -> LaTeX | html2latex | free | No |
| dvi -> ps | dvips | free | Yes |
| dvi -> pdf | dvipdfm | free | Yes |
| ps -> pdf | ps2pdf | free | Yes |
| pdf -> ps | pdf2ps | free | Yes |
| pdf -> word docs | Drake Plugin Software | $$ | No |
| word docs -> pdf | BCL easypdf 3.0 | $$ | No |
| word docs -> pdf | Adobe Acrobat | $$ | Yes (PC in mail room) |
| word docs (and ppt) -> pdf | OpenOffice.org | Free | Yes (ugrad?) |
| html -> pdf | Adobe Acrobat | $$ | Yes (PC in mail room) |
| pdf -> html | Intrapdf.com | $$ | No |
| various conversions to and from pdf | pdf995 | free | No |
| Dos -> Unix | dos2unix | free | Yes |
| Unix -> Dos | unix2dos | free | Yes |
Ispell is a spelling checker. To check spelling of a LaTeX file, type the command
ispell -t filename.tex
or simply
ispell filename.tex
Ispell will automatically use
TeX/LaTeX mode (the flag "-t") if the input file name has the extension
".tex", unless ispell is overridden by the
"-n" switch. More information on the usage of
ispell can be found by typing
man ispell
Examples:
tar cvf abc.tar a1.ps a2.tex adir/* # compress files to the file abc.tar
gzip -9 abc.tar /* # create abc.tar.gz file.
tar cvfz abc.tar.gz a1.ps a2.tex adir/* # directly create abc.tar.gz file
zip abc.zip a1.ps a2.tex adir/* # directly create abc.zip file
Note that -9 means the slowest compression method (best compression). By default,
-6 is used. -1 means fastest compression method (less compression).
The command zip is compatible with PKUNZIP on pc. Thus, the file
abc.zip can be uncompressed by WinZip.
Examples:
tar xvf abc.tar # uncompress abc.tar file
gunzip abc.tar.gz # after uncompress, get abc.tar
tar xvfz abc.tar.gz #unzip and utar *.tar.gz file
unzip abc.zip #unzip .zip file
Examples:
tar tvf abc.tar
tar tvfz abc.tar.gz
unzip -l abc.zip
To check your files in the directory /tmp, type:
cd /tmp
ls -lrt | grep yourlogin
To remove all your files which are more than 1 day old in the directory /tmp, type:
cd /tmp
find /tmp -user yourlogin -mtime +1 -exec rm -rf '{}' \; > /dev/null 2>&1
Note:
Send e-mail to sysman (help at stat dot ubc dot ca).
If the file has accidentally just been deleted (within a day), then you can try to restore it yourself.
Type command:
du -sh or du -h --max-depth=1 2> /dev/nullNote that there is no space between "2" and ">".
If you want to display file size according to the order of the file sizes, type:
du --max-depth=1 | sort -nNote that the above command may not work at hajek or newton. In this case, try pascal or fisher.
Syntax:
grep -v thepattern infile > outfile or fgrep -v thepattern infile > outfile
For example,
grep -v "hello" abc.txt > tmp.txt
Syntax:
grep thepattern infile > outfile
For example,
grep "hello" abc.txt > tmp.txt
To output the first and the third columns in the infile to outfile,
awk '{print $1, $3}' infile > outfile
For example, your data file like this:
Tom123
Mike345
William678
Type the unix command:
sed 's/\([0-9]\)/ \1 /g' infile > outfile
will generate output like this:
Tom 1 2 3
Mike 3 4 5
William 6 7 8
s/\([0-9]\)/ \1 /g is a regular expression.
s means "substitute"
The syntax is
s/beingreplace/substituecharacters/g
where g means to substitute in the "global" range,i.e. in the whole file range.
\([0-9]\) means any digit will be replaced.
\1 means any digit, 8 say, will be replaced by " 8 ", i.e. add a white space before and after the digit 8.