Thursday, 8 October 2015

Command Line - Tutorial 1

  •  Create a file - Write content inside the file - exit 

  1. $nano hello.txt  // create file named "hello.txt"

  2. write down "Hello, I am nano" in the file

  3. Ctrl + o // save a file

  4. Ctrl + x // exit the nano program

  5. Ctrl + g // open a help menu

  6. clear // clear the terminal window, moving the command prompt to the top of the screen


  •  ~/.bash_profile

  1. ~/.bash_profile is the name of file used to store environment settings. (usually called bash profile)

  2. $nano ~./bash_profile // opens up ~/.bash_profile in nano (~ : represents the user's home directory . : indicates the hidden file )

  3. Type the echo "Welcome, Jane Doe"

  4. Ctrl + o , Ctrl + x , clear

  5. $source ~/.bash_profile // activates the changes in ~/.bash_profile for the current session. (source makes the changes available right away)

  • Alias command

  1. in nano ~/.bash_profile, write down alias pd="pwd" (alias command allows you to create keyboard shortcuts for commonly used commands)

  2. Use source ~/.bash_profile to activate the changes to the bash profile for the current session.

  3. Once you type pd in terminal, the output is same as pwd command

  • Assign Variable - export USER="YOUR NAME"

  1. In nano, ~/.bash_profile, write down export USER="your name" (USER is variable, "your name" is a value, export makes the variable to be available to all child sessions initiated from the session you are in)

  2. echo $USER -> return the value of the variable


  • Change default command prompt from $ to >>

  1. In nano, ~/.bash_profile, add new line with export PS1=">> "

  2. and exit after changing it, use a source command

  3. after using source command, you can see the change of command prompt

  • env | grep PATH
  1. env command stands for environment, and return the list of environment variables for the current user. (including PATH, PWD, PS1 and HOME)

  2. If grep is used with PATH, only path will be printed.

No comments:

Post a Comment