mirror of
https://github.com/autistic-symposium/shell-whiz-toolkit.git
synced 2025-08-21 20:28:22 -04:00
move shell scripts and zsh and add fav vscode themes
This commit is contained in:
parent
40077637ce
commit
e6794a8954
43 changed files with 55 additions and 34 deletions
97
shell/shell_scripts/lessons/TRICKS.md
Normal file
97
shell/shell_scripts/lessons/TRICKS.md
Normal file
|
@ -0,0 +1,97 @@
|
|||
Wild Cards
|
||||
----------
|
||||
|
||||
Use *, ? (for one char), and [abc] for a series of options. Example:
|
||||
|
||||
$ ls [abc]*
|
||||
|
||||
|
||||
More commands on one line
|
||||
-------------------------
|
||||
|
||||
Use ;
|
||||
$ date;who
|
||||
|
||||
|
||||
Redirection of Standard output/input
|
||||
-----------------------------------
|
||||
|
||||
>, >>, <
|
||||
|
||||
Examples:
|
||||
|
||||
$ sort < filename > sorted_names
|
||||
|
||||
|
||||
Pipes
|
||||
-----
|
||||
A pipe is nothing but a temporary storage place where the output of one command is stored and then passed as the input for second command.
|
||||
|
||||
|
||||
Processes and PID
|
||||
-----------------
|
||||
An instance of running command is called process and the number printed by shell is called process-id (PID), this PID can be use to refer specific running process.
|
||||
|
||||
ps - show current running
|
||||
kill {PID} - kill process
|
||||
kill 0 - stop all processes except shell
|
||||
& - background process
|
||||
ps aux - display the owner of the processes along with the processes
|
||||
ps -ag - get information of all running processes
|
||||
ps ax | grep processes-you-want-to-see
|
||||
top - see currently running processes and other information like memory and CPU
|
||||
pstree - display a tree of processes
|
||||
|
||||
|
||||
|
||||
Useful Cmds:
|
||||
------------
|
||||
|
||||
List size of folders
|
||||
$ du -sh *
|
||||
|
||||
Print calendar:
|
||||
$ cal
|
||||
|
||||
Writing and creating a file:
|
||||
$ cat > NEWFILE
|
||||
|
||||
--- write here ---
|
||||
^D
|
||||
|
||||
|
||||
De-bug Shell Script
|
||||
-------------------
|
||||
|
||||
Use -v and -x option:
|
||||
$ sh option SCRIPT
|
||||
$ bash option SCRIPT
|
||||
|
||||
|
||||
Local and Global Variables
|
||||
-------------------------
|
||||
|
||||
Whenever you type:
|
||||
$ /bin/bash
|
||||
You start a new shell where the previous variables will be forgotten (local variables). To make variables global, you can do:
|
||||
$ export VARIABLE-NAME
|
||||
Before changing shell.
|
||||
|
||||
|
||||
Conditional Execution
|
||||
---------------------
|
||||
|
||||
The control operators are && (AND) and || (OR).
|
||||
$ rm myf && echo "File is removed successfully" || echo "File is not removed"
|
||||
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
$ SayHello()
|
||||
{
|
||||
echo "Hello $LOGNAME, Have nice computing"
|
||||
return
|
||||
}
|
||||
To execute this SayHello() function just type it name as follows:
|
||||
$ SayHello
|
Loading…
Add table
Add a link
Reference in a new issue