-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusefull-commands
More file actions
302 lines (235 loc) · 10.3 KB
/
usefull-commands
File metadata and controls
302 lines (235 loc) · 10.3 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
### change virtual terminal ###
chvt 1 or 7
############################
### trace process ###
strace ls 2>&1 | tee log ##### redirect stderr and stdout to pipe tee write stdin on console and to the file
###########################
### du size of all dir included hiddens dirs ###
du -sh .[^.]*
### download site ###
wget --recursive --no-clobber --page-requisites --html-extension --convert-links --restrict-file-names=unix,ascii --domains opennet.ru --no-parent http://site.com/doc/ ############ download website
#########################
### cpio archive ###
cpio -idmv < initrd-file
find ./ | cpio -H newc -o > /boot/new-initrd.cpio ###### create cpio archive
###############################
### reqursive substitude ###
find -type f -name \*.h -exec sed -i -r 's/server\.h"/net\.h"/g' {} \;
##############################
### memory ###
cat /proc/meminfo
cat /proc/sys/vm/swappiness
####################################
### drop all cach ###
echo 1 > /proc/sys/vm/drop_caches && sync && echo 2 > /proc/sys/vm/drop_caches && sync && echo 3 > /proc/sys/vm/drop_caches && sync && free -h
#####################################
### io statistic and information about kernel slab ###
iostat slabtop
################################
### ifconfig eth0 ${IP_ADDR} broadcast ${BROADCAST} netmask ${NETMASK} up ###
route add default gw ${GATEWAY}
################################
### find . -name \*.c | xargs grep '^function' ###
find . -type f -exec sh -c 'f={}; #created variables with finded filename
find . -exec grep -H -n 'hello' {} \; #Hn it is filename and number of string
grep -nHe ^xalloc_die -r .
##################################
### find multiply pattern and action with it ###
find . -name 'afile' -exec cat {} \; -or -name 'bfile' -exec cat {} \;
##################################
### awk ###
echo "username=DefUser2; PRNT=HP:0111020202=yes; HP:0s0dw33333=no; SCAN=HP:0999695444; FLASH=Kingston:5B651F00047B=rw;JetFlash:26HJQV7I57QG86CB=ro;" | awk -F";" '{ for (i=1; i<=NF; i++) { if ($i ~ "username=.*") { print $i } } }' | sed 's/username=//'
##################################
### print used space on mounted volume ###
df
##################################
### get or set hard disks parameters ###
hdparm
##################################
### losetup ###
modprobe -r loop
modprobe loop max_part=64
losetup /dev/loop0 ~/sda_backup
ls -l /dev/loop*
brw-rw--— 1 root disk 7, 0 Apr 4 14:34 /dev/loop0
brw-rw--— 1 root disk 7, 1 Apr 4 14:34 /dev/loop0p1
brw-rw--— 1 root disk 7, 5 Apr 4 14:34 /dev/loop0p5
brw-rw--— 1 root disk 7, 6 Apr 4 14:34 /dev/loop0p6
brw-rw--— 1 root disk 7, 7 Apr 4 14:34 /dev/loop0p7
brw-rw--— 1 root disk 7, 8 Apr 4 14:34 /dev/loop0p8
mount /dev/loop0p1 /mnt/part1/
###################################
### what file is opened on filesystem ###
fuser -mv /mount_point
###################################
### unarchive ###
bzip2 -cd filename.tar.bz2 | tar -xvf -
### concatenate and compress files ###
tar cfJ arch.tar.xz files_to_archive #create xz archive
tar -c * > archeve.tar
bzip2 -z archeve.tar #result file is archeve.tar.bz2
##################################
#search files which was later date of change than %filename1, ###
### and files which was earlier date of change than %filename2 ###
find / -not \( -path /root -prune \) -not \( -path /proc -prune \) -not \( -path /sys -prune \) -not \( -path /tmp -prune \) -not \( -path /boot -prune \) -not \( -path /run -prune \) -not \( -path /home -prune \) -not \( -path /media -prune \) -not \( -path /mnt -prune \) -and \( -newer /root/time1 \) -and \( ! -newer /root/time2 \)
find . -iname '*cxoffice*' -a -not -path '*.wine/*'
###################################
### redirect and merge stderr into stdout ###
date > file 2>$1
exec >filename #redirect stdout from all command of the script to "filename"
####################################
### operation with fd ###
n<&- #close input file descriptor n
0<&-, <&- #close stdin
n>&- #close output file descriptor n
1>&-, >&- #close stdout
#############################
#############################################
exec 6<&0 #lonk file descriptor #6 with stdin
exec < data-file
#############################################
### read from stdin or file and put it to var ${REPLY} ###
read s1 #read first line from data-file
read s2 #read second line from data-file
### restore stdin and close fd 6 ###
exec 0<&6 6<&- #restore stdin from fd 6 and close fd 6 to free it for system
#############################################
### Search the short descriptions and manual page names for the keyword printf as regular #expression. ###
man -k keyword
man -a intro #show all section where the "intro" is exest
###############################################
### output the first part of file (head) end of file (tail) ###
head
tail
#############################
### cut - remove sections from each line of files ###
cut
################################
### tr - translate or delete characters ###
tr
################################
### whatis whereis which ###
whatis whereis which
#############################
### nmap - Network exploration tool and security / port scanner ###
nmap -sT server.example.com # will be scanning port from 0 to 1024
nmap -O -sV server.example.com # will be scanning ports and detect operation sistem
###################################
### information from obj file ###
objdump
#######################################
### run as command in bash their argument ###
xargs
###################################
### list files which lock by PID ###
lsof -p "${PID}"
#################################
### manipulate jobs ###
bg - run jobs in the background
help bg
help fg
help jobs
help disown #detach process from terminal
man bash
info bash
###################################
### detach bg job from terminal ###
dtach
#################################
### immune to SIGHUP signal ###
nohup - run a command immune to hangups, with output to a non-tty
##################################
### write to file and stdout ###
tee # read from standard input and write to standard output and files
##################################
### installed package names ###
aptitude search package_name|sed -n '/^i *./p'|sed 's/^i //'|sed 's/^i A //'|sed 's/ *- .*//' #cut all from aptitude output without package names
####################################
### prepare file to kernel patch ###
./checkpatch.pl --no-tree -f sourcefile.c #check file for kernel style
###################################
### ls -l as column ###
(printf "PERMISSIONS LINKS OWNER GROUP SIZE MONTH DAY HH:MM PROG-NAME\n" ; ls -l | sed 1d) | column -t #print by columns
#####################################
### remove 2 to 4 char from each line ###
colrm 2 4 <filename #remove the second through fourth character from each line of text file "filename"
##################################
### set number of lines ###
nl < .vimrc #inserts numbers of non blanc line
#################################
### prepare file for printing ###
pr filename #prepare for printing file "filename" and put it to stdout
######################################
### read list as array of random digits ###
read -a list < <( od -Ad -w24 -t u2 /dev/urandom ) # list is array of random numbers
##############################
### generate random digit ###
head -c1 /dev/urandom | od -N 1 -i | awk '{ print $2 }' #generate 1 random number
########################################
### print groups in USER is included ###
for i in $(seq 0 $(( "${#GROUPS[@]}" - 1 )) ); do echo ${GROUPS[$i]} ; done #prints numbers of groups in which the user is included
###########################################
### changne file format ###
for pic in *"$infmt"; do echo "$pic"; ls "${pic}" | sed -e s/\.$infmt// ; p2=$(ls "$pic" | sed -e s/\.$infmt//); echo "${pic} ${p2}.${outfmt}"; done #change file extension from $infmt to $outfmt
##################################
### patch create and apply ###
diff -Naur standard_moodle my_moodle > difference.patch
patch -p1 < new_version.patch
#################################
### replacement obsolete netstat and route commands ###
NOTES
This program is mostly obsolete. Replacement for netstat is ss. Re‐
placement for netstat -r is ip route. Replacement for netstat -i is ip
-s link. Replacement for netstat -g is ip maddr.
netstat -putna #all tcp connections
netstat -tulpn
ss -l -p -n | egrep 'tcp|udp' #show opened ports
ss -aenp
################################################
### sed print lines between START and END ###
sed -n '/#START#/,/#END#/p' #print all lines between #START# and #END#
##########################################
### to view installed files of certain package
dpkg-query -L <package-name>
dpkg-deb -c /var/cache/apt/archives/package-name.deb
apt-file list <package-name>
#############################
### scp check destination folder is exist and copy ti this folder
scp sourcefile username@ip.address:'`[ -d /dest/dir ] || mkdir -p /dest/dir`/dest/dir/destfile'
#################################################
### first syslog record at boot time ###
kernel: [ 0.000000] #in vim search: kernel: [ 0.000000\]
################################################
### ssh vpn local settings ###
ip link set dev tun100 up
ip addr add 192.168.0.2/24 dev tun100
ip route add "${ssh_server_ip}" via 192.168.1.1 dev wlo1
ip route del default via 192.168.1.1 dev wlo1
ip route add default via 192.168.0.1 dev tun100
### ssh vpn remote settings ###
ip link set dev tun100 up
ip addr add 192.168.0.1/24 dev tun100
iptables -t nat -A POSTROUTING -s 192.168.0.2/32 -j SNAT --to-source "${uoter_ip}"
echo 1 > /proc/sys/net/ipv4/ip_forward
######################################
### iproute2 change MAC address ###
ip link set dev $IFACE down
ip link set dev $IFACE address XX:XX:XX:XX:XX:XX
ip link set dev $IFACE up
### ssh tunnel from office to internet host ###
#on office host need run sshd on port 22
#on internet host need option PermitTunnel yes
#run next
ssh -N -R 12344:localhost:22 root@internet_host_ip -p12345 &
#om home host to connect to office
ssh user_on_office_host@internet_host_ip -p12344
### cross compile ###
export PATH="/home/ivr/work/buildroot/buildroot-2018.02.4/output_soyuz_new/host/bin:$PATH"
make CC=arm-linux-gcc
### cross compile in kernel stile ###
ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- make -j10
# ps aux sort by cpu-utilization
ps aux --sort cputime
ps aux --sort -cputime
ps aux --sort -pcpu
ps aux --sort -time