Bash
CLI
tool
Bash is a command line tool and language.
Files
List files
- Number of files in a provided directory
- ```bash ls [myDirectory] | wc -l
### Manipulate Files
Remove directory tree with all its contents
: ```bash
rm -rf [myDirectory]
File Permissions
- Show access permissions of file in directory
- ```bash ls -l [myDirectory]
Change permissions of file
: ```bash
chmod u=rwx,g=rwx,o=rwx [myFile]
Control structures
- Use commandline arguments
-
The
while getopts :c:t flag do case "${flag}" in c) config=${OPTARG} python3 file_to_be_called.py -c $config ;; t) python3 file_to_be_called.py -t ;; :) echo "No arguments passed" exit 1 ;; ?) echo "Please call the script like this: bash_script.sh [-c config_file]" exit 1 ;; esac done:before the flag-characterclets you handle errors yourself (e.g. no arguments passed and wrong arguments passed). The:after the flag-charactercindicates that a value is required after the flag.
Processes
- List running processes
- ```bash htop
Commands |
----------------------------------------------|---
Help |
Kill process | <kbd>k</kbd>
Order processes by memory consumption |
Filter processes by user |
Display files used by the selected process |
Display user threads |
: {tbl-colwidths="[50,50]"}
Kill process
: ```bash
kill -9 [process-PID]
- Info on resource usage & processes on NVidia graphic cards
-
nvidia-smi