Sunday, November 2, 2014

Intro to Linux Command Line

I'm sure you are probably asking the question ... With all the Graphical User Interfaces (GUI), why even bother to learn how to use the command line? The reality is no matter which operating system you are using, being able to use the command line is critical. If you ever wish to script a task it is more than likely you will be doing this via the command line. Moreover, there are just some things (in my opinion) which are better done at the command line. 

In this post, we will try to learn by looking at a couple of tasks.



Task 1:
Navigate to the Desktop directory. Create a file name test.txt with the text “HI I AM A TEST FILE”. Output the contents of the file to verify that the file contains what it should.

To perform the tasks above, the following steps should be taken.

i.                     Type the command “pwd” to print your current working directory

This should be reported as “/root
if it does not state “/root” then type “cd /root” and perform the “pwd

ii.                   Type “ls” to verify the “Desktop” directory is listed in your current working directory

iii.                 Next “cd Desktop  to go into the “Desktop” directory

iv.                 Type “echo ‘ HI I AM A TEST FILE’ > test.txt” to redirect the quoted text to a file named “test.txt

v.                   Next type “cat test.txt” to verify the contents was successfully redirected to the file.



Once completed you would have performed the steps as shown below



Task 2:

In the Desktop directory, create a directory named testdirectory. Take a look at the Desktop to verify the command executed.  Move the file test.txt (created in 1) to the directory testdirectory.  List the contents of the testdirectory directory.  Delete the directory testdirectory.


Similar to task 1, follow the steps below to complete this task

i.                     Type “mkdir testdirectory” to create the test directory. The “mkdir” command stands for “make directory




ii.                   Type “mv test.txt testdirectory” to move the “test.txt” file previously created in “task 1” to the “testdirectory” folder

iii.                 Type “ls testdirectory” to verify the file has been successfully moved

iv.                 Once it is verified that the file has been successfully moved, type “rm –rf testdirectory” this will remove the test directory as well as any files and or directories within the “testdirectory



Once completed, you would have performed the following tasks

     

Task 3:

Launch a GUI application from the command line.  Get a list of all the currently running processes.   Identify which process corresponds to the GUI application you just launched and kill it from the command line.



Similar to the previous tasks, follow the steps below .
The GUI application we will use will be the browser. In Kali, the browser name is “Iceweasel

i.                     Launch the browser by clicking its icon




ii.                   Type “ps -eF”. This will display all processes. If we wish we can be selective and target the “iceweasel” process directly.
Type ”ps –eF | grep iceweasel” to target the “iceweasel” process directly




From above we can see we have among other things, the Process ID and the Process Name



iii.                 Type “kill -9 32723” to terminate the “iceweasel” process. The browser should no longer be visible on your desktop.






Task 4:
Open an FTP connection to ftp.debian.com (username is anonymous and no password) or to another FTP site.  Open a new terminal, navigate to the Desktop and capture a list of the current network connections to a file called 1.txt.  Quit the FTP connection.  Capture a list of the current network connections to a file called 2.txt.   Run a command to compare the contents of the files 1.txt & 2.txt. What command did you use? What does this command do? Are there any switches that will give you more information?  What differences do you see in the files? Why are they different?  Lastly, delete 1.txt and 2.txt.


Once again, similarly to the tasks above, complete the steps below
i.                     Type “ftp ftp.debian.com
ii.                   At the prompt, type username “anonymous
iii.                 Press “enter” when asked for a password
Your screen should now look like below

iv.                 As was done in task 1, open a new terminal window
v.                   Type “netstat –nltp > 1.txt”. This will obtain the current network connections and redirect the results to a file name “1.txt
vi.                 Type “quit” to exit the ftp session
vii.               Type “netstat –nltp > 2.txt”. This will obtain the current network connections and redirect the results to a file named “2.txt
viii.             To compare the difference between the two files type “diff 1.txt 2.txt”. This will show what is different between these two files.
ix.                 Type “rm –rf 1.txt 2.txt” this will delete both file “1.txt” and “2.txt” at the same time.





References:
http://linux.die.net/man/1/diff
http://linuxcommand.org/lc3_man_pages/cdh.html

http://linux.die.net/man/1/ls
http://linux.die.net/man/1/mkdir
http://unixhelp.ed.ac.uk/CGI/man-cgi?rm
http://linux.die.net/man/1/ps
http://unixhelp.ed.ac.uk/CGI/man-cgi?grep
http://linux.die.net/man/1/kill
http://unixhelp.ed.ac.uk/CGI/man-cgi?ftp
http://linux.die.net/man/8/netstat
http://unixhelp.ed.ac.uk/CGI/man-cgi?diff

1 comment: