0% found this document useful (0 votes)
3 views10 pages

Unix Command

The document provides a comprehensive overview of various UNIX commands including calendar management, date formatting, user information, file and directory operations, and basic scripting. It covers commands like 'cal', 'date', 'who', 'uname', 'mkdir', 'rm', 'cp', and more, detailing their options and usage. Additionally, it includes information on input/output redirection, pipelining, and text processing commands such as 'head', 'tail', 'cut', and 'paste'.

Uploaded by

0shubham.false
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views10 pages

Unix Command

The document provides a comprehensive overview of various UNIX commands including calendar management, date formatting, user information, file and directory operations, and basic scripting. It covers commands like 'cal', 'date', 'who', 'uname', 'mkdir', 'rm', 'cp', and more, detailing their options and usage. Additionally, it includes information on input/output redirection, pipelining, and text processing commands such as 'head', 'tail', 'cut', and 'paste'.

Uploaded by

0shubham.false
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ay

UNIX
2

3 commands :
cal: shows calendars
4
calendar
5 cal -j : julian
6 cal -y : ful1 calendar
julian calendar
7 cal -jy : full
cal -1 : current month (default)
cal -3: previous , current next month
9
10 cal -m : monday as first day
11 cal - s : sunday as first day
12 cal -y ( cal -y 2027 or cal 2027 orcal082027)
13
14
19 date : print or formats systm date/time
16
17 date " . . . "
18
19 $a : abbrivated day
I
20 $A : full day
21 $d :date
Sb :abbrivated month
$B : full month
24 $y : 2 digit year
25 $Y : 4 digit year
26 $H : 24 hour format
$I: 12 hour format
28 SM : minute
$S :seconds
30 $x : " dd/mm/yy" format
31 SX : "$I:M:%S" AM/ PM IST
32
33
34 date -d"mm/dd/yyyy" + ""
35 date -d"yyyy-mm-dd"4""

3
37 clear - clear screen
38
39
40 who : display all users in server
41 who -H :header
42 who -g :username with count
43 who -a :all users
44 who -b :boot info
Normal text file length: 3,554 lines: 134 Ln: 1 Col: 1 Pos: 1

Q Search
day [Link] x day [Link] [Link] [Link]
43 Who -a : a l l users
44 who -b :boot info
45 who -m :user associated with input
46 who am i :details of currently
47 whoami :username
logged in user
48
49
50 uname :prints kernel,system
51 hardware info
uname-s:kernel name
52 uname -a: all
53 uname -n: node/hostname
54 uname-v : version
55 uname -r: release
56 unamne p processor
57 uname -0: os type
58
59 bc: basic calculator
60
61 scable by default is 0
62 scale=2 -> set it as 2 digits after decimal
63 point
64 sqrt (2)
65
66
67
68
69 echo "heloworld": print
70 echo heloworld : also print
71 echo "10/2 " : print 10/2 as it a string
72 echo "10/2" | bc : print 5 as we use pipeline in it with bc (basic
73 calculator)
74 echo -e: disable escape char \tAn
75 echo -E : disable escape char \tNn
76 echo -n : supress default \n
77
78 printf : print without default \n
79
80 $d decimal
81 $s string
82 $f float
83
84 printf "\nhelo world\n"
85 printf "$s f\nts %f\n" "sal" 111. 00 "newsal" 120.0
86 Drintf "$s\nts" "ename" "salary"
Normal text file length: 3,554 lines: 134 Ln: 1 Cok 1 Pos: 1

Q Search
MYSGEC2G072 Ctrl+Alt+ Del 8 USB Devices Exit Fullscreen
File Edit Search View Encoding Language -X

day [Link] day [Link] [Link] new.1txt


85 printf " s $f\n%s 8f\n" "sal" 111.00 "newsal" 120.0
86 printf "$s\nts" "ename""salary"
87 printf "$-10s $-10f\n$-10s $-10f\n" "sal" 111.00 "newsal" 120.0
88
89
90 FILE AND DIRECTORY cOMMANDS-->>
91
92 pwd : print working directory
93 ls : display names
94 ls -1: long listing
95 ls -a :hidden files
96 ls -R: recursive
97 ls -t : sort by time
98 ls -s sort by size
99 ls -1 one l i s t at a time
100
101 ls abosolute path : ls /home/dhruv. na/big
102
103 mkdir make new directories
104 mkdir test :create a directory test
105 mkdir -p: parent directory
106
107 mkdir -p test/test1 : make test1 in test
108
109
relative path -> as we are in current directory so we can just give path after this
110 absolute path -> we give complete path
111
112 mdir :remove empty directories
113 rmdir test : remove test if its empty
114 rmdir -p: remove parent dirs if empty
115
116 rmdir -p test/testl : remove testl from test
117
118
119 rm : remove file/directories
120 rm -l: confirm for delete
121 rm -f : force delete
122 -r : recursive delete
123
124 touch :create empty file
125 touch -a :access time
126 touch -t :set manual time (yyyymmddhhmm)
127 touch -d :cutsom date ("yyyy-mm-dd")
128

Normal text file length: 3,554 lines: 134 Ln: 1 Col: 1 Pos: 1 Windows (CR LF

Q Search M36
File Edit Search View Encoding Alt+Del
Language USB Devices r Exit Fullscreen

day [Link] day [Link] [Link] [Link]


1
2 cat >filename : enter content in file
3
(override)
cat >>filename : append data in file
4 cat filename: display file contents
5 tac filename : display file content in
6 cat -n :no of 1ines
reverse order
7 cat -b number non-empty lines
cat -S :emove extra blank spaces

10 cat filel>file2 : data of fileg goes in


11 cat filel>>file2 : data of file 1 added file2 overriden (change data)
in file 2 without override (append
12 data)
13
14 cat b>a : value of b goes in a
15 cat a>b>c: data of a goes in b and from b
to c b will be empty (override c as a -data)
16 cat a>>b>>c data of a goes in band from b to c{append
17 data of a in c)
18 cat b<a : print data of b (no of data in a)
19
20 cat anyfileabsolutepatth : cat
chage
/home/ [Link]/big/[Link]
21
22
23 cd : change directory: naviagte between directories
24
25 cd labsolute/path
26 cd .. -> one directory backward
27 cd ../dir -> give backward and go to dir in that
28
29 cp: copies files or directories
30 cp filel file2 : copy file 1 data in file 2
31
32
copying of file from pwd from destination directory:
33
cd filel absolute path(/home/[Link]/ss) :copy filel in ss
34
35 copying of file from one directory to another
36 cp absolute file path absolute path_ofDir (cp /home/[Link]/ss/ data. txt (file path) /home/
37 [Link]/data (directory path where we want to copy) )
38
39 cp -r->dirl dir 2
40 cp -s: create symbolic link (both arguements should be having only absolute path )
41
42 nv:rename or move files
43
44 rename -> my [option] old file new file
Normal text file length: 6,344 lines: 287 Ln: 1 Col: 1 Pos: 1 Windows (CR LF)

Q Search NOSS
USB Devices Exit Fullscreen
-X
day [Link] day [Link] X [Link]
43 [Link]
44 rename -> mv option) old file new
45 file
46 move-mv [option] fìle name (or file name
47 mv /home/[Link]/data/a (file with directory) destination directory
48 path) /home/ dh
[Link]/dhruv (destination)
49
S0
51 v 0 n f i r m overwrite
52
53 V ->don't overwrite
54
55 for varìables
S6 nunl=10
57 nun2-10
S8
59 echo Snuml+$num2 | bc or use quotes
60
62 command substittution I
63 dìsplay=$ (ls) // any command (not math)
64
echo Sdisplay
66
for mathematical
69
69 display =$((10+20))
70
echo $( (numl+num2 ) )

we can also use backtick


74 display=ls
echoexpr $numl+$num2 bc

man: qives user manual for the Command

82 File descriptors (FD) :


0-> STDIN (input)
84 1-> STDOUT (input)
85 2-> STDERR (input)

Normal text file length: 6,344 lines: 287 Ln: 1 Col: 1 Pos: 1 Windows (

Q Search
Ctrl+Alt+Del B USB Devices
Exit Fullscreen
day [Link] day [Link] x [Link]
85 2-> STDERR (ìnput) [Link]
86
87 Input redìrections :
88
symbol: <
89 cmd <
90 [Link]>inout taken from file instead of
91 keyboard
92 Output redirection->
93 symbols :
94
95
>Overwrite
S>append
96
97 Error redirection:
98 2>: redirect error
99 2>> : append error
100 &>: redirect stdout+stderr
101
102 combined example:
103 sort [Link] > [Link]
104 2>[Link]
105 - STDIN (0) <- input. txt
106 - STDIN (1)<- [Link]
107 STDIN (2) <- [Link]
108
109
110 pipelining->
111 cmdl | cmd2 | cmd3
112 ex:
113 ls -l | wC -1
114 cat file | grep "hello"
115 sort [Link] | unig
116
117 to do unig data must be sorted
118
119
120 text processing ->
121
122 head : show first line of a file
123
124 head -5 filename: print first 5 records of file
125 cat filename | head -5
126
127
128 head -c: showfirst bytes of file

Normal text file length: 6,344 lines: 287 Ln: 1 Col: 1 Pos: 1 Windows (C

Q Search
Z\unixday [Link]- Notepad ++ MYSGEC2G072 Ctrl+Alt+Del B USB Devices Exit Fullscreen -X
File Edit Search View Encoding Language

day [Link] day [Link] [Link] [Link]


127
128 head -c : show first bytes of file
129 head -c 20 file : show 20 bytes
130 head -c 1k file : show 1 kilobytes
131 head -c 2M file : show 2 megabytes
132
133
134 tail : show last lines of file
135 tail file : show last 10 lines
136 tail -n 10 file : last 10 lines
137
138 tail - c : show last n bytes
139 tail -c 20 file : last 20 bytes
140
141 tail-n+2 [Link] : i t Wil1 remove first line and print
142
143
144 Cut extracting columns
145
146 Cut -c 1-5 file : chars from 1 to 5 (if we want to cut lines)
147
148 cut -d ":" -fl, 2 file (field 1 and 3) ( if we want to cut acc to fields acc to delimiter bw them )
149
150 extrat first field :
151 cut -d -f1 log data
152
153 extract lst field and then first 6 char from result:
154 cut -d " " -f1 log data | cut -cl1-6
155
156 extract 1 , 3 and 4 fields :
157 Cut -d "" -fl,3,4 log data
158
159 extract 1 , 3 and 4 fields
160 Cut -d -fl-4 log data
161
162 paste: merge line side by side
163
164 'paste fl f2 : print fl and f2
165
166 paste -d "," f1 f2: print with a comma seprating
167
168 paste -s : merge lines of a single file on after another
|l69 Ex:
| 170 paste [Link]:

Normal text file length: 6,344 lines: 287 Ln: Col: 1 Pos: 1 Windows (CR LA) UTF-8

557
Q Search 1/25/2
tZ\unix\day [Link]- Notepad ++ MYSGEC2GO72 E Ctrl+Alt+Del USB Devices r Exit Fullscreen
File Edit Search View Encoding Language

day [Link] day 2,txt 3 [Link] [Link]


166 paste -d "," f1 f2: print wìth a comma seprating
167
168 paste -s : merge lines of a sìngle file on after anothe
169 Ex:
170 paste [Link]:
171 empname
172
173
174
175
176
177 paste -s names-txt:
178 empname b C d
179 (maximun string sìze is for every )
180
181 Co
182 compares two sorted files line by line
183
184 columns : I
185 1 -> supress column 1 (lines only in file 1)
186 2-> supress column 2 (lines only in file 2)
187 3-> supress column 3 (common lines)
188
189 comn filel file2
190 Ex
191 cat [Link] :
192 apple
193 banana
194 cat
195 dog
196
197 cat [Link]
198 banana
199 cat
200 elephant
201 frog
202
203
204 comm [Link] [Link] :
205 apple
206 banana
207 cat
208 cat
|209 dog

Normal text file length: 6,344 lines: 287 Ln: 1 Col: 1 Pos: 1 Windows (CR LF) UTF-8

5:57 P
Q Search M369 1/25/202
\unix\day [Link] Notepad++
MYSGEC2G072 Ctrl+Alt+ Del B USB Devices Exit Fullscreen
File Edit Search View Encoding Language

day [Link] day [Link] x [Link] new,[Link]


202
203
204 comm [Link] [Link] :
205 apple
206 banana
207 Cat
208 Cat
209 dog
210 elephant
211 frog
212
213 Commn -1 file. txt [Link]
214 banana
215 cat
216 elephant
217 frog
218
219 comm -2 [Link] file2. txt:
220 apple I
221 banana
222 cat
223 dog
224
225 comm-3 [Link] [Link]:
226 apple
227 cat
228 cat
229 dog
230 elephant
231 frog
232
233 -check-orde: check if input are sorted. if not sorted ->error
234
235 -nocheck-order: ignore order , but comparison may be incorrect
236
237
238 diff : show diff bw two files line by line
239
240 diff filel file2
241
242 options:
243 -i ->ignore case
244 -C->context diff ( shows lines before /after changes)
245 -a-> brief input ("files differ")
Normal text file length: 6,344 lines: 287 Ln: 1 Col: 1 Pos: 1 Windows (CR LF) UTF-8

Q Search M365
ZAunix\day [Link]-Notepad++ Ctrl+Alt+Del
MYSGEC2GO72 USB Devices ExÁt Fullscreen -X
File Edit Search View Encoding Language

day [Link] day [Link] 3 [Link] newN,[Link]


241
242 options:
243 ->ignore case
244 -c context diff ( shows lines before lafter changes)
245 -q-brief input ("files differ")
246
247
248 sort sorts lìnes
249
250 sOrt file :sort acc to ascii value
251 sort -n fìle sort acc to number
252
253 sOrt- file : sort in reverse order
254
255 sort -u file: show only unique value in sorted
256
257 sort -c check if it is sorted or not
258
259 options :
260 -t (delimiter) :
261 sort -t ":" -k 2 file (here ":" is delimiter)
262
263 -k( key/column) :
264 sort -k 3 file ( sort by column 3)
265 sort -t "," -k2 (sort by column 2 based on comma delimiter)
266
267 exclude header and print in sorted way acc to 5th col in reverse order
268
269 tail -n+2 [Link] | sort-t "#" -k5 -r
270
271 exclude header , extract only customer id and then only numeric part , then sort it and print only unique values
272
273 tail -n+2 [Link] | cut -d "#" -f3 | cut -c2-4 | sort -nu
274
275
276 unig: remove conecutive duplicate lines (file must be sorted)
277
278 unig file :
279 sort file | unig
280
281 option:
282 -u -> print only unique values
283 -d -> print only lines which ar duplicate
|284 -c -> print no of occurences
Normal text file length: 6,344 lines: 287 Ln: 1 Col: 1 Pos: 1 Windows (CR LF) U

Q Search M365

You might also like