The development environment for this class will be the Unix/Linux environment where the system is interacted with via the terminal command line interface. When using this interface commands are typed at a command prompt, which for most of you will look something like:
cs25600@cs:/u1/class/cs25600>
Reading from left to right, includes your username@host (the machine you're logged into, in this case, the CS server,) then a colon followed by the path of the current working directory, which is the file path to your home directory on the server. This path will change as you use the cd command to change your working directory. When specifying paths you can use the special character . (dot or period) to specify your current working directory (i.e. the directory displayed in your prompt.)
@
cd
.
/ └── u1 └── class └── cs25600
Where your home directory is inside of the class directory which is inside of the u1 directory which is located at the root of the file-system (/).
class
u1
/
Your prompt can be modified by editing the .cshrc file in your home directory, which is also the file to change if you want to permanently add aliases or change other aspects of your shell environment.
.cshrc
The commands you will be expected to know and use in this class are in brief:
Command What is does passwd Change your password * man Get help from the online manual * handin Assignment checkout and handin system * ls List files in a directory * cd Change your current working directory pwd Print current working directory path * cp Copy files and/or directories * mv Move/rename files and/or directories * rm Remove/delete files and/or directories * mkdir Make new empty directories rmdir Remove an empty directory cat Output a file or files to the screen * more View a file or output one screen at a time less Like more, but less * chmod Change file permissions
passwd
man
handin
ls
pwd
cp
mv
rm
mkdir
rmdir
cat
more
less
chmod
* = A command you should definately remember how to do/use.
*
A quick reference sheet for the above commands
To change your password, at a terminal prompt, type:
Unix commands are words (usually) separated by spaces terminated by a newline or semicolon (;) The first word is the "command" name, the words, if any, that follow it are its "arguments" or "command line parameters", that tell the command what it needs to do.
command-name additional-parameters...
-
-a
-r
--help
--version
>
You can get help on specific commands or topics using the Unix online manual, accessed via the man command. An optional section number can be inserted between the man command and the name of the command or topic you want to disambiguate between commands of the same name in different sections (for example there is both a Unix printf command (found in section 1) and the C printf function (found in section 3).
printf
man [section#] command|system-call|C_library_function|config_file|topic
Examples What you get man man Manual page for man itself man ls Manual page for the ls command man 3 printf Manual page for the C printf function
man man
man ls
man 3 printf
Your assignments will be checked out and submitted using the local handin system. You can read more about how to use handin via the CS wiki:
> ls [-a] [-l] [--help] [path]
> ls
-l
switches -a List all files, including hidden files: files beginning with a dot (.) -l Long listing
Examples: What you get ls Short listing of all non-hidden files in the current directory. ls -a Short listing of all files in the current directory. ls -l Long listing of all non-hidden files in the current directory. ls -l /etc Long listing of all the non-hidden files in the /etc directory
ls -a
ls -l
ls -l /etc
-rw-r--r-- 1 user group 283 Jan 13 18:52 file │╲ ╱╲ ╱╲ ╱ │ ╲________╱ File ╲__________╱ └─── File-name │ U G O │ │ Size └──────────── Last modified time │ perms │ └────────────────────────────── User and Group owners of the file │ └──────────────────────────────────── Hard link count (ignore it) └─────────────────────────────────────────────── File type
File types - A regular file (such as a text file, i.e. files that contain user data) d A directory (or folder) l A symbolic link (a pointer to another file/directory
d
l
There are other file types, but as a normal user, we are not concerned with those.
Permission groups U User permissions (used if the owner is accessing the file) G Group permissions (used if a group owner is accessing a file) O Other permissions (used in all other cases)
Permissions are scanned from left to right and the first permission group that applies is the permission group used to determine access to the file/directory. The permissions for each group are as follows:
Permissions within each permission group: Permissions are in the order rwx (Read/Write/Execute(search)), if there is a dash (-) instead of rw or x then there is no permission allowed for that kind of access. i.e. if you see r-x there is no write access allowed, but read and execute are allowed. Permissions r Readable (file can be read or a directory can be listed ) w writable / modifiable (file can be modified and files can be added/removed from directories x Executable (for files) / Search-able (directories, i.e. can 'cd' into) - There is no permission for this specific permission.
Permissions within each permission group:
rwx
rw
x
r-x
r
w
> tree [directory]
> tree
Display a indented directory tree. Examples: tree ~
tree ~
tree /
Ctrl-C
> cd [dir]
> cd
Change working directory. Your working directory (also referred to as . (dot)) is the starting point for all relative paths (i.e. paths that do not start with a slash (/)). It is also the directory that will be listed by ls by default.
cd ~
cd ..
cd /
> pwd
"file" What it represents / root file-system directory . Current directory .. Parent directory .* All "hidden" files (i.e. files starting with a dot (.), not normally listed unless -a option used.) ~ (tilde character) Your home directory. ~user user's home directory
..
.*
~
Paths are directories and/or a file separated by forward slashes (/). Slashes therefor cannot be in a file-name. There are two types of "paths":
> cp [-r] source... destination
> cp
Examples cp -r dir1 dir2 ~/dest/ Recursively copies all of dir1 and dir2 into the directory dest in your home directory cp a.txt b.txt Copies a.txt as b.txt cp a.txt b.txt c Copies text files a.txt and b.txt to directory c.
cp -r dir1 dir2 ~/dest/
dir1
dir2
dest
cp a.txt b.txt
a.txt
b.txt
cp a.txt b.txt c
c
> mv source... destination
> mv
Examples: mv a.txt b.txt Renames a.txt as b.txt mv a.txt b.txt c Moves a.txt and b.txt into directory c.
mv a.txt b.txt
mv a.txt b.txt c
> rm [-r] file...
> rm
Examples rm a.txt b.txt Removes the files a.txt and b.txt. rm -r c Completely removes the directory c.
rm a.txt b.txt
rm -r c
> mkdir [-p] directory...
> mkdir
-p
> rmdir directory...
> rmdir
> cat [file(s)]
> cat
> more [file(s)] > less [file(s)]
> more
> less
Used to view files or the output of another program (if followed by the pipe (|) operator) one screen page at a time.
|
less file.txt
file.txt
ls -la | less
ls -la
tree | less
Keys (when viewing a file or man page): Key What it does q or Q Quit space Go to next page p or P Go to previous page Arrow-keys Move up/down/left/right /text Search for text in the document / Repeat last search.
Keys (when viewing a file or man page):
Text mode editors are editors that can be used in the terminal and do not require a graphical user interface. Those available are:
Editors vi / vim Use vimtutor to learn vim. emacs / jove Emacs based editors. Use teachjove to learn jove ne The nice editor, use the escape key (twice) or F1 to pop up a drop-down menu system nano / pico Includes simple menu at bottom, easy to learn and use. In the nano/pico menu's the ^ represents the Ctrl-key, so ^X -> Ctrl-X
vimtutor
teachjove
I recommend ne, jove or vim over nano or pico which are OK text editors, but not really geared toward source code editing. ne is probably the easiest to pick up as you need only remember to hit the escape key twice or F1 (if that works with your terminal setup) to bring up a drop-down menu to access the editors functions, it also includes nice features such as code highlighting / colorization and auto code indentation functionality.
ne
jove
vim
nano
pico
Graphical editors:
Editors kate Primarily a graphical Linux code/text editor, also available for Windows komodo Like kate, but lets you display HTML in a sub-window, cross-platform: Download atom Another cross-platform graphical editor. Download
You will need to use an editor to edit C source files and other text files for this class. You should invest some time in learning to use a good code editor which has things like code syntax highlighting and auto formatting.
We likely will not be needing to change the permissions of files or directories in this class often, but occasionally it may be necessary to do so. We can do this with the chmod command.
> chmod [-R] mode file(s)...
> chmod
-R
Set permissions on file or files. Mode has two possible forms, octal (three, base-8 numbers) or ASCII:
-R = Set permissions recursively (i.e. set the permissions on a directory and all its contents.)
Octal permissions expicitly set the permissions on a file. To compute the octal permissions you need three octal numbers (in the range 0-7,) one for each permission group. Each octal value is computed based on the which permissions are set:
Permission Value r 4 w 2 x 1 - 0
Thus: rwx is 7 (4+2+1), r-x is 5 (4+0+1) and r-- is 4. Thus 754 → rwxr-xr--.
r--
rwxr-xr--
examples:
chmod 755 ~/public_html Makes your public_html directory world accessible. 755 → rwxr-xr-x
chmod 755 ~/public_html
rwxr-xr-x
chmod ug=rw,o=r file Makes file read/write for user and group and read only for everyone else. Note that there is no spaces anywhere in the mode field, only commas (,) separating permission groups.
chmod ug=rw,o=r file
,
chmod a+x file Makes file executable for everyone. Also note that the mode must come immediately after the chmod command itself, i.e. it needs to be the first parameter, it cannot come after the names of the files to be modified.
chmod a+x file
chmod -R og= dir Removes other and group access to all the files in the directory dir. Note that any permission group not modified is left as-is. This is not possible to do when using an octal mode.
chmod -R og= dir
dir
> ssh [user@]hostname
> ssh
ssh cs25600@cs.indstate.edu
> sftp [user@]hostname
> sftp
> rsync [-a] [-v] source destination
> rsync
-v
Keep two directories in sync (transfers only changed files.) Source and or destination may be a local directory path or a remote path in the form: [user@]hostname:[remote-file-path] -a = archive mode (keeps permissions, timestamps and ownerships in sync as well) -v = Verbosity (shows what it is doing)
:
Examples: rsync -av . sbaker@cs.indstate.edu:dir/
rsync -av . sbaker@cs.indstate.edu:dir/
~/dir
rsync -av sbaker@cs.indstate.edu:dir ~/
> alias alias-name command-to-actually-run
> alias
Defines a command alias where alias-name is replaced by command-to-actually-run when alias-name is. Examples: alias d "ls -la"
alias d "ls -la"
alias df 'df -h'
-h
To avoid using an alias you can use a backslash (\) at the beginning of the command to use the real command instead of an alias for that command.
\
To make an alias permanent you will need to edit your ~/.cshrc file with a text editor and add the new or changed alias to it.
~/.cshrc