Command Line Basics Crash Course
Video - https://www.youtube.com/watch?v=cBokz0LTizk
Given above is a quick super-fast course in using the command line. It is intended to be done rapidly in about a day, and not meant to teach you advanced shell usage.
Practice Drill 1
- Create the following directory structure. (Create empty files where necessary)
hello
├── five
│ └── six
│ ├── c.txt
│ └── seven
│ └── error.log
└── one
├── a.txt
├── b.txt
└── two
├── d.txt
└── three
├── e.txt
└── four
└── access.log
- Delete all the files having the
.log
extension - Add the following content to
a.txt
- Delete the directory named
five
- Rename the
one
directory touno
- Move
a.txt
to thetwo
directory
Pipes and Redirection
Video 1 - https://www.youtube.com/watch?v=Bzd7XfApxLI Video 2 - https://www.youtube.com/watch?v=Bzd7XfApxLI
Practice Drill 2
Pipes
- Download the contents of “Harry Potter and the Goblet of fire” using the command line from here
- Print the first three lines in the book
- Print the last 10 lines in the book
- How many times do the following words occur in the book?
- Harry
- Ron
- Hermione
- Dumbledore
- Print lines from 100 through 200 in the book
- How many unique words are present in the book?
Processes, ports
- List your browser’s process ids (pid) and parent process ids(ppid)
- Stop the browser application from the command line
- List the top 3 processes by CPU usage.
- List the top 3 processes by memory usage.
- Start a Python HTTP server on port 8000
- Open another tab. Stop the process you started in the previous step
- Start a Python HTTP server on port 90
- Display all active connections and the corresponding TCP / UDP ports.
- Find the pid of the process that is listening on port 5432
Managing software
Use apt
(Ubuntu) or homebrew
(Mac) to:
- Install
htop
,vim
andnginx
- Uninstall
nginx
Misc
- What’s your local IP address?
- Find the IP address of
google.com
- How to check if Internet is working using CLI?
- Where is the
node
command located? What aboutcode
?
Submission
Copy and paste the command for each section into a text file with explanation. At the end the exercise upload this file.
CLI Command (for Review):
OS/Process Related Commands:
- ps
- top
- df
- uname
- free
- lspci
- kill (with flags)
Network Related Commands:
- ping
- ifconfig
- ssh
Bash Related Commands:
- xargs
- printenv
- nano
- awk
- sed
- Pipe operator |
Actions that you should be able to perform:
- Create/Read/Update/Delete/Move files and folders from command line
- Check disk status
- Check status of processes, able to extract process ids ( hint: use pipe operator to combine ps, xargs and awk)
- Getting the most senior parent process
- Change file permissions. Able to explain and manipulate the numerical file permissions. (chmod and chown)
- Able to extract last x lines from files, get word count for a particular word, find a particular word. (basics of sed or awk would do)
- Basics of sed and awk.
- learn what is the difference between absolute and relative paths
- Practice using absolute and relative paths
- Learn how to use the find command
- Learn ls with the 5 most commonly used flags used such as: – View hidden files – Sort by time – Reverse sort – Human readable file sizes – Combining flags to get hidden files, sorted by time in reverse with human readable file sizes.
- Find out what are terminal control codes such as Ctrl + D, Ctrl + C, Ctrl + Z etc and use them
- Find out the difference between Ctrl + C and Ctrl + Z
- Find out how to use Ctrl + R to reverse search
- Find out how to use tab autocompletion
- Find out how to use the arrow keys to navigate history
Sample Review Questions:
- Go into your home directory
- Create a directory d1
- Create a file a.txt inside it
- Check permission of a.txt. What are the permissions in decimal format?
- What are three elements in the permission? Do you understand conversion of decimal to binary?
- Change the permissions of a.txt to 755?
- Add a directory d2
- Add b.txt inside d2
- Change permissions of d2 (and everything inside) to 755
- Start the Firefox browser.
- List all processes in your computer
- Find pid of Firefox Browser. Difference between parent process and child process. (hint: you need to learn pipes)
- Kill the process (hint: pipes, awk, xargs, kill)
- What is your user in Linux?
- What is your group in Linux?
- What is your computer architecture? (hint: uname command, learn the flags)
- What is your audio driver? (hint: lspci, learn pipes and grep)
- Go to home folder. Use find command to find all occurrences of “java” text anywhere in any filename or directory name in your system?
- List everything in the home directory to get all files (including hidden), sorted by time in reverse with human readable file sizes.
- Get last x lines for Harry Potter. Get word counts for particular words.
Questions:
- What is the difference between service and application?
- What are these wildcards ~, ., .., * and ??
- What are the different flags for kill? Why do we use kill -9 in general?
- Are you clear about file permissions? Explain them? chmod and chown commands?
- Usage of Ctrl+R to search previously run commands, arrow keys, tab autocompletion.