Basic Unix Commands

Submitted By guohui
Words: 868
Pages: 4

Lecture2 – Basic Unix
Commands
Instructor: Hui Guo
Spring 2013

Today’s Focus
• System login
• Directories and files
• Basic commands (directory and file related)
– id, passwd
– ls, chmod
– cd, pwd

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) 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

The Command Prompt
• After you login, you will see the command prompt at 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 prompt

Command (optional) flags (optional) arguments

id Command
• 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)

Setting a Password
• passwd command
– You can use passwd to 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:

Directories
• In Unix, files are grouped together in places called directories, which are analogous to folders in 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

Directories - contd
• Following symbols have special meanings you need to know
– ~ : Your home directory
– .. : The parent directory
– . : The current directory

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.

List the Content
• ls command
– 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 [ … ]
– Example: ls backups/
• List the contents in ‘backups’ directory

The ls Command with -l
• ls –l
– This command gives more information about the files present in the current directory.

Notes on access permissions
• Example: (a) drwxrwxr-(b) -rwxr-x--• First character: directory (d) or file (-).
• Then, 3 groups of 3 letters