Академический Документы
Профессиональный Документы
Культура Документы
Example: pwd>1a.txt
This example stores the present working directory into named file "1.txt"
OUTPUT:
$ pwd>1a.txt
[user15@setserver1 test]$ cat 1a.txt
/home/user15/user/test
Example to append the output of a command to the file
ls>>1a.txt
OUTPUT:
$ ls>>1a.txt
[user15@setserver1 test]$ cat 1a.txt
/home/user15/user/test
10.txt
11.txt
12.txt
13.txt
14.txt
15.txt
1a.txt
1.txt
2.txt
3.txt
4.txt
5.txt
6.txt
7.txt
8.txt
9.txt
user15_test.txt
This appends the the list of all files and directories into the file named "1a.t
xt".
________________________________________________________________________________
____________________________________________________________________________
2)We use the command "top" to check the CPU/Memory consumption in unix
OUTPUT:
$ top
top - 14:08:16 up 10 days, 21:26, 19 users, load average: 4.05, 4.13, 4.14
Tasks: 381 total, 3 running, 323 sleeping, 54 stopped, 1 zombie
%Cpu(s): 15.5 us, 29.4 sy, 0.0 ni, 54.3 id, 0.0 wa, 0.2 hi, 0.5 si, 0.0 st
KiB Mem: 8087576 total, 7726024 used, 361552 free, 260396 buffers
KiB Swap: 12386300 total, 100668 used, 12285632 free, 6347572 cached
PID
498
16768
7406
319
nal
482
9
33
37
42
499
USER
root
user8
user8
root
PR NI
VIRT
RES
SHR
20 0
4292
512
440
20 0 113152 1400 1144
20 0 113152 1364 1140
20 0 219520 91184 90744
S
S
R
S
S
%CPU
33.6
29.6
10.3
2.0
avahi
root
root
root
root
root
20
20
20
rt
rt
20
S
S
S
S
S
S
1.0
0.3
0.3
0.3
0.3
0.3
0 28648
0
0
0
0
0
0
0
0
0 441260
2056
0
0
0
0
4188
1176
0
0
0
0
2448
%MEM
0.0
0.0
0.0
1.1
TIME+
582:59.68
497:30.07
167:31.38
111:40.68
COMMAND
rngd
bash
bash
systemd-jour
er
693 gdm
20 0 949772 11556 2112 S 0.3 0.1 26:53.17 gnome-settin
gs1167 oracle
20 0 1397028 107272 102084 S 0.3 1.3 4:01.11 oracle
7806 root
20 0 114072 2208 1048 S 0.3 0.0 2:08.13 backgr.sh
13871 root
20 0
0
0
0 S 0.3 0.0 0:00.49 kworker/2:2
14098 root
20 0
0
0
0 S 0.3 0.0 0:01.35 kworker/3:2
27259 root
20 0
0
0
0 S 0.3 0.0 0:03.03 kworker/4:2
29429 root
20 0
0
0
0 S 0.3 0.0 0:02.10 kworker/5:1
________________________________________________________________________________
____________________________________________________________________________
3)The current running processes in UNIX can be found out using "ps -ef" command
OUTPUT:
$ ps -ef
UID
PID PPID C STIME TTY
root
1
0 0 Jul08 ?
hed-root --system --deserialize 22
root
2
0 0 Jul08 ?
root
3
2 0 Jul08 ?
root
5
2 0 Jul08 ?
root
7
2 0 Jul08 ?
root
8
2 0 Jul08 ?
root
9
2 0 Jul08 ?
root
10
2 0 Jul08 ?
root
11
2 0 Jul08 ?
root
12
2 0 Jul08 ?
root
13
2 0 Jul08 ?
root
15
2 0 Jul08 ?
root
16
2 0 Jul08 ?
root
17
2 0 Jul08 ?
root
18
2 0 Jul08 ?
root
20
2 0 Jul08 ?
root
21
2 0 Jul08 ?
root
22
2 0 Jul08 ?
root
23
2 0 Jul08 ?
root
25
2 0 Jul08 ?
root
26
2 0 Jul08 ?
root
27
2 0 Jul08 ?
root
28
2 0 Jul08 ?
root
30
2 0 Jul08 ?
root
31
2 0 Jul08 ?
root
32
2 0 Jul08 ?
root
33
2 0 Jul08 ?
root
35
2 0 Jul08 ?
root
36
2 0 Jul08 ?
root
37
2 0 Jul08 ?
root
38
2 0 Jul08 ?
root
40
2 0 Jul08 ?
root
41
2 0 Jul08 ?
TIME CMD
00:00:39 /usr/lib/systemd/systemd --switc
00:00:00
00:00:48
00:00:00
00:01:08
00:00:00
00:08:13
00:00:04
00:00:04
00:01:05
00:00:50
00:00:00
00:00:04
00:01:04
00:00:48
00:00:00
00:00:04
00:01:06
00:00:46
00:00:00
00:00:08
00:03:44
00:00:54
00:00:00
00:00:08
00:03:40
00:00:52
00:00:00
00:00:29
00:03:37
00:00:52
00:00:00
00:00:07
[kthreadd]
[ksoftirqd/0]
[kworker/0:0H]
[migration/0]
[rcu_bh]
[rcu_sched]
[watchdog/0]
[watchdog/1]
[migration/1]
[ksoftirqd/1]
[kworker/1:0H]
[watchdog/2]
[migration/2]
[ksoftirqd/2]
[kworker/2:0H]
[watchdog/3]
[migration/3]
[ksoftirqd/3]
[kworker/3:0H]
[watchdog/4]
[migration/4]
[ksoftirqd/4]
[kworker/4:0H]
[watchdog/5]
[migration/5]
[ksoftirqd/5]
[kworker/5:0H]
[watchdog/6]
[migration/6]
[ksoftirqd/6]
[kworker/6:0H]
[watchdog/7]
________________________________________________________________________________
____________________________________________________________________________
4)We can use the following statement
ls -lR|find -name "EXCEPTION_FILE"
OUTPUT:
tree
.
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
+-
+--
10.txt
11.txt
12.txt
13.txt
14.txt
15.txt
1a.txt
1.txt
2.txt
3.txt
4.txt
5.txt
6.txt
7.txt
8.txt
9.txt
sub1
+-- EXCEPTION_FILE
sub2
+-- EXCEPTION_FILE
user15_test.txt
2 directories, 19 files
ls -lR|find -name "EXCEPTION_FILE"
./sub2/EXCEPTION_FILE
./sub1/EXCEPTION_FILE
________________________________________________________________________________
____________________________________________________________________________
5)To find remaining space in UNIX/LINUX server we can use
df -k
OUTPUT:
Filesystem
/dev/sda4
devtmpfs
tmpfs
tmpfs
tmpfs
tmpfs
/dev/sda2
/dev/sda1
1K-blocks
Used Available Use% Mounted on
467831344 45016848 399026928 11% /
4036528
0 4036528 0% /dev
4043788 676676 3367112 17% /dev/shm
4043788
1900 4041888 1% /run
4043788
0 4043788 0% /sys/fs/cgroup
4043788
12 4043776 1% /tmp
499656
69076
393884 15% /boot
51082
9708
41374 20% /boot/efi
________________________________________________________________________________
____________________________________________________________________________
6)we use kill command to kill a process in unix server.
gracefull killing: kill -15 25718
force killing: kill -9 25718
where 25718 is the pid of a particular process.
________________________________________________________________________________
____________________________________________________________________________
7)grep -v '^$' a.txt>withoutblanks.txt
'-v' option of the grep command displays all lines that do not match the patter
n.The pattern matches the empty lines
OUTPUT:
cat>a.txt
velson
joyal
rosario[user15@setserver1 test]$ vi user15_test.txt
[user15@setserver1 test]$ grep -v '^$' a.txt>withoutblanks.txt
[user15@setserver1 test]$ cat withoutblanks.txt
velson
joyal
rosario
________________________________________________________________________________
_____________________________________________________________________
8)#!/bin/bash
string=_Processed
for var in `ls /home/user15/user/test/DataRecord`
do
if [ -f $var ]
then
mv /home/user15/user/test/DataRecord/$var /home/user15/user/test/DataRecord/Pro
cessed/$var$string
fi
done
OUTPUT:
.
+-- 10.txt
+-- 11.txt
+-- 12.txt
+-- 13.txt
+-- 14.txt
+-- 15.txt
+-- 1a.txt
+-- 1.txt
+-- 2.txt
+-- 3.txt
+-- 4.txt
+-- 5.txt
+-- 6.txt
+-- 7.txt
+-- 8.sh
+-- 8.txt
+-- 9.txt
+-- a.txt
+-- DataRecord
+-- a.txt
+-- Processed
+-- a.txt_Processed
+-- sub1
+-- EXCEPTION_FILE
+-- sub2
+-- EXCEPTION_FILE
+-- user15_test.txt
+-- withoutblanks.txt
________________________________________________________________________________
____________________________________________________________________________
So by removing writing from group and adding execute permission to owner, we can
achieve the objective in the question
OUTPUT:
ls -l a.txt
-rw-rw-r--. 1 user15 user15 7 Jul 19 14:37 a.txt
[user15@setserver1 test]$ chmod 744 a.txt
[user15@setserver1 test]$ ls -l a.txt
-rwxr--r--. 1 user15 user15 7 Jul 19 14:37 a.txt
________________________________________________________________________________
____________________________________________________________________________
12)Hidden directory is the one whose contents are not visible when we access the
directory in which it resides.
We can identify it using "ls -a"
To list the hidden folders in the directory "/home/user15" we can use
find /home/user15 -name ".*" -ls
OUTPUT:
27134269
4 drwxr-xr-x 4 user15 user15
4096 Jul 25 2014 /home/user1
5/.mozilla
27134272
4 -rw-r--r-- 1 user15 user15
193 Aug 9 2013 /home/user1
5/.bash_profile
27134371
4 drwxr-xr-x 3 user15 user15
4096 Jul 11 08:43 /home/user1
5/.local
27134273
4 -rw-r--r-- 1 user15 user15
231 Aug 9 2013 /home/user1
5/.bashrc
27134441 12 -rw------- 1 user15 user15
11969 Jul 18 16:50 /home/user1
5/.bash_history
27134274
4 -rw-r--r-- 1 user15 user15
172 Mar 30 2015 /home/user1
5/.kshrc
27134275
4 -rw-r--r-- 1 user15 user15
18 Aug 9 2013 /home/user1
5/.bash_logout
________________________________________________________________________________
____________________________________________________________________________
13)#!/bin/bash
read -p "enter a number: " n
if [ $($n%2) == 0 ]
then
echo "number is even"
else
echo "number is odd"
fi
OUTPUT:
sh 13.sh
enter a number: 12
number is even
[user15@setserver1 test]$ sh 13.sh
enter a number: 11
number is odd
________________________________________________________________________________
____________________________________________________________________________
14)#!/bin/bash
ls -l>all.txt|cat all.txt|while read line1
do