This self-directed tutorial is mainly for people who have none or very little experience in Linux system, particularly for Windows users who want to migrate to SHARCNET Linux systems. Examples shown in the lightgrey areas were run on 'narwhal', a SHARCNET cluster. We hope that this tutorial would be a good starting point for newcomers to Linux.
Back to IndexLinux is a free Unix-type operating system originally created by Linus Torvalds with the assistance of developers around the world in the 90's. Linux is becoming popular as a powerful, low-cost operating system for cluster servers.
Linux Features
|
[jemmyhu@nar316 ~]$ hostname |
|
[jemmyhu@nar316 ~]$ whoami |
[jemmyhu@nar316 ~]$ pwd |
[jemmyhu@nar316 ~]$ date |
To change your Linux account password, use the command passwd
[jemmyhu@nar316 ~]$ passwd |
If you type your old password and a new password correctly, the new one becomes valid.
NOTE: you can change your SHARCNET password on the SHARCNET webportal.
Back to Indexls displays the names of all files and subdirectories in the working (current) directory. |
|
ls -l shows the detailed information of the contents (permissions, owners, size, and timestamp). |
|
ls -a shows all subdirectories and files, even files that are hidden (these files begin with a dot.) |
[jemmyhu@nar316 ~]$ ls -a . Courses .octave_hist test_g03 .. Dakota Octave_matlab test_mpiPWSCF adf2007.01 .ddt OpenMP_Summer07 util adf2007.01.pc64_linux.hpmpi.bin.tar .ddt_session .pathscale .viminfz.tmp .assistant debugger .rpmmacros work awk_example fftw_test scratch .Xauthority .bash_history HU script .bash_logout .lsbatch .sq .bash_profile Matlab .ssh .bashrc mpi test_g03 bin .nodelist test_mpiPWSCF |
mkdir my_dir my_dir is the name of a newly created directory, a subdirectory of the current directory.
rmdir my_dir remove my_dir if it is empty. If my_dir is not empty, use rm -r my_dir
cd | Change to your home directory |
cd .. | Change to the parent directory |
cd Directory | Change to directory |
[jemmyhu@nar317 ~]$ cd |
more File |
less File |
cp File NEWFILE | Copy FILE to NEWFILE in the same directory. |
cp /home/jemmyhu/File . | Copy FILE from /home/jemmyhu to the current directory. |
cp -r DIR NEWDIR | Copy DIR and all its contents to NEWDIR. |
mv File NEWNAME | Rename FILE to NEWNAME in the same directory. |
mv File DIR | Move FILE to existing directory DIR. |
mv DIR NEWDIRNAME | Rename DIR to NEWDIRNAME |
rm File | Remove FILE in the current directory. |
rm b*p | Remove all files beginning with b and ending with p in the current directory. |
rm * | Remove all files in the current directory |
rm -i * | the system will ask for permission before removing each file. |
rm -r DIR | Remove DIR and its entire contents. |
[jemmyhu@nar316 work]$ file README |
diff File_1 File_2 | Show differences between two versions of a file. |
find File(s) | Search current dir and its subdirs for FILE(S). |
find /usr -name "lpr" -print | Find a file lpr in directory /usr and its subdirectories. |
[jemmyhu@nar316 ~]$ find /usr -name "lpr"
-print |
ps -u username | List all your processes. |
|
kill -9 PID | Stop a process with process NO. PID before it has been finished normally. |
time executablecode | Display the time used to run executablecode. |
[jemmyhu@nar316 ~]$ time ./pi-serial |
|
[jemmyhu@nar316 ~]$ which cc |
|
|
du -sh DIRECTORY | Display only the total disk usage of DIRECTORY (in MB). |
|
chmod who=permissions Filename | Gives 'who' the specified permissions for a given filename. |
chmod who=permissions DIR | Gives 'who' the specified permissions for a given directory. |
Operator = is used to set up permissions | |
To add permissions, use + | To take away permissions, use - |
|
|
EXAMPLES: [jemmyhu@nar316 work]$ ls -l README -rw------- 1 jemmyhu jemmyhu 342 Nov 7 14:17 README The letters written from the 2nd to the 10th column are for file permissions. The first three columns are permissions for the user, the columns 5, 6, 7 for the user's group, and the last three for other users. In the above example, user (jemmyhu) has read and write permissions on file 'README', but no permissions for the group and others.
Here are some examples to change the permissions on
file 'README': |
vi (visual editor) is the default editor that comes with the UNIX/Linux operating system. Alternate editors for UNIX environments include nano (formerly named pico) and emacs (For basic emacs commands, see: http://www.cs.colostate.edu/helpdocs/emacs.html ) The vi editor is a full screen editor and has two modes of operation: 1. Command mode commands which cause action to be taken on the file, and 2. Insert mode in which entered text is inserted into the file. In the command mode, every character typed is a command that does something to the text file being edited; a character typed in the command mode may even cause the vi editor to enter the insert mode. In the insert mode, every character typed is added to the text in the file; pressing the Esc key turns off the Insert mode. While there are a number of vi commands, just a handful of these are usually sufficient for beginning vi users. Both UNIX/Linux and vi are case-sensitive. Be sure not to use a capital letter in place of a lowercase letter; the results will not be what you expect.Back to Index
vi Filename - Open Filename in command mode |
If Filename exists, the file will be displayed on the screen. If Filename does not exist, then an empty file is created for entering text. The screen looks like: ~ |
Keystrokes | Meaning |
---|---|
:x [Enter] | exit vi, save the modified file to file named |
:wq [Enter] | exit vi, save the modified file to file named |
:q [Enter] | exit vi |
:q! [Enter] | exit vi, without saving the modified file |
Keystroke | Meaning |
---|---|
i | insert text before cursor, until Esc key is pressed |
a | append text after cursor, until Esc key is pressed |
o | open a new line below current line, until Esc key is pressed |
Keystroke | Meaning |
---|---|
h | Cursor is moved one space to the left |
l | Cursor is moved one space to the right |
j | Cursor is moved one line down |
k | Cursor is moved one line up |
Keystroke | Meaning |
---|---|
r | Replace one character over the cursor |
R | Overwrite text until the keystroke of Esc |
Keystrokes | Meaning |
---|---|
x | delete single character under cursor |
dd | delete the current line |
Ndd | delete N lines, beginning with the current line |
Keystrokes | Meaning |
---|---|
yy | copy (yank, cut) the current line into the buffer |
Nyy | copy (yank, cut) the next N lines into the buffer |
p | paste the copied line(s) into the text after the current line |
Keystrokes | Meaning |
---|---|
^f | move down (forward) one screen |
^b | move up (backward) one screen |
^d | move down (forward) one half screen |
^u | move up (back) one half screen |
Keystrokes | Meaning |
---|---|
/string [Enter] | search forward for occurrence of 'string' in text |
?string [Enter] | search backward for occurrence of 'string' in text |
n [Enter] | move to next occurrence of search string |
:%s/oldstring/newstring/cg [Enter] | search 'oldstring' and replace it with 'newstring' in the entire file |
Keystrokes | Meaning |
---|---|
:.= [Enter] | returns line number of current line at bottom of screen |
:= [Enter] | returns the total number of lines at bottom of screen |
:set number [Enter] | provides the line number for the entire file |