Sunteți pe pagina 1din 39

Introduction to Unix/Linux

Introduction: Why Unix/Linux?

 Linux is free
 It’s fully customizable
 It’s stable (i.e. it almost never crashes)

 These characteristics make it an ideal OS


for programmers and scientists
Connecting to a Unix/Linux system
 Open up a terminal:
Connecting to a Unix/Linux system
 Open up a terminal:

The “prompt”

The current directory (“path”)

The host
Help!

 Whenever you need help with a command


type “man” and the command name
Help!
Help!
Help!
File Handling commands-mkdir

 The “mkdir” (Make directory) command create a new directory.

 If directory already exists, it will return an error message “cannot


create folder, folder already exists”.

 Syntax: mkdir directory_name

 Example: mkdir student


Command: mkdir
 To create a new directory use “mkdir”
LS
Command: ls
 To list the files in the current directory use “ls”
Command: ls

 ls has many options


 -l long list (displays lots of info)
 -t sort by modification time
 -S sort by size
 -h list file sizes in human readable format
 -r reverse the order
 “man ls” for more options
 Options can be combined: “ls -ltr”
Command: ls -ltr
 List files by time in reverse order with long listing
cd

 It is used for changing the directory.

 Syntax: cd dir_name

 Example: cd student
Command: cd
 To change to a specific directory use “cd”
Command: cd

 “~” is the location of your home directory


Command: cd
 “..” is the location of the directory below
current one
pwd

 It prints the current working directory with


full path name from terminal.

 Syntax: pwd
pwd

 To find your current path use “pwd”


cp

 It copies a file from one location to another


location.

 Syntax: cp src_file desti_file

 Example: cp file1 file2


Command: cp

 To copy a file use “cp”


mv

 The “mv” command moves a file from one


location to another location.

 Syntax: mv source destination

 Example: mv file1 student


Command: mv

 To move a file to a different location use “mv”


Command: mv

 mv can also be used to rename a file


rm

 rm remove
 files or directories
 Usage: rm [OPTION]... FILE...
 eg. rm file1.txt , rm rf some_dir
Command: rm

 To remove a file use “rm”


Command: rm

 To remove a file “recursively”: rm –r


 Used to remove all files and directories
 Be very careful, deletions are permanent
in Unix/Linux
Command: rmdir
 To remove and empty directory use “rmdir”
find & history

 find – search for files in a directory


hierarchy
 Usage: find [OPTION] [path] [pattern]
 eg. find file1.txt, find name file1.txt
 • history – prints recently used commands
 Usage: history
Text Processing-cat

 It is used to create a file with content.


 And can concatenate two or more file contents.

 Syntax: cat > filename

 Example: cat > file1


echo
 Prints a text on the standard output.

 However in an interactive script, echo passes the message to


the user through terminal.

 Syntax: echo message


 Usage: echo [OPTION] [string] ...
 Example: echo hello class
 eg. echo I love India
 echo $HOME
grep

 It searches the given file for lines


containing a match to the given strings or
words.
 Syntax: grep word filename
 Example: grep m file2
Command: grep
 To search files in a directory for a specific
string use “grep”
wc

 wc print the number of newlines, words,


and bytes in files
 Usage: wc [OPTION]... [FILE]...
 eg. wc file1.txt
 wc L file1.txt
A few examples of piping
sort

 sort – sort lines of text files


 Usage: sort [OPTION]... [FILE]...
 eg. sort file1.txt
 sort r file1.txt
Unix Web Resources

 http://www.ee.surrey.ac.uk/Teaching/Unix/

 http://www.ugu.com/sui/ugu/show?help.be
ginners

 http://en.wikipedia.org/wiki/Unix

S-ar putea să vă placă și