-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_operation.sh
67 lines (44 loc) · 1.05 KB
/
file_operation.sh
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
#!/bin/bash
# using the if statement
echo Enter the name of the file
read name
if [ -f $name ];
then
echo file "$name" exits
else
echo file "$name" does not exits
fi
# -------------------------------------------------#
# creating the dir and file inside it then deleting it
# -------------------------------------------------#
echo "Enter the dir name: "
read name
org_dir=$(pwd)
# check if dir already exits
[[ -d $name ]] && echo $name already exits !, aborting && exit
sudo mkdir $name
cd $name
pwd
# using the touch to create the several file
for n in 1 2 3 4
do
sudo touch file$n
done
ls file?
for content in file?
do
sudo echo This file is named $content > $content
done
sudo cat file?
cd $org_dir
sudo rm -rf $name
echo Good Bye!
# -------------------------------------------------#
# Testing the file
# -------------------------------------------------#
# if [ -x /etc/passwd ]; then
if [ -f /etc/passwd ]; then
echo file is executable
# ACTION
fi
# -------------------------------------------------#