You are on page 1of 87

LINUX COMMANDS

Day -1
Linux

• Linux is Unix based Operating System


• It was first Introduced by Linus Torvalds.
• Linux is an Open Source.
• Linux Kernel is low level system software.
• Portable - supports their programs on any kind of hardware platform
• Linux provides a standard file structure in system/user files.
• Linux provides user security using authentication features.
Linux Architechture

special interpreter program

core part of linux

all peripheral devices(RAM/HDD/CPU)


Linux Commands
System Basic Commands
File Commands
Processes
network
Permissions
Searching
Link
Compress
Job Schedule
Installation
Root Commands
File Transfer Commands
System Basic Commands
System Basic Command
arch
Print machine architecture.

[sdbt ~]$ arch


x86_64..
System Basic Command
uname
Display the Operating System Information

[sdbt ~]$ uname


Linux
System Basic Command
uname
Display the Operating System Information

[sdbt ~]$ uname


Linux

[sdbt ~]$ uname -r


3.8.13-44.1.1.el6uek.x86_64

[sdbt ~]$ uname -a


Linux sdbt.localdomain 3.8.13-44.1.1.el6uek.x86_64 #2 SMP Wed Sep 10 06:10:25 PDT 2014
x86_64 x86_64 x86_64 GNU/Linux
System Basic Command
/etc/redhat-release
Display the Operating System Release

[sdbt ~]$ cat /etc/redhat-release


Red Hat Enterprise Linux Server release 6.6 (Santiago)
System Basic Command
hostname
Display the current host, domain or node name of the system.
These names are used by many of the netwoking programs to identify the machine.

[sdbt ~]$ hostname


sdbt.localdomain

[sdbt ~]$ hostname –I #Display the host ip addresses only


192.168.1.250
System Basic Command
logname
Display the name of the current user.

[sdbt ~]$ logname


sdbt
System Basic Command
uptime
Display how long the system has been runnig. Next how many users are currenty
logged on and the system load averages for the past 1,5 & 15 min.

[sdbt ~]$ uptime


14:56:17 up 4:36, 4 users, load average: 0.65, 0.44, 0.50

[sdbt ~]$ uptime -V


procps version 3.2.8
System Basic Command
date
Display the system date & time.

[sdbt ~]$ date


Fri Jun 29 15:06:48 IST 2018

[sdbt ~]$ date -u


Fri Jun 29 09:36:51 UTC 2018

[sdbt ~]$ date +%A #Display Day of the week only


Friday

[sdbt ~]$ date +%D #Display the date only


06/29/18

[sdbt ~]$ date +%m/%d/%y


06/29/18
System Basic Command
cal
Display a calendar.

[sdbt ~]$ cal #current month calender


June 2018
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
System Basic Command
[sdbt ~]$ cal 7 2020 #July 2020 year calender
July 2020
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

[sdbt ~]$ cal -3 #Display last, current, next month calender.


May 2018 June 2018 July 2018
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 1 2 1 2 3 4 5 6 7
6 7 8 9 10 11 12 3 4 5 6 7 8 9 8 9 10 11 12 13 14
13 14 15 16 17 18 19 10 11 12 13 14 15 16 15 16 17 18 19 20 21
20 21 22 23 24 25 26 17 18 19 20 21 22 23 22 23 24 25 26 27 28
27 28 29 30 31 24 25 26 27 28 29 30 29 30 31
System Basic Command
who
Print Information about users who are currently logged in.

[sdbt ~]$ who


oracle tty1 2018-06-29 10:20 (:0)
oracle pts/0 2018-06-29 14:20 (192.168.1.17)
sdbt pts/1 2018-06-29 14:37 (192.168.1.5)
sdbt pts/2 2018-06-29 15:06 (192.168.1.5)

[sdbt ~]$ who -u


oracle tty1 2018-06-29 10:20 old 7241 (:0)
oracle pts/0 2018-06-29 14:20 00:02 15047 (192.168.1.17)
sdbt pts/1 2018-06-29 14:37 00:04 15515 (192.168.1.5)
sdbt pts/2 2018-06-29 15:06 . 16474 (192.168.1.5)
System Basic Command

[sdbt ~]$ who am i


sdbt pts/2 2018-06-29 15:06 (192.168.1.5)

[sdbt ~]$ whoami


sdbt
System Basic Command
wall
Send a message to everybody's terminal.

[sdbt ~]$ wall


Welcome to sdbt

Broadcast message from sdbt@acs.localdomain (pts/2) (Fri Jun 29


15:47:17 2018):

[sdbt ~]$ who -T


oracle + tty1 2018-06-29 10:20 (:0)
oracle + pts/0 2018-06-29 14:20 (192.168.1.17)
sdbt + pts/1 2018-06-29 14:37 (192.168.1.5)
sdbt + pts/2 2018-06-29 15:06 (192.168.1.5)
System Basic Command
w
Displays information about the users currently on the machine and their processes.
Header shows uptime information. Follwing details for each user - login name, the TTY name,
the remote host, login time, idle time, JCPU, PCPU and currently processing command.

[sdbt ~]$ w
15:32:01 up 5:12, 4 users, load average: 0.42, 0.53, 0.50
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
oracle tty1 :0 10:20 5:12m 11:40 0.02s pam: gdm-passwo
oracle pts/0 192.168.1.17 14:20 13:13 0.09s 0.03s /bin/bash
sdbt pts/1 192.168.1.5 14:37 1:21 0.03s 0.03s -bash
sdbt pts/2 192.168.1.5 15:06 1.00s 0.04s 0.00s w

-h skip header
-l long listing (default)
-s short listing
-u ignore uid of processes
-V display version
System Basic Command
id
Print user and group information for the specified IDs.

[sdbt ~] id
uid=2028(jlaxmi) gid=2028(jlaxmi) groups=2028(jlaxmi),54321(oinstall)

-g print only the effective group ID


-G print all group IDs
-n print name
-r print ID
-U Print effective user ID.
System Basic Command
users
Display the user names of users currently logged in to the current host

[sdbt ~] users

sdbt sdbt oracle oracle root root


System Basic Command
groups
Display group memberships for each username.

[sdbt ~] groups
sdbt oinstall

[sdbt ~]groups sdbt


sdbt : sdbt oinstall

[sdbt ~] groups oracle


oracle : oinstall wheel
System Basic Command
history
Display the command history list with line numbers.
[sdbt ~]$ history
1 pwd
2 hostname -i
3 su sdbt
4 pwd
7 date
8 date +%A
9 who am i
10 w
11 who -T
12 wall
13 uptime -V
14 history

[sdbt ~]$ history -c #clear the history


System Basic Command
clear
Clear the terminal screen.

[sdbt ~]$ clear


System Basic Command
alias
create alias string for command with option.

example
alias name=value
[sdbt ~]$ alias clr=clear

[sdbt ~]$ alias


alias clr='clear'
alias l.='ls -d .* --color=auto'
alias ldir='ls -l | egrep '\''^d'\'''
alias lf='ls -l | egrep -v '\''^d'\'''
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
System Basic Command
unalias
Remove each name from the list of defined aliases.

[sdbt ~]$ unalias clr


System Basic Command
man
Display the online manual pages.

[sdbt ~]$ man man


System Basic Command
cpuinfo
Display the cpu information its not permanant.

[sdbt ~]$ cat /proc/cpuinfo


processor :0
vendor_id : GenuineIntel
cpu family :6
model : 42
model name : Intel(R) Xeon(R) CPU E31220 @ 3.10GHz
stepping : 7
microcode : 0x29
cpu MHz : 1600.000
cache size : 8192 KB
physical id :0
siblings : 4
core id :0
cpu cores :4
System Basic Command
meminfo
Display the memory information its not permanant.
[sdbt ~]$ cat /proc/meminfo
MemTotal: 7620288 kB
MemFree: 624548 kB
Buffers: 156812 kB
Cached: 5610244 kB
SwapCached: 0 kB
Active: 3907708 kB
Inactive: 2731372 kB
Active(anon): 2927820 kB
Inactive(anon): 809092 kB
Active(file): 979888 kB
Inactive(file): 1922280 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 31457276 kB
SwapFree: 31457276 kB
System Basic Command
expr
evaluate expressions.

[sdbt ~]$ expr 10 + 40


50
[sdbt ~]$ expr 1000 - 999
1
[sdbt ~]$ expr 25 / 5
5
[sdbt ~]$ expr 10 \* 10 \* 10
1000
System Basic Command
seq
Display a sequence of numbers

[sdbt ~]$ seq 1 1 5


1
2
3
4
5

[sdbt ~]$ seq 5 -1 1


5
4
3
2
1
System Basic Command
exit
Exit is executed before the shell terminates

[sdbt ~]$ exit

[sdbt ~]$ logout


File commands
File Commands

File systems

ordinary file

directory file

executive file
File Commands

[
File Commands
pwd
print name of the current working directory.

[sdbt ~]$ pwd


/home/sdbt
File Commands
ls
listout directory and file contents

[sdbt ~]$ ls
Desktop Downloads oradata script
admin check.sh dir1 log
Pictures Templates arch create
Documents Music Public test

-i print the index number of each file


-l use a long listing format
-r use reverse order while sorting
-t sort by time modification
-R list subdirectories recusively
-s print the allocated size of each file.
-S sort by file size
-X sort alphabetically by entry extension
-1 list one file per line
File Commands
dir
List directory contents sort entries alphabetically

[sdbt ~]$ cd /
[sdbt ~]$ dir
archive backup etc media pgarchive slave_arch usr
archive9_6 bin home misc postdumps slave_Arch v1
asmdisk1 boot lib mnt proc soft v2
asmdisk2 cgroup lib64 net root srv var
asmdisk3 data lost+found opt sbin sys
asmdisk4 dataold master oracle selinux tmp

-a hidden entries too


-C list entries by columns
-f enable -aU
-U list entries in directory order
File Commands
cd
Change the current directory to another directory location.

[sdbt ~]$ cd #default home directory


[sdbt ~]$ cd dir1 #change from current directory to dir1 directory.
[sdbt ~]$ cd .. #change back to one step backward directory location.
[sdbt ~]$ cd - #change to previous path
[sdbt ~]$ cd ~ #change to home directory
[sdbt ~]$ cd ../dir1 #change back to one step backward and forward to dir1.
[sdbt ~]$ cd ../.. #change back to two step backward directory.
[sdbt ~]$ cd dir1/sdira/sdirb/sdirc
#change location to specified path
File Commands
cat
concatenate files and print on the standard output

cat > file1 #create a new file records

cat file1 #Display the file records

cat >> file1 #Append the exist file.

cat file1 > file2 #File1 output stored in another file2 file

cat -n #number all output lines

cat -A #equivalent to -vET

cat -E #display $ at end of each line


File Commands

[sdbt ~]$cat > file1.txt #To create a new file


linux is open source
linux is written by Linux Torvalds
linux is simple and elegant
written in the c programming language

[sdbt ~]$ cat file1.txt #To view the file contents


linux is open source
linux is written by Linus Torvalds
linux is simple and elegant
written in the c programming language
File Commands

[sdbt ~]$ cat >> file1.txt #To append the exist file
Linux is user for servers
linux is fast and secure
Its acts has multi user platforms

[sdbt ~]$ cat file1.txt #To view the file contents


linux is open source
linux is written by Linus Torvalds
linux simple and elegant
written in the c programming language
Linux is user for servers
linux is fast and secure
Its acts has multi user platforms
File Commands

[sdbt ~]$ cat file1.txt > file2.txt #To divert output in another file

[sdbt ~]$ cat file2.txt #To view the file contents


linux is open source
linux is written by Linus Torvalds
linux is simple and elegant
written in the c programming language
Linux is user for servers
linux is fast and secure
Its acts has multi user platforms
File Commands

[sdbt ~]$ cat -A 1.txt #To view the file contents


arch$
awk$
alias$

[sdbt ~]$ cat -vET 1.txt #To view the file contents
arch$
awk$
alias$
File Commands
tac
concatenate and print files in reverse.

[sdbt ~]$ cat fileinfo.txt


fruits
animals
vechicles
animals
Fruits
vegetables

[sdbt ~]$ tac fileinfo.txt


vegetables
fruits
animals
vechicles
animals
Fruits
File Commands
touch
Create multiple file, create empty file and change file timestamps

[sdbt ~]$ touch filea.txt fileb.txt filec.txt

[sdbt ~]$ touch –t 201806281010 filepast.txt

-a change only the access time


-d use it instead of current time
-t use YYMMDDhhmm instead of current time
-m change only modification time.
File Commands
vi editor
vi is a text editor. It can be used to edit all kinds of plain text. It is especially useful for
editing programs.

There are three mode


 Command mode
 Insert mode
 Escape mode

[sdbt ~]$ vi file1.txt


Linux is open Source.
Linux invented by Linux Torvalds.
Linux is multiuser and multplatform
File Commands

command mode

filename

cursor
point
File Commands

Insert mode

insert
allowed
cursor
point
File Commands

Escape mode

Esc
mode
File Commands
Command mode
1G - Move Cursor into First Line of the File
nG - Move Cursor into nth Number of the Line in File
G - Move Cursor into Last Line of the Line in File.
yy - Copy a Single line.
nyy - Copy Multiple line.
dd - Delete a Single Line.
ndd - Delete Multiple Line.
dw - Delete Single word.
x - Delete a Single character.
r - Replace a Single Character.
R - Replace a Multiple Character.
p - Paste the deleted or copied information.
u - Undo the changes
k - Move the cursor upward.
j - Move the cursor downward.
h - Move the cursor left side.
l - Move the cursor right side.
File Commands
Insert mode
i - allow insert cursor location.
I - allow insert start line of cursor location.
a - allow insert next to cursor location.
A - allow insert end line of cursor locaion.
o - open a new line below and allow insert from the cursor location.
O - open a new line above and allow insert from the cursor location.

Escape mode
Esc + :
w -Save
q -Quit
! -Force
n -next
/string -Search string in file
rew -review the multiple file once more
File Commands
ed
ed is a line-oriented text editor.

[sdbt ~]$ ed -p'>' >,p


ed >4,5n
>a 4 old
ed is
old 5 editor
is >w fileed.txt
old editor
>3 36
editor >Q
. old
>,p >i
interactive mode [sdbt ~]$ cat fileed.txt
ed ed
is .
>1,3n is
old interactive mode
editor 1 ed
2 is old
>= editor
4 3 interactive mode
>a
.
File Commands
nano
nano is a small, free and friendly editor which aims to replace pico, the default editor
included in the non-free pine package.

Four section of editor


• top line show the program version
• main editor window file being edited
• status line third line show important messages
• bottom two line show the shortcuts in the editor
File Commands

top

bottom
File Commands
mkdir
Create a Directory

[sdbt ~]$ mkdir dir1

[sdbt ~]$ mkdir dir2 dir3 dir4 #create Multiple Directory

[sdbt ~]$ mkdir -p dir5/sdira/sdirb/sdirc #create a Parental with Subdirectory


File Commands
rmdir
remove empty directories

sdbt ~]$ rmdir dir1


File Commands
rm
remove files or directories

-f force
-r recursive

[sdbt ~]$ rm file.txt

[sdbt ~]$ rm -rf dir5 # the directory which have contents


File Commands
head
Give Output the first 10 lines of the file

[sdbt ~]$ head alphabets.txt


aA
bB
cB
dD
eE
fF
gG
hH
iI
jJ
File Commands
tail
Give Output the bottom 10 lines of the file

[sdbt ~]$ tail alphabets.txt


qQ
rR
sS
tT
uU
vV
wW
xX
yY
zZ
File Commands
[sdbt ~]$ head -3 alphabets.txt
aA
bB
cB

[sdbt ~]$ tail -3 alphabets.txt


xX
yY
zZ

[sdbt ~]$ cat alphabets.txt |head -15|tail -1


oO
File Commands

more
Filter for paging through text one screenful at a time.

[sdbt ~]$ ls -l>/tmp/file1.txt

[sdbt ~]$ more /tmp/file1.txt


total 224
-rw-rw-r-- 1 sdbt sdbt 16 Jun 26 15:45 1.txt
-rw-rw-r-- 1 sdbt sdbt 74 Jun 26 11:33 add.sh
-rw-rw-r-- 1 sdbt sdbt 78 Jul 4 13:17 alphabetsdummy.txt
-rw-rw-r-- 1 sdbt sdbt 78 Jul 4 12:08 alphabets.txt
drwxrwxr-x 2 sdbt sdbt 4096 Jun 19 16:59 arch
-rw-rw-r-- 1 sdbt sdbt 44 Jun 26 11:35 ass.sh
-rw-rw-r-- 1 sdbt sdbt 212 Jun 26 11:32 case.sh
-rw-rw-r-- 1 sdbt sdbt 156 Jun 26 11:36 check.sh
--More--(28%)
File Commands

less
less similar to more but allows backwared and forward movement.

[sdbt ~]$ less /tmp/file1.txt


total 224
-rw-rw-r-- 1 sdbt sdbt 74 Jun 26 11:33 add.sh
-rw-rw-r-- 1 sdbt sdbt 78 Jul 4 13:17 alphabetsdummy.txt
-rw-rw-r-- 1 sdbt sdbt 78 Jul 4 12:08 alphabets.txt
drwxrwxr-x 2 sdbt sdbt 4096 Jun 19 16:59 arch
-rw-rw-r-- 1 sdbt sdbt 44 Jun 26 11:35 ass.sh
-rw-rw-r-- 1 sdbt sdbt 212 Jun 26 11:32 case.sh
-rw-rw-r-- 1 sdbt sdbt 156 Jun 26 11:36 check.sh
/tmp/file1.txt
File Commands

nl
number lines of file

[sdbt ~]$ nl fileinfo.txt


1 fruits
2 animals
3 vechicles
4 animals
5 fruits
6 vegetables
File Commands

sort
sort lines of text files.

[sdbt ~]$ sort fileinfo.txt


animals
animals
fruits
fruits
vechicles
vegetables
wechicles
File Commands

uniq
Filter adjacent matching lines.

[sdbt ~]$ sort fileinfo.txt | uniq

animals
fruits
vechicles
vegetables
wechicles
File Commands

comm
Compare sorted files file1 and file2 line by line

[sdbt ~]$ sort fileinfo.txt >infosort.txt


[sdbt ~]$ sort filedummy.txt >infodsort.txt
[sdbt ~]$ comm infosort.txt infodsort.txt

animals
animals
birds
fruits
fruits
vechicles
vegetables
wechicles
File Commands

diff
Compare files line by line

[sdbt ~]$ diff fileinfo.txt filedummy.txt


2d1
< animals
4d2
< animals
6a5
> birds
File Commands

diff3
Compare three files line by line

[sdbt ~]$ cat > file1.txt


Linux is OpenSource
[sdbt ~]$ cat > file2.txt
Linux is UserFrendly
[sdbt ~]$ cat > file3.txt
Linux is MultiPlatforms
[sdbt ~]$ diff3 file1.txt file2.txt file3.txt
====
1:1c
Linux is OpenSource
2:1c
Linux is UserFrendly
3:1c
Linux is MultiPlatforms
File Commands
sdiff
side-by-side merge of file differences.

[sdbt ~]$ sdiff fileinfo.txt filedummy.txt


fruits fruits
animals <
vechicles vechicles
animals <
wechicles wechicles
fruits fruits
> birds
vegetables vegetables
File Commands

cmp
compare two files byte by byte.

[sdbt~]$ cmp fileinfo.txt filedummy.txt


fileinfo.txt filedummy.txt differ: byte 8, line 2
File Commands
wc
Print line,word and byte counts for each fie

[sdbt ~]$ wc alphabets.txt


26 26 78 alphabets.txt

[sdbt ~]$ wc -l alphabets.txt


26 alphabets.txt

-l lines
-w words
-c bytes
File Commands
cp
Copy files and directories

[sdbt ~]$ cp file1.txt filenew.txt

[sdbt ~]$ cp -R dir5 dirdup

[sdbt ~]$ cp file1.txt /home/jlaxmi/dir5/sdira/fnew.txt

[sdbt ~]$ cp /home/jlaxmi/dir5/sdira/fnew.txt /home/jlaxmi/dirdup/sdira/fdup.txt


File Commands
mv
Rename sorce to destination, or Move sources to directory.

[sdbt ~]$ mv file1.txt filepast.txt

[sdbt ~]$ mv filepast.txt /home/jlaxmi/dir5/sdira/file1.txt

[sdbt ~]$ mv /home/jlaxmi/dir5/sdira/file1.txt /home/jlaxmi/dirdup/sdira/fileone.txt


File Commands
dd
data duplicator and used for copying and converting data. It is very
powerful low level utility of Linux which can do much more like;
Backup and restore the entire hard disk

[sdbt ~]$ dd if=file1.txt of=filenew.txt conv=ucase


0+1 records in
0+1 records out
93 bytes (93 B) copied, 0.000119011 s, 781 kB/s

[sdbt ~]$ cat filenew.txt


1.LINUX IS OPENSOURCE
2.LINUX INVENTED BY LINUX TORVALDS
3.LINUX IN MULTIUSER MULTIPLATFORMS
File Commands
split
split a file into pieces

[sdbt~]$ split alphabets.txt


[sdbt~]$ split -10 alphabets.txt

[sdbt~]$ ls -lrt|tail -3
-rw-rw-r-- 1 sdbt sdbt 18 Jul 4 13:19 xac
-rw-rw-r-- 1 sdbt sdbt 30 Jul 4 13:19 xab
-rw-rw-r-- 1 sdbt sdbt 30 Jul 4 13:19 xaa
File Commands
paste
Merge line of files

[sdbt~]$ paste xaa xab


aA kK
bB lL
cB mM
dD nN
eE oO
fF pP
gG qQ
hH rR
iI sS
jJ tT
File Commands
[sdbt~]$ paste xaa xab > xmerge.txt

[sdbt~]$ cat xmerge.txt


aA kK
bB lL
cB mM
dD nN
eE oO
fF pP
gG qQ
hH rR
iI sS
jJ tT
File Commands
join
join lines of two files on a common field.

[sdbt ~]$cat >filenumeric.txt


one
five
ten
zero
[sdbt ~]$cat >fileseries.txt
one
Zero

[sdbt ~]$join filenumeric.txt fileseries.txt


one
zero
File Commands
csplit
split a file into sections determined by context lines

[sdbt ~]$ csplit file1.txt 3 {3}


57
93
93
93
36
[sdbt ~]$ ls -lrt|tail
-rw-rw-r-- 1 sdbt sdbt 36 Jul 9 13:01 xx04
-rw-rw-r-- 1 sdbt sdbt 93 Jul 9 13:01 xx03
-rw-rw-r-- 1 sdbt sdbt 93 Jul 9 13:01 xx02
-rw-rw-r-- 1 sdbt sdbt 93 Jul 9 13:01 xx01
-rw-rw-r-- 1 sdbt sdbt 57 Jul 9 13:01 xx00
[sdbt ~]$ cat xx00
1.Linux is OpenSource
2.Linux Invented by Linux Torvalds
File Commands
fmt
simple optimal text formatter

[sdbt ~]$ fmt fileinfo.txt


fruits animals vechicles animals wechicles fruits vegetables

[sdbt ~]$ fmt -u alphabets.txt


aA bB cB dD eE fF gG hH iI jJ kK lL mM nN oO pP qQ rR sS tT uU vV wW xX
yY zZ

-c, --crown-margin preserve indentation of first two lines


-p, --prefix=STRING reformat only lines beginning with STRING,
reattaching the prefix to reformatted lines
-s, --split-only split long lines, but do not refill
-t, --tagged-paragraph indentation of first line different from second
-u, --uniform-spacing one space between words, two after sentences
-w, --width=WIDTH maximum line width (default of 75 columns)
File Commands
strings
print the strings of printable characters in files.

[sdbt ~]$ strings -n 2 -f fileinfo.txt filedummy.txt


fileinfo.txt: fruits
fileinfo.txt: animals
fileinfo.txt: vechicles
fileinfo.txt: animals
fileinfo.txt: wechicles
fileinfo.txt: fruits
fileinfo.txt: vegetables
filedummy.txt: fruits
filedummy.txt: vechicles
filedummy.txt: wechicles
filedummy.txt: fruits
filedummy.txt: birds
filedummy.txt: vegetables
File Commands
fold
check file types and compare values.

[sdbt ~]$ fold -b10 filenew.txt [sdbt ~]$ fold -w 10 -s filenew.txt


1.LINUX IS OPEN 1.LINUX IS
SOURCE OPENSOURCE
2.LINUX 2.LINUX
INVENTED BY LIN INVENTED BY
UX TORVALDS
LINUX TORVALDS
3.L
INUX IN MULTIUS 3.LINUX IN
ER MULTIPLATFOR MULTIUSER
MS MULTIPLATFORMS

-b, --bytes count bytes rather than columns


-c, --characters count characters rather than columns
-s, --spaces break at spaces
-w, --width=WIDTH use WIDTH columns instead of 80
File Commands

[sdbt ~]$ strings -t d alphabets.txt

-a - --all Scan the entire file, not just the data section
-f --print-file-name Print the name of the file before each string
-n --bytes=[number] Locate & print any NUL-terminated sequence of at
-<number> least [number] characters (default 4).
-t --radix={o,d,x} Print the location of the string in base 8, 10 or 16
-o An alias for --radix=o
-T --target=<BFDNAME> Specify the binary file format
-e --encoding={s,S,b,l,B,L} Select character size and endianness:
s = 7-bit, S = 8-bit, {b,l} = 16-bit, {B,L} = 32-bit
@<file> Read options from <file>
File Commands
tee
tee command reads the standard input and writes it to both the standard output and one or more
files. The command is named after the T-splitter used in plumbing. It basically breaks the output of a program
so that it can be both displayed and saved in a file.

[sdbt ~]$ ls -l|grep sdbt> newfile.txt [sdbt ~]$ ls –l | grep whale | tee newfile.txt
-rw-r----- 1 sdbt sdbt 16071 Jun 19 17:02 whale
[sdbt ~]$ cat newfile.txt
-rw-rw-r-- 1 sdbt sdbt 692 Jul 11 10:50 sdbt [sdbt ~]$ cat newfile.txt
-rw-rw-r-- 1 sdbt sdbt 0 Jul 9 12:58 sdbt00 -rw-r----- 1 sdbt sdbt 16071 Jun 19 17:02 whale
-rw-rw-r-- 1 sdbt sdbt 22 Jul 9 12:58 sdbt01
-rw-rw-r-- 1 sdbt sdbt 35 Jul 9 12:58 sdbt02 [sdbt ~]$ date | tee newfile.txt
-rw-rw-r-- 1 sdbt sdbt 36 Jul 9 12:58 sdbt03 Wed Jul 11 10:55:20 IST 2018
-rw-rw-r-- 1 sdbt sdbt 279 Jul 9 12:58 sdbt04
[sdbt ~]$ cat newfile.txt
Wed Jul 11 10:55:20 IST 2018
File Commands
unexpand
Convert blanks in each FILE to tabs, writing to standard output.With no FILE, or when FILE is -, read
standard input. Mandatory arguments to long options are mandatory for short options too.

[sdbt ~]$ cat newfile.txt


link is help to backup a file.
hard link is defaul
twhen interconect file corrupted.link is available

[sdbt ~]$ cat -vet newfile.txt


link^Iis^Ihelp^Ito^Ibackup^Ia^Ifile.$
hard^Ilink^Iis^Idefault$when^Iinterconect^Ifile^Icorrupted.$
link^Iis^Iavailable$
File Commands

[sdbt ~]$ unexpand -a -t5 newfile.txt>newfile2.txt

[sdbt ~]$ cat -vet newfile2.txt


link is^Ihelp to^Ibackup^Ia^Ifile.$
hard link is^Idefault$
when interconect^Ifile corrupted.$

[sdbt ~]$ unexpand -t5 newfile2.txt


link is help to backup a file.
hard link is default
when interconect file corrupted.
link is available

You might also like