Download presentation
Presentation is loading. Please wait.
1
Tutorial of Unix Commands
Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar/Hector Cen Spring 2018
2
Outline Introduction How to log in to the servers?
How to transfer files between your computer and the server? Unix basic commands
3
Outline Introduction How to log in to the servers?
How to transfer files between your computer and the server? Unix basic commands
4
What is UNIX? UNIX is an operating system which was first developed in the 1960s It is a stable, multi-user, multi-tasking system for servers, desktops and laptops There are many different versions of UNIX (or based in UNIX): Sun Solaris GNU/Linux MacOS X
5
The UNIX Operating System
Everything in UNIX is either a file or a process A process is an executing program identified by a unique PID (process identifier) A file is a collection of data. They are created by users using text editors, running compilers etc.
6
The Directory Structure
The full path to the file report.doc: "/home/its/ug1/ee51vn/report.doc" All the files are grouped together in the directory structure The file-system is arranged in a hierarchical structure, like an inverted tree. The top of the hierarchy is traditionally called root (written as a slash / ) In the diagram above, we see that the home directory of the undergraduate student "ee51vn" contains two sub-directories (docs and pics) and a file called report.doc. The full path to the file report.doc is "/home/its/ug1/ee51vn/report.doc"
7
Outline Introduction How to log in to the servers?
How to transfer files between your computer and the server? Unix basic commands
8
How to log in - Windows Download putty (SSH client) from latest.html PuTTY is a free implementation of Telnet and SSH for Windows and Unix platforms
9
Connect to the server The host is margay.cs.fiu.edu 1 2 3 4
10
Log in - Account information
Login as : Your FIU username Password : Your first initial + PantherID + Your last initial For example, Steven Jackson with PID should have password s j (if you haven’t already changed it)
11
How to log in - Macos Use the existing SSH client in macOS through Terminal by following the steps: - Search for Terminal from Spotlight, e.g., located on the upper right corner of your screen (or press Command+SpaceBar) - Open Terminal - Connect to the server margay.cs.fiu.edu using the following command: ssh - Type your password - Now, you are connected.
12
How to log in - Macos
13
Outline Introduction How to log in to the servers?
How to transfer files between your computer and the server? Unix basic commands
14
Transfer files to and from the server
You have several options: For Unix-like environments: scp command (secure copy) sftp (through Cyberduck application) For Windows environments: sftp (FTP through SSH) (Filezilla)
15
Transfer files to and from the server
Using scp: Syntax: scp file scp dest Example: $ scp Project1.docx It will copy the file Project1.docx from the local computer to the remote computer and store it in /home/bear-b/users/jdoe001 $ scp Project1/ It will copy the file script.sh from the remote computer to the local computer and store it in Project1 folder
16
Transfer files to and from the server
Using FileZilla (Windows): - Credentials
17
Transfer files to and from the server
Using FileZilla (Windows): - Accept unknown host’s key
18
Transfer files to and from the server
Using FileZilla (Windows): - Connected
19
Transfer files to and from the server
Using FileZilla (Windows): - To upload files to the server
20
Transfer files to and from the server
Using FileZilla (Windows): - File is uploaded to the server
21
Transfer files to and from the server
Using FileZilla (Windows): - To download files from the server
22
Transfer files to and from the server
Using FileZilla (Windows): - File is downloaded from the server
23
Transfer files to and from the server
Using Cyberduck (macOS): - Credentials
24
Transfer files to and from the server
Using Cyberduck (macOS): - Connected
25
Transfer files to and from the server
Using Cyberduck (macOS): - To upload files to the server
26
Transfer files to and from the server
Using Cyberduck (macOS): - File is uploaded to the server
27
Transfer files to and from the server
Using Cyberduck (macOS): - To download files from the server
28
Outline Introduction How to log in to the servers?
How to transfer files between your computer and the server? Unix basic commands
29
Commands about Files (1)
ls : list the contents of your current directory. Format Options -a : list all the files including the hidden ones -l : list not only the filenames but also the related info -t : list content sorted by modification time (newest first) ls [option] [directory][file]
30
Commands about Files (2)
ls : list the contents of your current directory. Format ~ (your home directory) Example: List all the files in your Documents folder ls ~/Documents/ ls [option] [directory] [file] Home directory Documents Desktop Downloads / …
31
Commands about Files (3)
File permission Example: ls –l Field1 : A set of nine permission flags Field2 : link count Field3 : owner of the file Field4 : group of the file Field5 : size in bytes Field 6-8 : Last modification date Field9 : file/folder name
32
Commands about Files (4)
chmod : change the permission flags of the files Format Examples chmod g+w myfile chmod g-rw myfile chmod –R g+rw myfile chmod [option] [types][+/-][types of permission] filename Who: u=user, g=group, o=other, a=all (default) Opcode: + means add permission - means remove permission = means assign permission and remove the permission of unspecified fields Permission r=Read, w=write, x=Execute
33
Example The sticky bit S should have always been called the "restricted deletion bit" given that's what it really connotes. When this mode bit is enabled, it makes a directory such that users can only delete files & directories within it that they are the owners of.
34
Commands about Files (5)
pwd : print out the current working directory cd : change directory cd . (.) means the current directory C (..) means the parent of current directory Cd cd with no argument will return you to your home directory cd . cd .. cd Use the commands cd, ls and pwd to explore the file system.
35
Commands about Files (6)
cp : copy files Format Options -i : It can be used to avoid overwriting the original file -r : Copy the folder and all the files and subfolders under it. cp [options] File1 File2
36
Commands about Files (7)
scp : securely transfer files between two Unix computers To: From: scp [options] local_dest scp [options] local_file
37
Commands about Files (8)
mv : move a file from one place to another or rename a file. Format mv File1 File2 *.txt : all the files ended with .txt
38
Commands about Files (9)
mkdir : create a directory Format rm : remove files or directories Option -i : ask before actually delete -r : delete the folders and all the files and subfolders under it mkdir directory_name rm [option] file1 file2 file3…
39
Commands about Files (10)
test : A command in Unix that evaluates conditional expressions. Format or The functions will return true if the object exist or the condition specified is true. File functions -d Filename : Filename is a directory -s Filename : Filename has a size greater than 0 -f Filename : Filename is a regular file test expression [ expression ] echo: print a message. It's a handy way to create customized output in your terminal
40
Commands about File’s contents (1)
cat : display the contents of a file on the screen Format head : display the first ten lines of a file to the screen tail : display the last ten lines of a file to the screen cat file1 head –n file1 tail –n file1
42
Commands about File’s contents (2)
wc : word count Format Options -w : find out how many words the file has -l : find out how many lines the file has -m: find out how many characters the file has wc [options] file
43
Commands about File’s contents (3)
grep : It searches files for the specified words or patterns. Format: Options: -c : Display the number of columns which satisfied the pattern. -i : Ignore case distinctions in both the PATTERN and the input files. -v : Invert the sense of matching, to select non-matching lines. grep [options] [pattern] file
44
Pipe: It treats the output the execution of one command as the input of the next command
A | B | C
45
Commands about Text processing (1)
cut : extract sections from each line of a file. Format Option -c : character -f : field -d “:” : delimiter (default is a tab) cut [options] [range] filename
46
Commands about Text processing (2)
Range N-M N- -M cut [options] [range] filename
47
Commands about Text processing (3)
awk: It is a text processing utility on Linux based operating systems. It provides an scripting language of its own. Format: Options: -F : specify the file separator -f : specify the file that will be processed. -v var=val : Assigns a value to a variable before execution of the program begins awk [options] [script] file
48
Commands about Text processing (4)
awk examples: Print the first column of the file latlonpts.txt, specifying the delimiter as ‘,’
49
Commands about Text processing (5)
awk examples: Assign main bulding as the value of the variable pattern. It can be later used to perform operations on text.
50
Commands about Text processing (6)
sort : sort lines of a text file or files Default : sort without any option will sort the file alphabetically Format uniq : remove duplicate adjacent lines from sorted file. sort [option] file
52
Redirection & Pipes (>, >>, <, |)
These are operators that allows us to control and/or redirect the commands output. We will focus on the following: >: Directs the output of the command to a file. >>: Appends or create the output of the command to a file. Creates the file if it doesn’t exist, otherwise appends to it. <: Takes input for a command. |: The pipe operator. It passes the output of one command as the input of another.
53
Redirection & Pipes (>)
Example: To send the output of a command to a file. It sent the output of the command date to a file called today.txt. It creates the file if it doesn’t exist, otherwise overwrites it.
54
Redirection & Pipes (>>)
Example: To append the output of a command to a file. It sent the output of the command who to the end of the file called today.txt. It creates the file if it doesn’t exist.
55
Redirection & Pipes (<)
Example: To take input for a command. It took the contents of the file latlonpts.txt as input for the wc command.
56
Redirection & Pipes (|)
Example: To take input for a command. Dumps the contents of the file sample.txt, which is then piped to the program grep and finally piped as input for the wc program. It can be seen as: command1 | command2 | command3
57
Commands about Text processing (7)
sed: stream editor Detailed tutorial : Important function -> Substitution Format : sed 's/term1/term2/g‘ filename
58
Unix Tutorials for Beginners
tro.html tutorial/toc.html
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.