Amr | b26d0d2 | 2018-12-19 21:13:10 +0200 | [diff] [blame] | 1 | commands in Linux/Ubuntu: |
| 2 | ------------------------- |
| 3 | echo $SHELL --> echo shell path |
| 4 | |
| 5 | ls -a --> list (a)ll files including hidden files |
| 6 | |
| 7 | ls -l -->list all files with their information |
| 8 | |
| 9 | ls -hl --> list all files with their information in a human readable format. |
| 10 | |
| 11 | touch fileName.txt |
| 12 | |
| 13 | pwd (print working directory): print current directory. |
| 14 | |
| 15 | echo "mytext" > mytext.txt : insert text into mytext file. |
| 16 | |
| 17 | history --> To list all commands ... |
| 18 | |
| 19 | man <cmd> : to get cmd manual |
| 20 | |
| 21 | man -k <word> EX: man -k list |
| 22 | |
| 23 | apropos <keyword>: Search man pages by keyword EX: apropos ls |
| 24 | if you found a number like (2) that number indicates the section of this command in the manual |
| 25 | |
| 26 | info <cmd>: Get command info EX: info ls |
| 27 | |
| 28 | whatis <cmd>: Get a brief about a specific command and returns its section in manual page (in circular braces () )EX: whatis ls |
| 29 | |
| 30 | uname -a : Get full info about your device (After laptop name is the Kernel version) |
| 31 | |
| 32 | uptime: Show you the time elapsed from the boot up till now |
| 33 | |
| 34 | cd ~: change directory to home directory |
| 35 | |
| 36 | cd - : change directory to the previous directory |
| 37 | |
| 38 | There's no rename in linux we move the folder to the same directory with a different name = Rename :) |
| 39 | |
| 40 | rm <Dir_Naem>: remove directory only if it's empty |
| 41 | |
| 42 | ------------ |
| 43 | Text Editos |
| 44 | ------------ |
| 45 | 1-vi <file_Name> |
| 46 | |
| 47 | it has 3 Modes: |
| 48 | ----------------- |
| 49 | 1- Insert Mode: Press i then insert your text |
| 50 | 2- Navigate |
| 51 | 3- 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 | ------------------------------------------------------------------------------------------------------------------------------- |
| 53 | 2- nano <file_name> |
| 54 | |
| 55 | |
| 56 | ======================================================================================= |
| 57 | |
| 58 | bash : is an implementation of shell |
| 59 | |
| 60 | Fish : is an implementation of shell has an autocomplete feature...more or advanced GUI for shell |
| 61 | |
| 62 | Power shell : is a linux shell implemented on windows |
| 63 | |
| 64 | Note: |
| 65 | ===== |
| 66 | |
| 67 | default input for shell is Keyboard |
| 68 | |
| 69 | default output for shell is monitor |
| 70 | --------------------------------------------------- |
| 71 | more ~/.bashrc |
| 72 | less ~/.bashrc |
| 73 | head -n <file_Name> : head -10 ~/.bashrc (echo the first 10 lines in that file) |
| 74 | tail -n <file_Name> : tail -10 ~/.bashrc (echo the last 10 lines in that file) |
| 75 | diff <file_One> <file_Two> : shows the difference between two files |
| 76 | ========================================================================================= |
| 77 | Wildcards(Globbing): |
| 78 | -------------------- |
| 79 | to 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 | |
| 85 | EX: |
| 86 | ls *.txt >> list all .txt files |
| 87 | ============================================================================================ |
| 88 | grep <option> <pattern> <file> |
| 89 | |
| 90 | EX: |
| 91 | grep error *.log |
| 92 | |
| 93 | clear |
| 94 | ====================================================== |
| 95 | 29/11/2018 |
| 96 | ----------------------- |
| 97 | Permissions: |
| 98 | ============ |
| 99 | |
| 100 | password in linux (passwd): hide the letters and password |
| 101 | Password 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> |
| 109 | EX: man 5 passwd |
| 110 | |
| 111 | password is saved in another file called shadow but it needs sudo |
| 112 | |
| 113 | id >> returns the user ID |
| 114 | uid==> user id |
| 115 | |
| 116 | whoami ==> return user fileName |
| 117 | |
| 118 | exit ==> exit the terminal |
| 119 | |
| 120 | ------------------------------------------------------------- |
| 121 | We set rules of a group and another rules per specific user |
| 122 | ------------------------------------------------------------- |
| 123 | Unix like OS : Follow Unix standard |
| 124 | |
| 125 | sudo:super user do :gives the privileges of super user temporarily for 15 minutes |
| 126 | |
| 127 | /etc/sudoers ---> contains super users names |
| 128 | |
| 129 | su <user-name> : Switch user from terminal |
| 130 | |
| 131 | change root user(super user) password: sudo passwd root |
| 132 | |
| 133 | to exit root user : exit |
| 134 | |
| 135 | ***************************************** |
| 136 | Execute the directory means to open it |
| 137 | ***************************************** |
| 138 | |
| 139 | the need to create a file that can be read by all people but user and his group: VIRUS |
| 140 | |
| 141 | ----------------------------------------------------------- |
| 142 | change file Permissions: |
| 143 | ------------------------ |
| 144 | chmod <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 | |
| 156 | digit2=7=> the same for group |
| 157 | |
| 158 | =========================================================================================== |
| 159 | change ownership: |
| 160 | ------------------- |
| 161 | chown -R Abdeen /home/myFolder #Makes Abdeen the new owner of all files in myFolder directory |
| 162 | ================================================= |
| 163 | Shell built-in commands: |
| 164 | ------------------------- |
| 165 | sudo should execute a program (binary) |
| 166 | |
| 167 | to know if the command is a program or a script use: type <cmd> |
| 168 | |
| 169 | if its type in /bin directory it's a program |
| 170 | if it's hashed it means it's in a hash table |
| 171 | if it's shell builtin it means it's a program within the shell itself |
| 172 | .... |
| 173 | .... |
| 174 | .... |
| 175 | EX: |
| 176 | type grep |
| 177 | ------------------------------------------------------------- |
| 178 | .deb : debian is the software installer for debian |
| 179 | ========================================================================== |
| 180 | cd - : change directory to previous directory (like back in windows) |
| 181 | cd is a builtin command so if you want to know its information you should use : |
| 182 | help cd #help is a program |
| 183 | NOTE: --->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 | |
| 192 | Home directory contains all users folders |
| 193 | ================================================================== |
| 194 | File hierarchy: |
| 195 | ---------------- |
| 196 | everything is a file |
| 197 | |
| 198 | process is a task in the running state |
| 199 | |
| 200 | Hard disk is a file |
| 201 | Device is a file |
| 202 | |
| 203 | partition table : contains start/End of each partition |
| 204 | |
| 205 | File System is methodology for storing the Permissions of files access/files numbers per partition/...etc |
| 206 | it consists of File system metadata and File System data. |
| 207 | |
| 208 | File system is per each partition. |
| 209 | |
| 210 | File 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 | =============================================== |
| 222 | Question: how to know block size in linux? |
| 223 | ================================================ |
| 224 | |
| 225 | File ID may be reused if the older file is deleted... |
| 226 | |
| 227 | df --> list all partitions with their information |
| 228 | |
| 229 | df -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 |
| 233 | but 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 | ===================================================================================================================== |
| 240 | File descriptor : contains file inode and something like a cursor(another pointer) to where the current cursor is.. |
| 241 | ===================================================================================================================== |
| 242 | |
| 243 | *************************************************************** |
| 244 | Assignment: Links:Hard Link vs Symbolic |
| 245 | Journal in Linux/Ubuntu |
| 246 | *************************************************************** |
| 247 | |
| 248 | Backward compatible: if newer version of a program it will support the previous versions of OS like 98,XP,Vista,7,... |
| 249 | |
| 250 | Kernel 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 | ============================================================================== |