Changes between Version 8 and Version 9 of Csle2022/Agenda/linuxhandson
- Timestamp:
- Nov 27, 2022, 9:28:24 AM (2 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Csle2022/Agenda/linuxhandson
v8 v9 1 1 2 = = '''Linux''' ==2 = '''Linux''' = 3 3 4 4 == '''Working with directories''' == … … 7 7 A brief overview of the most common commands to work with directories: pwd, cd, ls, mkdir and rmdir. These commands are available on any Linux (or Unix) system. 8 8 9 •'''pwd''' : Print Working Directory (Will tell you the location you are currently working)10 •'''cd''' : You can change your current directory with the cd command11 o cd: shortcut to get back into your home directory. Just typing cd without a target directory, will put you in your home directory12 o cd ..: To go to the parent directory (the one just above your current directory in the directory tree)13 o cd- : To go to the previous directory14 • ls: You can list the contents of a directory with ls15 o ls -a: To show all files. Showing all files means including the hidden files. When a file name on a Linux file system starts with a dot, it is considered a hidden file and it doesn't show up in regular file listings.16 o ls -l: to display the contents of the directory in different formats or to display different parts of the directory.17 o ls -lh: shows the numbers (file sizes) in a more human readable format.18 •'''mkdir''' : Create new directories19 •'''mkdir -p:''' To create parent directories as needed20 •'''rmdir''': To remove the directory. (Directory has to be empty)9 * '''pwd''' : Print Working Directory (Will tell you the location you are currently working) 10 * '''cd''' : You can change your current directory with the cd command 11 * '''cd''' : shortcut to get back into your home directory. Just typing cd without a target directory, will put you in your home directory 12 * '''cd ..''' : To go to the parent directory (the one just above your current directory in the directory tree) 13 * '''cd''' - : To go to the previous directory 14 * '''ls''' : You can list the contents of a directory with ls 15 * '''ls -a''' : To show all files. Showing all files means including the hidden files. When a file name on a Linux file system starts with a dot, it is considered a hidden file and it doesn't show up in regular file listings. 16 * '''ls -l''' : to display the contents of the directory in different formats or to display different parts of the directory. 17 * '''ls -lh''' : shows the numbers (file sizes) in a more human readable format. 18 * '''mkdir''' : Create new directories 19 * '''mkdir -p:''' To create parent directories as needed 20 * '''rmdir''': To remove the directory. (Directory has to be empty) 21 21 22 22 … … 256 256 == Exercise == 257 257 258 Create numbers.txt (Containing ten lines of numbers one to ten) file with cat command. 258 //Create numbers.txt (Containing ten lines of numbers one to ten) file with cat command.// 259 259 $ cat > numbers.txt 260 260 261 Add the lines with enter key at the end. After inserting all the lines press Ctrl + D 261 //Add the lines with enter key at the end. After inserting all the lines press Ctrl + D// 262 262 263 263 one … … 266 266 Ten 267 267 268 View the file you created using less and cat 268 //View the file you created using less and cat// 269 269 270 270 Cat … … 288 288 less 289 289 290 {{{ 290 291 $ less numbers.txt 291 292 }}} 293 294 {{{ 292 295 Press q to exit from less 293 294 View first four lines and last four lines using head and tail commands 296 }}} 297 //View first four lines and last four lines using head and tail commands// 295 298 296 299 … … 308 311 }}} 309 312 310 Create another file numbers2.txt(with lines contain eleven to fifteen) 313 //Create another file numbers2.txt(with lines contain eleven to fifteen)// 311 314 312 315 … … 321 324 322 325 323 Combine numbers.txt and numbers2.txt and create numbers3.txt. and view the file. 326 //Combine numbers.txt and numbers2.txt and create numbers3.txt. and view the file.// 324 327 325 328 … … 346 349 347 350 348 Check the file format of the newly created file 349 351 //Check the file format of the newly created file// 352 {{{ 350 353 $ file numbers3.txt 354 }}} 351 355 numbers3.txt: ASCII text 352 356 … … 358 362 $ cd test 359 363 $ ls 360 numbers2.txt numbers3.txt numbers.txt one 361 }}} 362 363 364 Make a copy of test directory as newtest and rename it to numbers 364 }}} 365 //numbers2.txt numbers3.txt numbers.txt one// 366 367 368 369 //Make a copy of test directory as newtest and rename it to numbers// 365 370 366 371 {{{ … … 371 376 372 377 373 Delete the test directory 378 //Delete the test directory// 374 379 375 380 … … 388 393 * Commands with more specific command lines (e.g. "RTR-GW>" or "mysql>") imply that you are executing commands on remote equipment, or within another program. 389 394 390 chmod: Change file read write permission chown: Change the owner of the file chgrp: Change the group of the file395 **chmod**: Change file read write permission **chown**: Change the owner of the file **chgrp**: Change the group of the file 391 396 392 397 Reference … … 402 407 So, the directory has r (read), w (write), x (execute) access for the User and Group. For Other it has r (read) and x (execute) access. The file has read/write/execute access for User and read only access for everyone else (Group and Other). 403 408 404 To change permissions you use the chmod command. chmod uses a base eight (octal) system to configure permissions. Or, you can use an alternate form to specify permissions by column (User/Group/Other) at a time.409 To change permissions you use the **chmod** command. **chmod** uses a base eight (octal) system to configure permissions. Or, you can use an alternate form to specify permissions by column (`User/Group/Other`) at a time. 405 410 406 411 Permissions have values like this: … … 408 413 [[Image(reference.png, 300px, nolink))]] 409 414 410 411 415 Thus you can give permissions to a file using the sum of the values for each permission you wish to give for each column. Here is an example: 412 416 … … 446 450 $ chmod 044 numbers.txt 447 451 }}} 448 Now you have remove read privilege try view the file using cat 452 //Now you have remove read privilege try view the file using cat// 449 453 {{{ 450 454 $ chmod 444 numbers.txt 451 455 }}} 452 456 453 Now you have set privilege as read only. Open the file via vi editor and try to edit the file454 Switch to root user 457 //Now you have set privilege as read only. Open the file via vi editor and try to edit the file 458 Switch to root user// 455 459 {{{ 456 460 $ sudo su … … 466 470 467 471 468 who: who command will give you information about who is logged on the system.472 **who**: who command will give you information about who is logged on the system. 469 473 {{{ 470 474 $ who 471 475 }}} 472 476 473 whoamicommand tells you your username477 **whoami** command tells you your username 474 478 {{{ 475 479 $ whoami 476 480 }}} 477 481 478 df -h: report file system disk space usage482 **df -h**: report file system disk space usage 479 483 {{{ 480 484 df -h … … 483 487 [[Image(whoami.png, 400px, nolink))]] 484 488 485 man: Will give you man pages (also called manual pages) on your Unix or Linux computer489 **man**: Will give you man pages (also called manual pages) on your Unix or Linux computer 486 490 487 491 {{{ … … 490 494 }}} 491 495 492 date: Will give you the date and time of the system493 496 **date**: Will give you the date and time of the system 497 {{{ 494 498 $ date 495 496 To set time zone – type $ timedatectl set-timezone Asia/Colombo 499 }}} 500 To set time zone 501 {{{ 502 $ timedatectl set-timezone Asia/Colombo 503 }}} 497 504 498 505 ln: Use to create links between files. Frequently use with -s to create symbolic links