Thursday, May 11, 2017

Linux Command Line Basics


For a Mac user who is familiar with bash shell, you already know a lot about the command line and how to install software in the black. What adds to your knowledge reserve is the server-side operation, which is becoming more common if handling bigger data.
Host OS: an operating system that’s installed directly on your physical computer.
Guest OS: OS installed indirectly, using a virtual machine (VM) software such as VirtualBox. VMs isolate programming projects from everything else without disrupting their day-to-day environment.
Install VirtualBox and Vagrant. My previous post has some more details when VM is used for psql.
Download the vagrantfile, cd to the target folder.
vagrant up   # download the 1.67 GB .vmdk file
vagrant ssh  # enter ubuntu 14, use 25% memory
ls
pwd
cd
curl http://udacity.github.io/ud595-shell/stuff.zip -o things.zip
sudo apt-get install cowsay
cowsay good morning
cowsay -e ^^ good morning
cowsay -f tux good morning
man conwsay
q  # exit manual
apropos working directory
bc # simple calculator
default shell on most Linux and Mac is GNU Bash.
bash --version
hostname
host udacity.com
date
history
rm xx.txt  # equal to os.remove("xx.txt")
uptime
(ctrl+r)  # search previous command
unzip things.zip
cat bivalves.txt  # read short file
less xx.txt  # read long file
wc bivalves.txt   # word count: lines,words,bytes
diff file1, file2  # show difference
nano xx.txt  # edit file. ctrl+key is shortcut
ping 8.8.8.8 # connect to another computer
  • use quote”” or backslash\ if the file name has special symbols or space
  • / is root, means absolute path
  • ../ is one-level up parent of current work directory
  • . path from root to current work directory
  • ~ / home directory
  • otherwise is a relative path, which is more convenient
package source list
cat /etc/apt/sources.list
sudo apt-get update   # update info
sudo apt-get upgrade  # upgrade software
sudo apt-get install finger
cat /etc/passwd  # record of all users !
sudo adduser student
ssh student@127.0.0.1 -p 2222
search package at http://packages.ubuntu.com
Linux distributions:
  • Red Hat: Enterprise level
  • Ubuntu: free and ease of use
  • Linux Mint Desktop users with proprietary media support
  • CoreOS: clustered, containerized deployment of apps.