Remote connecting with SSH, using basic commands & creating folers+simple text files through a command line

 

Hi, in this post I will go through things like connecting to a computer/server remotely trough SSH, using basic command line commands and how you can easily create & read folders+simple text files.

First we’ll begin by going through what you need:

  1. A working internet connection
  2. A SSH client (For example Putty)
  3. A server/computer you want to connect to

 

Basic command line commands

  • cd = change directory – can be used to switch between file paths
    • cd .. = navigate one directory backwards
    • cd / = navigate to the root folder
    • cd home = navigate from your current folder to a sub-folder inside your current folder called home
    • cd /home/example = navigate to the folder example that is within the home folder
  • ls = list – lists all the files and folders that are located in the specific path in a UNIX enivronment
    • ls = show the contents of the current working directory
    • ls /home/example = list the contents of the example folder
    • ls /home/example /home/example2 = show the contents of the folders example and example2
  • dir = directory – lists all the files in a directory. This is the Windows version of the ls command
    • dir Windows Users = lists the contents and size of the folders Windows and Users. NOTE: you must be inside the PARENT directory in order to get the command to work
  • pwd = print working directory – tells you your current file path in a UNIX environment. Windows command line shows the file path all the time so this isn’t needed in windows. For instance if you’re in the folder example, but don’t know/remember the full directory you can type pwd and you’ll get a output like this: /home/example
  • mkdir = make directory – creates a folder
    • mkdir example = creates a folder called example in the current working directory
    • mkdir example /home/example = creates a folder called example in the folder /home/example
    • mkdir example example2 example3 = creates the folders example, example2 and example3 in the current working directory
  • nano = a text editor for Unix environments that is pre-installed in almost every Unix envrionment
    • nano example = create/modify the file example
      • Ctrl+O = save your file
      • Ctrl+X = exit the editor
    • nano example example2 = create two files, nano will first open example and after you’ve either saved/exited example it will open example2
  • notepad.exe = simple text editor for Windows environments that is pre-installed in every version of Windows
    • notepad.exe example.txt = opens up notepad with a text file called example.txt
  • rm = remove – delete files in a Unix environment. NOTE: Be extremely careful when using this command as you might delete all your files if you type the command wrong!
    • -f = forcefully remove file(s)
    • -i = ask for confirmation of every file you want to delete before deleting
    • -r = remove the contents of directories recursively
      • rm -rfi /home/example/ = delete everything in example and the folder itself and ask for confirmation for every single file about to be deleted
  • cp = copy – copy a file/folder
    • -r = copy directories recursively
    • -f = specifies removal of the target file if it cannot be opened for write operations
    • -i = prompts with the name of a file to be overwritten
      • cp example example.backup /home/example = copy example and call the copy example.backup + save the copy into the folder example
      • cp -r /home/example /home/example2 = copy the whole example folder with all of it’s contents into example2
  • mv = move – move a file/folder
    • f = force overwriting the destination
    • -i = interactively process, write a prompt to standard error before moving a file that would overwrite an existing file
      • mv example example2 = rename example to example2
      • mv /home/example/test.txt /home/ = move test.txt from example to home

 

Creating folders & simple text files through the command line

Part 1: Connecting with a SSH client to another computer/server

  1. Open your SSH client (I’m using Putty for this tutorial)
  2. Enter the address you want to connect to, select SSH as type of connection and hit connect (I’ll be connecting to my school computer)
  3.  Accept the security key if prompted
  4. Login with your username & password you have for the remote connection
  5.  You are now connected through SSH

Part 2: Creating folders & simple text files

  1.  Navigate to the folder you want to work in with the cd command
  2.  Let’s create 7 folders called Mon, Tue, Wed, Thu, Fri, Sat & Sun – Type:
    mkdir Mon Tue Wed Thu Fri Sat Sun
  3.  Let’s check that the folders were created – Type: ls
  4. If you see all the 7 folders we can continue by creating 2 text files in every folder. Head over to the Mon folder – Type:
    cd Mon
  5.  Inside type:
    nano one.txt two.txt
  6.  You can now type anything you want into the text file. We’ll leave the files blank for the purpose of this tutorial. To save the file hit: Crtl+O -> Enter
  7.  Hit: Ctrl+X
  8.  one.txt will close and two.txt will now open. Repeat the same steps you did for one.txt
  9.  Now you have 2 text files in your Mon folder called one.txt and two.txt, but how can we get the same file in all the 7 folders? We could repeat the same steps for every folder, but why take the longer route when you can use the cp command?
  10.  We want to copy the 2 .txt files to all the other 6 folders. Type:
    cp {one.txt,two.txt} /path/to/Tue
  11.  Repeat the same command for every folder. NOTE: you can reuse the same command by pressing the upper arrow key
  12. Congratulations! You have now created 7 folders called Mon,Tue,Wed,Thu,Sat,Sun & 2 text files in every folder called one.txt and two.txt

Images for part 1&2 are found below

  12     3  4  5 6

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s