-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBasic-Linux-commands
More file actions
117 lines (68 loc) · 1.94 KB
/
Basic-Linux-commands
File metadata and controls
117 lines (68 loc) · 1.94 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
How to create files in linux
-----------------------------------
touch one.txt
Different ways to create files
-------------------------------
1) touch one.txt
2) cat <<EOF>> file3
I'm from file3
EOF
---------------------------------
To view the contents of file
cat becomedevops.txt
----------------------------------
To copy the contents of files
cp firstfile.txt firstfile_bkup.txt
-----------------------------------
To rename thefiles
mv firstfile.txt file1.txt
-------------------------------------
To Delete the files
rm firstfile.txt
-------------------------------------
Types of editors
------------------
vi
vim
nano
Using a Vi Editor
-----------------------------
vi firstfile.txt
To add any content in the file
Enter i ---> Insert Mode
add any text
To save
ESC
shift+: wq!
-------------------------------------------
To create Directory
------------------
mkdir aws
---> To get in to a particular directory use cd command
ex: cd aws
To create directories recursively
---------------------------------
mkdir -p aws/ec2/userdata
To get back to the previous directory
------------------------------------
cd ..
To know the current directory
-------------------------------------
pwd
--------------------------------------
To Delete directories
rmdir aws
-------------------------------------
To see the list of heirarchies of files and drectories visually
Install tree utility
apt install tree
tree
ex: tree aws
aws is a directory
----------------------------------
you want to clean empty directories, find command can make the job easy:
$ find . -type d -empty -exec rmdir -v {} +
The -type d option searches for directories, -empty select empty ones and -exec rmdir {} executes the rmdir command to delete them.
The rmdir command ensures that the directory is empty before deleting it.
Alternatively, you can also use this command to complete the same task:
$ find . -type d -empty -delete