Changes between Version 8 and Version 9 of Csle2022/Agenda/linuxhandson


Ignore:
Timestamp:
Nov 27, 2022, 9:28:24 AM (2 years ago)
Author:
tuwan
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Csle2022/Agenda/linuxhandson

    v8 v9  
    11
    2 == '''Linux''' ==
     2= '''Linux''' =
    33
    44== '''Working with directories''' ==
     
    77A 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.
    88
    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 o cd : shortcut to get back into your home directory. Just typing cd without a target directory, will put you in your home directory
    12 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 directory
    14 •       ls : You can list the contents of a directory with ls
    15 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 directories
    19 •       '''mkdir -p:''' To create parent directories as needed
    20 •       '''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)
    2121
    2222
     
    256256== Exercise ==
    257257
    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.//
    259259$ cat > numbers.txt
    260260
    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//
    262262
    263263one
     
    266266Ten
    267267
    268 View the file you created using less and cat
     268//View the file you created using less and cat//
    269269
    270270Cat
     
    288288less
    289289
     290{{{
    290291$ less numbers.txt
    291 
     292}}}
     293
     294{{{
    292295Press 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//
    295298
    296299
     
    308311}}}
    309312
    310 Create another file numbers2.txt(with lines contain eleven to fifteen)
     313//Create another file numbers2.txt(with lines contain eleven to fifteen)//
    311314
    312315
     
    321324
    322325
    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.//
    324327
    325328
     
    346349
    347350
    348 Check the file format of the newly created file
    349 
     351//Check the file format of the newly created file//
     352{{{
    350353$ file numbers3.txt
     354}}}
    351355numbers3.txt: ASCII text
    352356
     
    358362$ cd test
    359363$ 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//
    365370
    366371{{{
     
    371376
    372377
    373 Delete the test directory
     378//Delete the test directory//
    374379
    375380
     
    388393* 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.
    389394
    390 chmod: Change file read write permission chown: Change the owner of the file chgrp: Change the group of the file
     395**chmod**: Change file read write permission **chown**: Change the owner of the file **chgrp**: Change the group of the file
    391396
    392397Reference
     
    402407So, 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).
    403408
    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.
     409To 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.
    405410
    406411Permissions have values like this:
     
    408413[[Image(reference.png, 300px, nolink))]]
    409414
    410 
    411415Thus 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:
    412416
     
    446450$ chmod 044 numbers.txt
    447451}}}
    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//
    449453{{{
    450454$ chmod 444 numbers.txt
    451455}}}
    452456
    453 Now you have set privilege as read only. Open the file via vi editor and try to edit the file
    454 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
     458Switch to root user//
    455459{{{
    456460$ sudo su
     
    466470
    467471
    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.
    469473{{{
    470474$ who
    471475}}}
    472476
    473 whoami command tells you your username
     477**whoami** command tells you your username
    474478{{{
    475479$ whoami
    476480}}}
    477481
    478 df -h: report file system disk space usage
     482**df -h**: report file system disk space usage
    479483{{{
    480484df -h
     
    483487[[Image(whoami.png, 400px, nolink))]]
    484488
    485 man: Will give you man pages (also called manual pages) on your Unix or Linux computer
     489**man**: Will give you man pages (also called manual pages) on your Unix or Linux computer
    486490
    487491{{{
     
    490494}}}
    491495
    492 date: Will give you the date and time of the system
    493 
     496**date**: Will give you the date and time of the system
     497{{{
    494498$ date
    495 
    496 To set time zone – type $ timedatectl set-timezone Asia/Colombo
     499}}}
     500To set time zone
     501{{{
     502$ timedatectl set-timezone Asia/Colombo
     503}}}
    497504
    498505ln: Use to create links between files. Frequently use with -s to create symbolic links