Week 1:Video and wiki links to setup your environment:
If you use a recent version of Windows 10 or MacOS or Linux, you can access the CS server using the ssh client via a terminal (command prompt) window:
where
This is normal, just say yes and continue to the password prompt and enter the password you've been provided to login:
You will not see anything as you type, this is a normal security measure to prevent any onlookers from seeing how long your password is. Unix commands: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:
Reading from left to right, includes your username
Your prompt can be modified by editing the The commands you will be expected to know and use in this class are in brief:
Changing your password: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...
Get help on
|
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 |
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]
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
-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
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 ofrw
orx
then there is no permission allowed for that kind of access. i.e. if you seer-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.
> tree
[directory]
Display a indented directory tree.
Examples:
tree ~
tree /
Ctrl-C
key combination on your keyboard.> cd
[dir]
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.
examples | |
---|---|
cd |
Changes to your home directory |
cd ~ |
Same thing |
cd .. |
Moves to the parent directory |
cd / |
Moves to the root file-system directory. |
> 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. ~
useruser'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":
/
), and absolutely
define the location of a file or directory in the file-system regardless of what
the users current working directory is.> cp
[-r
] source... destination
-r
= Copy files/directories recursively. This will copy a directory and its
entire contents to the destination. You cannot normally copy a directory
without this option.
Examples cp -r dir1 dir2 ~/dest/
Recursively copies all of dir1
anddir2
into the directorydest
in your home directorycp a.txt b.txt
Copies a.txt
asb.txt
cp a.txt b.txt c
Copies text files a.txt
andb.txt
to directoryc
.
> mv
source... destination
Examples: mv a.txt b.txt
Renames a.txt
asb.txt
mv a.txt b.txt c
Moves a.txt
andb.txt
into directoryc
.
> rm
[-r
] file...
-r
= Recursively remove files and directories. DANGEROUS.
Examples rm a.txt b.txt
Removes the files a.txt
andb.txt
.rm -r c
Completely removes the directory c
.
> mkdir
[-p
] directory...
-p
= Make parent directories if they don't exist.> rmdir
directory...
> cat
[file(s)]
> more
[file(s)]
> less
[file(s)]
Used to view files or the output of another program (if followed by the
pipe (|
) operator) one screen page at a time.
Examples: | |
---|---|
less file.txt |
Views the file file.txt one screen at a time |
ls -la | less |
Views the output of ls -la one screen at a time |
tree | less |
Output of the tree command one screen-full at a time |
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.
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 jovene 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
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.
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)...
Set permissions on file or files. Mode has two possible forms, octal (three, base-8 numbers) or ASCII:
Group (1+) | Mode (one of) | Permssions (0+) |
---|---|---|
u (user) | + (add) | r (read) |
g (group) | - (subtract) | w (write) |
o (other) | = (set equal to) | x (execute/search) |
a (all) | t (sticky bit) | |
s (setuid bit) |
-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--
.
examples:
chmod 755 ~/public_html
- Makes your public_html directory world accessible. 755 →
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 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 -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.
> ssh
[user@
]hostname
ssh cs25600@cs.indstate.edu
> sftp
[user@
]hostname
> rsync
[-a
] [-v
] source destination
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/
~/dir
on the machine cs.indstate.edu under the sbaker account.rsync -av sbaker@cs.indstate.edu:dir ~/
dir
in our
local home directory.> alias
alias-name command-to-actually-run
Defines a command alias where alias-name is replaced by command-to-actually-run
when alias-name is.
Examples:
alias d "ls -la"
d
will execute ls -la
. Any parameters following d
are appended to the real ls -la
command.alias df 'df -h'
-h
option.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.