Unix For Testers
Unix System Architecture
Unix File System Structure
Absolute and Relative Path
Basic Unix Commands
cal command in Unix
who command in Unix
date command in Unix
clear command in Unix
more command in Unix
whoami command in Unix
uname command in Unix
man command in Unix
echo command in Unix
Unix File System Commands
ls command in Unix
cat command in Unix
cp command in Unix
mv command in Unix
pwd command in Unix
cd command in Unix
mkdir command in Unix
rmdir command in Unix
rm command in Unix
touch command in Unix
dirname command in Unix
tar command in Unix
Unix Links(ln)
Hard Link
Soft Link
Regular Expressions
Basic Regular Expressions
Interval Regular Expressions
Pipes and Filters
Unix Text Processing Commands
cmp command in Unix
diff command in Unix
comm command in Unix
cut command in Unix
Paste command in Unix
head command in Unix
tail command in Unix
wc command in Unix
sort command in Unix
grep command in Unix
Process Related Command
top command in Unix
ps command in Unix
nice command in Unix
Kill command in Unix
nohup command in Unix
time command in Unix
File Tranfer Commands in Unix
file transfer using scp command
file transfer using rlogin command
file transfer using telnet command
ssh(Secure Shell) command in Unix
ftp file transfer command
sftp file transfer command
chmod command in Unix
File Permission and File Security in Unix
Text Processing Unix Commands
Text processing Unix commands are those affecting text and text files. For example cut command in Unix, paste command in Unix, cmp command in Unix, sort command in Unix, comm command in Unix, head command in Unix, tail command in Unix, wc command in Unix, diff command in Unix, grep command in Unix are few in the list. While editing files, you may lose track of what changes you have made to which files.
In this article, we will cover commands that compare files.
cut command in Unix
- Cut selected fields of each line of a file.
- It can be used to cut parts of a line by byte position, character and field.
- It is necessary to specify option with command otherwise it gives error.
SYNTAX:
cut OPTION... [FILE]
Option | Use |
-b | Bytes, extract the specific bytes |
-c | Characters, extract the specific characters |
-d | Delimiter, use the mentioned delimiter |
-f | Fields, extract only these fields |
Example:
List without ranges:
$ cat test.txt Learn Daily Study Smart Grow
$ cut -b 1,2,3 test.txt Lea Stu Gro
List with ranges:
$ cut -b 1-3,5-7 test.txt Lean D Stuy S Gro
Use -d option ,consider space as a field separator or delimiter:
$ cut -d " " -f 1 test.txt Learn Study Grow
paste command in Unix
- Merging the corresponding lines of given files
- It is used to join files horizontally (parallel merging)
SYNTAX:
$ paste [Option] file1 file2
Example:
$cat file1.txt class Percent
$cat file2.txt 10th Pass
$paste file1 file2 class 10th Percent Pass
head command in Unix
- Display the top count lines of files or piped data to standard output.
- It displays 10 lines by default
SYNTAX:
head [-count] [file ...]
Options | Use |
-n | “n” is number of lines |
-c | “c” is number of bytes |
-f | Follow the change in the file |
-s | Sleep interval |
Display Specific number of lines using head command
the OPTIONS “-n” where n is an integer displays the specific number of lines of the file.
SYNTAX: $ head -n filename.txt or $ head - filename.txt
Example:
$ head -n 15 file1.txt $ head -15 file1.txt
Display Specific number of bytes using head command
the OPTIONS “-c” displays the specific number of bytes of the file.
SYNTAX: $ head -c filename.txt
Example:
$ head -c 150 file1.txt
Display content of mutiple file using head command
Head command displays first 10 lines (by default) of each file when multiple files are provided as input to it.
SYNTAX: $ head filename1.txt filename2.txt
to view a different number of lines use “-n” option.
Example:
$ head -n 15 file1.txt file2.txt
tail command in Unix
-
- Display the last count lines of files or piped data to standard output.
- It displays 10 lines by default
SYNTAX: tail [OPTIONS].. [FILE]..
Options | Use |
-n | “n” is number of lines |
-c | “c” is number of bytes |
-f | Follow the change in the file |
-s | Sleep interval |
for more on options, refer here
Display Specific number of lines from last using tail command
the OPTIONS “-n” where n is an integer displays the specific number of lines of the file.
SYNTAX: $ tail -n <INTEGER> filename.txt or $ tail -<INTEGER> filename.txt
Example:
$ tail -n 15 file1.txt $ tail -15 file1.txt
Display Specific number of bytes from last using tail command
the OPTIONS “-c” displays the specific number of bytes of the file.
SYNTAX: $ tail -c <INTEGER> filename.txt
Example:
$ tail -c 150 file1.txt
Display content of mutiple files
Tail command displays last 10 lines (by default) of each file when multiple files are provided as input to it.
SYNTAX: $ tail filename1.txt filename2.txt
to view a different number of lines use “-n” option.
Example:
$ tail -n 15 file1.txt file2.txt
Use tail with Other Commands in Unix
The tail command can be used in combination with other commands in unix.
Example:
tail -f error.log | grep 'message'