Unix Experience
Unix Experience
ls COMMAND
The ls command lists all files in the directory that match the name. If
name is left blank, it will list all of the files in the directory.
Meta Characters:
Using VI Editor
Touch
cat>TestFile
content
Cat Command
$ cat filename
$ wc filename
cp command
Renaming Files
mv Command
mv file1 file2
rm Command
$rm Filename
$cd ~
cd Command
cd [directory]
cd.. Command
mkdir command
$mkdir dirname
mv command
rmdir command
$rmdir dirname
- 10
TCS INTERNAL
-
File Access Permission – Introduction
- 11
TCS INTERNAL
-
File Access Permission – cont…
The permissions are broken into groups of threes, and each position
in the group denotes a specific permission, in this order: read (r),
write (w), execute (x)
1.Read: Grants the capability to read ie. view the contents of the file.
- 12
TCS INTERNAL
-
File Access Permission - Diagram
- 13
TCS INTERNAL
-
Changing Permissions:
chmod command
- 14
TCS INTERNAL
-
Output Redirection
- 15
TCS INTERNAL
-
Output Redirection cont…
• You can use >> operator to append the output in an existing file
as follows:
• $ echo line 2 >> userss
- 16
TCS INTERNAL
-
Input Redirection
• Input Redirection:
• $ wc -l < users
• Unix IO
- 17
TCS INTERNAL
-
Filters
• Filters in Unix are some programs that read some input and
perform a simple transformation on it, and write some
output to the standard output. The inputs taken are not
changed.
- 18
- 18 - TCS INTERNAL
-
sort
- 19
- 19 - TCS INTERNAL
-
Sort Cont…
- 20
- 20 - TCS INTERNAL
-
Sort cont…
- 21
- 21 - TCS INTERNAL
-
uniq
• The filter uniq displays the content of a file, removing all the
duplicate lines from it.
• If 2 files are specified, uniq reads from the first and writes to
the second.
- 22
- 22 - TCS INTERNAL
-
Uniq cont….
- 23
- 23 - TCS INTERNAL
-
cut
$ cat file
learning UNIX
learning VI command
Did you learn Cut command
$ cut -c5 file
n
n
y
- 24
- 24 - TCS INTERNAL
-
cut
$ cat file
learning UNIX
learning VI command
Did you learn Cut command
$ cut -c5 file
n
n
y
- 25
- 25 - TCS INTERNAL
-
cut
$ cut -c5,8 file
ng
ng
y
Above command prints the 5th and 8th character of each line of a file.
Above command prints 2nd and 3rd word of each line considering space as a
delimiter.
TCS INTERNAL
head
Syntax
• head -n filename
tail
Lists the (tail) end of a file to stdout.
The default is 10 lines, but this can be changed with the -n option
Syntax
tail -n filename
- 27
- 27 - TCS INTERNAL
-
grep
• A multi-purpose file search tool that uses Regular
Expressions.
Syntax
- 28
- 28 - TCS INTERNAL
-
grep cont…
- 29
- 29 - TCS INTERNAL
-
pipe (|)
Pipe is
• A method of inter process communication (IPC).
For example
$ who | wc –l
- 30
- 30 - TCS INTERNAL
-
AWK
~$cat awk_file
Name,Marks,Max_Marks
Peter,200,1000
Sam,500,1000
Greg,1000
Abharam,800,1000
Henry,600,1000
Peter,400,1000
Example: Default behavior of awk
Print all the lines from a file. By default, awk prints all
lines of a file, so to print every line of above
created file use below command:
~$ awk '{print}' awk_file
TCS INTERNAL
~$ awk -F”,” {print $2,$3;}' awk_file
~$ awk '/Henry|Peter/' awk_file
BEGIN block Syntax
1|Latha|Third|Vikas|90|91
2|Neethu|Second|Meridian|92|94
3|Sethu|First|DAV|86|98
4|Theekshana|Second|DAV|97|86
5|Teju|First|Sangamithra|89|88
6|Theekshitha|Second|Sangamithra|99|100
TCS INTERNAL
awk -F"|" 'BEGIN{s=0}{s=$5+$6;print $2,s}' studentData|sort -k2 -nr|head -3
END block which is executed after executing all the AWK code. This is the
last AWK code
going to execute.
Example:
Print some meaning full info after processing AWK code.
~$ awk -F"|" 'BEGIN{s=0}{s=$5+$6;print $2,s} END {print
"############################"}' studentData
Output:
Latha 181
Neethu 186
Sethu 184
Theekshana 183
Teju 177
Theekshitha 199
############################
TCS INTERNAL
THANK YOU
TCS INTERNAL