0

Linux Command Line Hackery Series: Part 2



Welcome back to Linux Command Line Hackery, yes this is Part 2 and today we are going to learn some new skills. Let's rock

Let us first recap what we did in Part 1, if you are not sure what the following commands do then you should read Part 1.

mkdir myfiles                                                # make a directory (folder) with myfiles as name
cd myfiles                                                      # navigate to myfiles folder
touch file1 file2 file3                                    # create three empty files file1file2file3
ls -l                                                                   # view contents of current directory
echo This is file1 > file1                               # write a line of text to file1
cat file1                                                           # display contents of file1
echo This is another line in file1 >> file1    # append another line of text to file1
cat file1                                                          # display the modified content of file1

Command:  cp
Syntax:        cp source1 [source2 ...] destination
Function:     cp stands for copy. cp is used to copy a file from source to destination. Some important flags are mentioned below
Flags:          -r copy directories recursively
                     -f if an existing destination file cannot be opened, remove it and try  again

Let us make a copy of file1 using the new cp command:

cp file1 file1.bak

what this command is going to do is simply copy file1 to another file named file1.bak. You can name the destination file anything you want.
Say, you have to copy file1 to a different folder maybe to home directory how can we do that? well we can do that like this:

cp file /home/user/

I've used the absolute path here you can use whatever you like.
[Trick: ~ has a special meaning, it stands for logged in user's directory. You could have written previous command simply as
cp file1 ~/
and it would have done the same thing.]
Now you want to create a new directory in myfiles directory with the name backup and store all files of myfiles directory in the backup directory. Let's try it:

mkdir backup
cp file1 file2 file3 backup/

this command will copy file1 file2 file3 to backup directory.
We can copy multiple files using cp by specifying the directory to which files must be copied at the end.
We can also copy whole directory and all files and sub-directories in a directory using cp. In order to make a backup copy of myfiles directory and all of it's contents we will type:

cd ..                                           # navigate to previous directory
cp -r myfiles myfiles.bak       # recursively copy all contents of myfiles directory to myfiles.bak directory

This command will copy myfiles directory to myfiles.bak directory including all files and sub-directories

Command: mv
Syntax:       mv source1 [source2 ...] destination
Function:    mv stands for move. It is used for moving files from one place to another (cut/paste in GUI) and also for renaming the files.

If we want to rename our file1 to  file1.old in our myfiles folder we'll do the follow:

cd myfiles                                      # navigate first to myfiles folder
mv file1 file1.old

this command will rename the file1 to file1.old (it really has got so old now). Now say we want to create a new file1 file in our myfiles folder and move the file1.old file to our backup folder:

mv file1.old backup/                    # move (cut/paste) the file1.old file to backup directory
touch file1                                    # create a new file called file1
echo New file1 here > file1         # echo some content into file1

Command:  rmdir
Syntax: rmdir directory_name
Function: rmdir stands for remove directory. It is used for removing empty directories.

Let's create an empty directory in our myfiles directory called 'garbage' and then remove it using rmdir:

mkdir garbage
rmdir  garbage

Good practice keep it doing. (*_*)
But wait a second, I said empty directory! does it mean I cannot delete a directory which has contents in it (files and sub-directories) with rmdir? Yes!, you cannot do that with rmdir
So how am I gonna do that, well keep reading...

Command:  rm
Syntax:        rm FILE...
Function:     rm stands for remove. It is used to remove files and directories. Some of it's important flags are enlisted below.
Flags:          -r remove directories and their contents recursively
                     -f ignore nonexistent files and arguments, never prompt

Now let's say we want to delete the file file1.old in backup folder. Here is how we will do that:

rm backup/file1.old                # using relative path here

Boom! the file is gone. Keep in mind one thing when using rm "IT IS DESTRUCTIVE!". No I'm not yelling at you, I'm just warning you that when you use rm to delete a file it doesn't go to Trash (or Recycle Bin). Rather it is deleted and you cannot get it back (unless you use some special tools quickly). So don't try this at home. I'm just kidding but yes try it cautiously otherwise you are going to loose something important.

Did You said that we can delete directory as well with rm? Yes!, I did. You can delete a directory and all of it's contents with rm by just typing:

rm -r directory_name

Maybe we want to delete backup directory from our myfiles directory, just do this:

rm -r backup

And it is gone now.
Remember what I said about rm, use it with cautious and use rm -r more cautiously (believe me it costs a lot). -r flag will remove not just the files in directory it will also remove any sub-directories in that directory and there respective contents as well.

That is it for this article. I've said that I'll make each article short so that It can be learned quickly and remembered for longer time. I don't wanna bore you.
Related news
  1. Hacking Tools For Games
  2. Hack Tools For Mac
  3. Hack Tools
  4. Hack Tools For Pc
  5. Hacker Tools Windows
  6. Android Hack Tools Github
  7. Pentest Tools Port Scanner
  8. Computer Hacker
  9. Hacking Tools Name
  10. Hack App
  11. Hacking Tools For Games
  12. Hack And Tools
  13. Hack Tools For Windows
  14. Hack Tools For Games
  15. Hacker Tools
  16. Hacking Tools For Windows
  17. Hacker Tools For Ios
  18. Hacking Tools Windows 10
  19. Hacking Tools Free Download
  20. Hack Tools Github
  21. Hacker Tools Apk
  22. Ethical Hacker Tools
  23. Easy Hack Tools
  24. Top Pentest Tools
  25. Hacking Tools Windows 10
  26. Hacking Tools For Beginners
  27. Hacker Tools Mac
  28. Hacking Tools Github
  29. Bluetooth Hacking Tools Kali
  30. Hack Tools
  31. Hack Rom Tools
  32. Hacker Tools Apk Download
  33. Hacker Techniques Tools And Incident Handling
  34. Hacking Tools For Windows
  35. Beginner Hacker Tools
  36. Hack Tool Apk No Root
  37. Hacker Tools For Mac
  38. Hack Tools Github
  39. Hack Tools Pc
  40. Hackers Toolbox
  41. Hacks And Tools
  42. Hack App
  43. Hack Tools
  44. Pentest Tools Apk
  45. Nsa Hack Tools
  46. Hacker Tools For Mac
  47. Hacking Tools 2020
  48. Pentest Reporting Tools
  49. Hacks And Tools
  50. Pentest Tools Download
  51. Top Pentest Tools
  52. Hacking Tools Mac
  53. Pentest Tools Download
  54. Hacking Tools For Beginners
  55. Hacker Tools For Ios
  56. Hacker Tools 2019
  57. Hacking Tools For Windows 7
  58. Nsa Hacker Tools
  59. Hacker Tools 2019
  60. Hacker Tools Apk
  61. Hack Tools 2019
  62. Pentest Tools Tcp Port Scanner
  63. Black Hat Hacker Tools
  64. Hacking Tools And Software
  65. Bluetooth Hacking Tools Kali
  66. Hacking Tools Name
  67. Hacker Tools Mac
  68. Bluetooth Hacking Tools Kali
  69. Hack Tools 2019
  70. Hak5 Tools
  71. Hack Apps
  72. Hack Tools Pc
  73. Hacking Tools Mac
  74. Hack Website Online Tool
  75. Hacker Tools For Pc
  76. Hacker Tools Github
  77. Hacker Tools 2019
  78. Pentest Tools For Windows
  79. Pentest Recon Tools
  80. Pentest Tools Apk
  81. Pentest Tools Windows
  82. Hack Tools For Games
  83. Tools 4 Hack
  84. Nsa Hacker Tools
  85. Hacker Tools Online
  86. Wifi Hacker Tools For Windows
  87. Pentest Tools For Mac
  88. Hacker Tools For Windows
  89. Hack Tools
  90. Hack Tools Github
  91. Hacking Tools Name
  92. Best Pentesting Tools 2018
  93. Pentest Tools Port Scanner
  94. Hacking Tools Mac
  95. Hacking Tools 2020
  96. Hacking Tools For Windows Free Download
  97. Hacker Tools For Pc
  98. Pentest Tools For Mac
  99. Hacker Tools Mac
  100. Hacker Search Tools
  101. Github Hacking Tools
  102. Hack Apps
  103. Hacking Tools Mac
  104. Hacker Tools Online
  105. Physical Pentest Tools
  106. Free Pentest Tools For Windows
  107. Nsa Hack Tools
  108. Hacker Search Tools
  109. Pentest Tools Linux
  110. Hacker Tools 2020
  111. Hacker Tools Windows
  112. Hacker Tools Linux
  113. Pentest Tools Alternative
  114. Pentest Automation Tools
  115. Computer Hacker
  116. Top Pentest Tools
  117. Pentest Tools Android
  118. Pentest Tools Review
  119. New Hacker Tools
  120. Hacker Tools Linux
  121. Hacker Tools Apk
  122. Hacker Tools For Windows
  123. Pentest Tools Port Scanner
  124. Hacking Tools And Software
  125. Hackrf Tools
  126. Hack Tools 2019
  127. Hacking Tools
  128. Pentest Tools Framework
  129. Hacker Tools
  130. Hack Tools For Windows
  131. Hacking Tools Name
  132. Pentest Tools Kali Linux
  133. Hacking Tools Online
  134. Hacking Tools And Software
  135. Hack Tools For Games
  136. Tools 4 Hack
  137. Hacker Tools Linux
  138. Pentest Tools Find Subdomains
  139. Install Pentest Tools Ubuntu
  140. Pentest Tools Framework
  141. Hacking Tools And Software
  142. Hack Tools For Pc
  143. Hack Tools
  144. Hacker Tools Windows
  145. Game Hacking
  146. Pentest Tools Bluekeep
  147. Hacking Tools Pc
  148. Hacker Techniques Tools And Incident Handling
  149. Pentest Tools For Mac
  150. Nsa Hacker Tools
  151. Hack Tools For Ubuntu
  152. Kik Hack Tools
  153. Bluetooth Hacking Tools Kali
  154. Tools 4 Hack
  155. Hacking Tools For Windows Free Download
  156. Hacking Tools 2020
  157. Wifi Hacker Tools For Windows
  158. Hacker Tools For Windows
  159. Hacker Tools Free Download
  160. Hacking Tools Pc
  161. Hacking Tools Software
  162. Hacker Tools Github
  163. New Hacker Tools

0 critiques:

Post a Comment

Back to Top