SPACE
for next slideShift+SPACE
for previous slide*nix represents Unix and Unix like systems
"Hello World!"
program$ echo 'Hello World!' Hello World! $ █
These variables govern the way applications communicate with the OS to access certain resources.
Some examples are:
pwd
- Shows value of $PWD
ls
- List files in $PWD
cd path
- Change $PWD
A path defines the location of a file in the file system
~ |
Home directory |
. |
Current directory |
.. |
Previous directory |
/ |
Root directory |
man ls # Manual entry for ls help pwd # Shell's pwd help /bin/pwd --help # Command specific help
uptime -p
up 2 days, 23 hours, 38 minutes
"/"
- The Root directorywhich cmd
- Prints path of an executable/sbin
, /bin
- Location of commonly used binaries/home/username
- Home folder of username
/boot
- Boot files are located heremkdir <dir_name>
touch <file_name>
cat <file_name>
rmdir <dir_name>
Use this when safety is the first priority
rm -rf <dir_name>
-r | Recursively |
-f | Force |
M
= ESC
or Alt
^
= Ctrl
It is a modal editor.
Mode | Comment |
---|---|
Command | Pressing shortcuts |
Insert | Inserting text |
Command line | Writing commands |
:q!
- Force Quitdd
- Deletes a linev
- To enter visual mode
Use h
, j
, k
and l
keys to select the region.
:x
- Save and Quit:set autoindent
- Auto indentCtrl+C
sends force quit signal to a running processCtrl+Z
to pause a process<full_command> &
ps -e # Gives simple list ps aux # Gives verbose list top # Priority based ordering of processes
kill 1234 # Like ^C killall -9 firefox # Force kill
ls -l > ls.txt # stdout to ls.txt ls /x 2> lserr.txt # stderr to lserr.txt cat < ls.txt # stdin from ls.txt
grep
- Finding a string in file(s)grep import file1 file2 # Find "import" in file1 and file2 grep -r import dir # Recursively search in a dir grep -n import file1 # Show line numbers of matches grep -i import file1 # Ignore case grep -rI import *.txt dir *.py # Ignores binary files
find
- Finding a file in a dirfind dir -name '*.py' # Remember the single quote find dir -iname '*sys*' # Case insensitive search find dir -type f -name '*.ini' # Only show files find dir -type f -empty # Show empty files only
head
- Show first few linestail
- Show last few linesPassing output from one program to another
ps -e | grep py
Use one program’s output as a parameter of another command
ls -l `which python`