Jiang Li, Ph.D.
Department of Computer Science
CSCI 211
UNIX Lab
Basic Unix Commands (1)
Dr. Jiang Li

Jiang Li, Ph.D.
Department of Computer Science
Today’s Focus
•System login
•Directories and files
•Basic commands (directory and file related)
–id, passwd
–ls, chmod
–man
–cd, pwd

Jiang Li, Ph.D.
Department of Computer Science
Logging in
•Connecting to a remote machine:
–We’ll connect to the Linux Server via SSH
(available in putty)
–The server’s address is 138.238.148.14
–After connection, you are presented with a login
prompt
–Input your username and password to login
–After logging in, you’re placed in your home
directory(where your personal files are located)

Jiang Li, Ph.D.
Department of Computer Science
Putty Connection Interface
•Input the server’s
address in ‘Host Name’
text box
•Choose SSH as the
connection type
•Use the default port
number 22
•Click ‘Open’ button to
connect to the server

Jiang Li, Ph.D.
Department of Computer Science
The Command Prompt
•After you login, you will see the command promptat beginning of each line
•You can type your commands after the command prompt
•A command consists of a command name and some option(s) called flag(s)
•In Unix and Linux, everything (including commands) is case-sensitive.
Command promptCommand(optional) flags(optional) arguments

Jiang Li, Ph.D.
Department of Computer Science
idCommand
•Users and Groups
–Linux is a multi-user/group system
–Each user belongs to one or more groups
–Each group contains one or more users
•id
–Get the information of the login account
•User’s id, username, group id and group’s names that the user belongs to
–Example
[prompt] $ id
uid=51931(hguo) gid=14082(cgroup761)
groups=14082(cchome761),16207(admin_nonprod),16210(admin_
prod)

Jiang Li, Ph.D.
Department of Computer Science
Setting a Password
•passwdcommand
–You can use passwdto change/setting a password for
your account
–You need to input your old password for authentication,
then input your new password two times
–Example
[prompt] $ passwd
Changing password for hguo.
Enter login(LDAP) password:
New password:
Re-enter new password:

Jiang Li, Ph.D.
Department of Computer Science
Directories
•In Unix, files are grouped together in places called directories,
which are analogous to foldersin Windows
•Directory paths are separated by a forward slash: /
–Example: /home/scs/howard
•The hierarchical structure of directories (the directory tree)
begins at a special directory called the root, or /
–Absolute paths start at /
•Example: /home/robh/classes/sycs211
–Relative paths start in the current directory
•Example: classes/sycs211(if you’re currently in /home/robh)
•Your home directory “~” is where your personal files are
located, and where you start when you log in.
–Example: /home/yourusername

Jiang Li, Ph.D.
Department of Computer Science
Directories (cont’d)
•Following symbolshave special meanings you need
to know
–~: Your home directory
–..: The parent directory
–.: The current directory

Jiang Li, Ph.D.
Department of Computer Science
Files
•File is a logical unit used to store user’s and/or system data
•Ultimately, Linux is a collection of files stored on the hard disk
•Filename
–Unix filenames are much like the filenames on other OS.
–But unlike Windows, Unix file types (e.g. “executable files, ” “data
files,” “text files”) are not determined by file extension (e.g. “foo.exe”,
“foo.dat”, “foo.txt”)
•Many file-manipulation commands use only 2 letters
–e.g., ls, cd, cp, mv, rm, nl, etc.

Jiang Li, Ph.D.
Department of Computer Science
List the Content
•lscommand
–One of the most frequently used command
–LiSts the contents (and their attributes) in a
specified directory (or the current directory if no
arguments are specified)
–Syntax: ls [<args> … ]
–Example: ls backups/
•List the contents in ‘backups’ directory

Jiang Li, Ph.D.
Department of Computer Science
The lsCommand with -l
•ls –l
–This command gives more information about the files
present in the current directory.

Jiang Li, Ph.D.
Department of Computer Science
Notes on access permissions
•Example: (a) drwxrwxr--
(b) -rwxr-x---
•First character: directory (d) or file (-).
•Then, 3 groups of 3 letters (total 9 letters)
–Owner’s permission, Group member’s, Others’
•Within each group
–Readable (r) / Writable (w) / Executable (x)
–No permission is represented by a dash (-)

Jiang Li, Ph.D.
Department of Computer Science
Notes on access permissions
•Example
-rwxrwxrwx
•Everybody can read, write and execute the file
•Lowest security, highest accessibility
-rw-------
•Only the owner can read and write the file
•Highest security, lowest accessibility

Jiang Li, Ph.D.
Department of Computer Science
chmod-Modify Permissions
•Syntax:
chmod [OPTION] mode FILE/DIR
•Examples:
–chmod u+rwx myfile
•chmod go-w mydir
–Remove write permission on group&others for mydir
directory
r: readable
w: writeable
x: executable
u: user
g: group
o: others
+: assign
-: remove

Jiang Li, Ph.D.
Department of Computer Science
The lsCommand with -a
•ls –a
–Using (-a) flag shows allfiles/sub-directories,
including visible files and invisible files
–Invisible file’s filename start with dot sign
•e.g.: .profile, .bashrc, ., ..

Jiang Li, Ph.D.
Department of Computer Science
Getting help with man
•man(short for “manual”) documents for commands
–man <cmd> retrieves detailed information about <cmd>
–man –k<keyword> searches the short descriptions and manual
pages for keyword(faster, and will probably give better results)
fiji:~$ man –k password
Passwd (5) -password file
xlock (1) -Locks the local X display
until a password