blob: 7f84e9ef013f8fc52c84b8c11cd086ee15566600 [file] [log] [blame]
Amrb26d0d22018-12-19 21:13:10 +02001commands in Linux/Ubuntu:
2-------------------------
3echo $SHELL --> echo shell path
4
5ls -a --> list (a)ll files including hidden files
6
7ls -l -->list all files with their information
8
9ls -hl --> list all files with their information in a human readable format.
10
11touch fileName.txt
12
13pwd (print working directory): print current directory.
14
15echo "mytext" > mytext.txt : insert text into mytext file.
16
17history --> To list all commands ...
18
19man <cmd> : to get cmd manual
20
21man -k <word> EX: man -k list
22
23apropos <keyword>: Search man pages by keyword EX: apropos ls
24if you found a number like (2) that number indicates the section of this command in the manual
25
26info <cmd>: Get command info EX: info ls
27
28whatis <cmd>: Get a brief about a specific command and returns its section in manual page (in circular braces () )EX: whatis ls
29
30uname -a : Get full info about your device (After laptop name is the Kernel version)
31
32uptime: Show you the time elapsed from the boot up till now
33
34cd ~: change directory to home directory
35
36cd - : change directory to the previous directory
37
38There's no rename in linux we move the folder to the same directory with a different name = Rename :)
39
40rm <Dir_Naem>: remove directory only if it's empty
41
42------------
43Text Editos
44------------
451-vi <file_Name>
46
47it has 3 Modes:
48-----------------
491- Insert Mode: Press i then insert your text
502- Navigate
513- Command mode(One line Mode) (To exit: ESC then : then q ) (To exit and save: ESC then : then wq) w for write and q for quit
52-------------------------------------------------------------------------------------------------------------------------------
532- nano <file_name>
54
55
56=======================================================================================
57
58bash : is an implementation of shell
59
60Fish : is an implementation of shell has an autocomplete feature...more or advanced GUI for shell
61
62Power shell : is a linux shell implemented on windows
63
64Note:
65=====
66
67default input for shell is Keyboard
68
69default output for shell is monitor
70---------------------------------------------------
71more ~/.bashrc
72less ~/.bashrc
73head -n <file_Name> : head -10 ~/.bashrc (echo the first 10 lines in that file)
74tail -n <file_Name> : tail -10 ~/.bashrc (echo the last 10 lines in that file)
75diff <file_One> <file_Two> : shows the difference between two files
76=========================================================================================
77Wildcards(Globbing):
78--------------------
79to do an operation to a group of files at once
80* is a wild card represents 0 or more character or number
81? any character
82[] range of characters EX ls [a-z]
83{} group of wild cards
84
85EX:
86 ls *.txt >> list all .txt files
87============================================================================================
88grep <option> <pattern> <file>
89
90EX:
91 grep error *.log
92
93clear
94======================================================
9529/11/2018
96-----------------------
97Permissions:
98============
99
100password in linux (passwd): hide the letters and password
101Password is a file that contains user password and info...
102
103>> cat /etc/passwd
104| pipe sign will redirect the output of a command to be the input of another commands
105
106>> cat /etc/passwd | grep "Amr Abdeen"
107
108>> man <section_num> <cmd>
109EX: man 5 passwd
110
111password is saved in another file called shadow but it needs sudo
112
113id >> returns the user ID
114uid==> user id
115
116whoami ==> return user fileName
117
118exit ==> exit the terminal
119
120-------------------------------------------------------------
121We set rules of a group and another rules per specific user
122-------------------------------------------------------------
123Unix like OS : Follow Unix standard
124
125sudo:super user do :gives the privileges of super user temporarily for 15 minutes
126
127/etc/sudoers ---> contains super users names
128
129su <user-name> : Switch user from terminal
130
131change root user(super user) password: sudo passwd root
132
133to exit root user : exit
134
135*****************************************
136Execute the directory means to open it
137*****************************************
138
139the need to create a file that can be read by all people but user and his group: VIRUS
140
141-----------------------------------------------------------
142change file Permissions:
143------------------------
144chmod <Permissions> <files> : change Mode of a file
145
146 chmod <digit1><digit2><digit3> <fileName> : each digit represents a rwx operations for each part (user,group,Others)
147
148 chmod 777 fileName
149
150 digit1=7=> 4+2+1 >read/write/execute
151
152 4= 0b100 >read
153 2= 0b010 >write
154 1= 0b001 >execute
155
156digit2=7=> the same for group
157
158===========================================================================================
159change ownership:
160-------------------
161chown -R Abdeen /home/myFolder #Makes Abdeen the new owner of all files in myFolder directory
162=================================================
163Shell built-in commands:
164-------------------------
165sudo should execute a program (binary)
166
167to know if the command is a program or a script use: type <cmd>
168
169if its type in /bin directory it's a program
170if it's hashed it means it's in a hash table
171if it's shell builtin it means it's a program within the shell itself
172....
173....
174....
175EX:
176 type grep
177-------------------------------------------------------------
178.deb : debian is the software installer for debian
179==========================================================================
180cd - : change directory to previous directory (like back in windows)
181cd is a builtin command so if you want to know its information you should use :
182help cd #help is a program
183NOTE: --->whatis will not work with cd
184 info will not work with cd
185
186*To make nested folders : cd -p {folderOne/folderTwo/folderThree}
187
188* you can create multiple files @ once using : touch dirName/fileName{startNum..EndNum}.extension
189 EX: touch myDir/myFile{1..5}.txt
190
191
192Home directory contains all users folders
193==================================================================
194File hierarchy:
195----------------
196everything is a file
197
198process is a task in the running state
199
200Hard disk is a file
201Device is a file
202
203partition table : contains start/End of each partition
204
205File System is methodology for storing the Permissions of files access/files numbers per partition/...etc
206it consists of File system metadata and File System data.
207
208File system is per each partition.
209
210File system meta data consists of:
211
212 1- inode(index-node) which is a part of file system metadata
213 each inode (wit unique node ID) contains file creation ,file size , user Creator, modification , etc...
214 each file is attached to a specific node...
215
216 2- dentry(directory entery) Cache: contains file name , column ID in inode , file's parent
217 *parent is a file that has a parent until ROOT which is the parent of itself.
218
219-->To show ID for each file : ls -i or ls -il
220-->To Show all information about that file: stat <fileName>
221===============================================
222Question: how to know block size in linux?
223================================================
224
225File ID may be reused if the older file is deleted...
226
227df --> list all partitions with their information
228
229df -i | less : to list all partitions with their inodes data
230
231
232*When moving a file from directory to another in the same partition the inode will be the same
233but the dentry will be changed.
234
235*when moving a file form file system to another file system it will copy the file itself , its inode , dentry , ...
236
237*open: open a file inside C Program and returns File descriptor...
238
239=====================================================================================================================
240File descriptor : contains file inode and something like a cursor(another pointer) to where the current cursor is..
241=====================================================================================================================
242
243***************************************************************
244Assignment: Links:Hard Link vs Symbolic
245 Journal in Linux/Ubuntu
246***************************************************************
247
248Backward compatible: if newer version of a program it will support the previous versions of OS like 98,XP,Vista,7,...
249
250Kernel contains a file system driver for each file system...
251
252>> file <file_name> : list file information
253>> xxd <file_name> : show HEX representation of a file
254
255>> File Signature=magic number: found in file header indicates file extension...
256
257>>
258==============================================================================