%%script bash
if which python &> /dev/null; then
echo "Python is installed."
echo "Python Version:"
python --version
else
echo "Python is not installed."
fi
Python is installed.
Python Version:
Python 3.9.12
%%script bash
if which python &> /dev/null
then
echo "Java Version"
java --version
else
echo "Java is not installed."
fi
Java Version
openjdk 11.0.20 2023-07-18
OpenJDK Runtime Environment (build 11.0.20+8-post-Ubuntu-1ubuntu120.04)
OpenJDK 64-Bit Server VM (build 11.0.20+8-post-Ubuntu-1ubuntu120.04, mixed mode, sharing)
%%script bash
if which python &> /dev/null
then
echo "Jupyter Core Packages:"
jupyter --version
else
echo "Jupyter is not installed."
fi
Jupyter Core Packages:
Selected Jupyter core packages...
IPython : 8.2.0
ipykernel : 6.9.1
ipywidgets : 7.6.5
jupyter_client : 6.1.12
jupyter_core : 4.9.2
jupyter_server : 1.13.5
jupyterlab : 3.3.2
nbclient : 0.5.13
nbconvert : 6.4.4
nbformat : 5.3.0
notebook : 6.4.8
qtconsole : 5.3.0
traitlets : 5.1.1
%%bash
env
SHELL=/bin/bash
PYTHONUNBUFFERED=1
CONDA_EXE=/home/vardaan/anaconda3/bin/conda
_CE_M=
APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL=1
WSL_DISTRO_NAME=Ubuntu
ELECTRON_RUN_AS_NODE=1
VSCODE_AMD_ENTRYPOINT=vs/workbench/api/node/extensionHostProcess
NAME=Code
PWD=/home/vardaan/vscode/vsstudent/_notebooks
LOGNAME=vardaan
CONDA_ROOT=/home/vardaan/anaconda3
CONDA_PREFIX=/home/vardaan/anaconda3
PYDEVD_IPYTHON_COMPATIBLE_DEBUGGING=1
_=/usr/bin/env
MOTD_SHOWN=update-motd
HOME=/home/vardaan
LANG=C.UTF-8
WSL_INTEROP=/run/WSL/896_interop
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
WAYLAND_DISPLAY=wayland-0
CONDA_PROMPT_MODIFIER=(base)
PYDEVD_USE_FRAME_EVAL=NO
CLICOLOR=1
VSCODE_L10N_BUNDLE_LOCATION=
GEM_HOME=/home/vardaan/gems
LESSCLOSE=/usr/bin/lesspipe %s %s
VSCODE_HANDLES_SIGPIPE=true
TERM=xterm-color
_CE_CONDA=
LESSOPEN=| /usr/bin/lesspipe %s
USER=vardaan
GIT_PAGER=cat
PYTHONIOENCODING=utf-8
CONDA_SHLVL=1
DISPLAY=:0
SHLVL=3
PAGER=cat
VSCODE_CWD=/mnt/c/Users/vards/AppData/Local/Programs/Microsoft VS Code
MPLBACKEND=module://matplotlib_inline.backend_inline
CONDA_PYTHON_EXE=/home/vardaan/anaconda3/bin/python
XDG_RUNTIME_DIR=/mnt/wslg/runtime-dir
CONDA_DEFAULT_ENV=base
WSLENV=ELECTRON_RUN_AS_NODE/w:
VSCODE_WSL_EXT_LOCATION=/mnt/c/Users/vards/.vscode/extensions/ms-vscode-remote.remote-wsl-0.79.5
XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktop
PATH=/home/vardaan/anaconda3/bin:/home/vardaan/.local/bin:/home/vardaan/gems/bin:/home/vardaan/gems/bin:/home/vardaan/gems/bin:/home/vardaan/anaconda3/bin:/home/vardaan/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files (x86)/Mail Enable/BIN:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0:/mnt/c/WINDOWS/System32/OpenSSH:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/Program Files (x86)/Mail Enable/BIN64:/mnt/c/Users/vards/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/vards/AppData/Local/Programs/Microsoft VS Code/bin:/snap/bin
VSCODE_NLS_CONFIG={"locale":"en","osLocale":"en","availableLanguages":{}}
HOSTTYPE=x86_64
PULSE_SERVER=/mnt/wslg/PulseServer
VSCODE_HANDLES_UNCAUGHT_ERRORS=true
VSCODE_IPC_HOOK_CLI=/mnt/wslg/runtime-dir/vscode-ipc-e3aa1971-6d45-4260-896d-a5f0261d2515.sock
TOP 5 MOST USED LINUX COMMANDS:
- cd
- cd stands for “change directory”
- This is often used via WSL to switch between repositories and directories within repositories to access different files
- ls
- ls is Linux’s primary listing method
- Through ls (and it’s many additional parameter extensions) you can list the files in a particular directory
- You can add certain parameters after ls to show hidden files or certain types of file extensions
- cat
- This is more often going to be used when working in the AWS environment
- The command is used to gather the full body of a file and display it in a terminal rather than having to go into a text editor to view it
- sudo
- More than a command, this can be considered a precursor to all the commands you run on Linux when you are a primary editor
- sudo denotes giving yourself root permissions to perform certain actions on your system which a standard user is unable to
- mkdir and touch
- If you need to make a new directory inside of a repository - mkdir is utilized
- If you want to create a new file, you can utilize the touch command inside of the repository you wish to create a file in
Updating a Repository (note: This is not going to work in this notebook because of the location that this file is in, but it can be used via WSL)
%%bash
cd /your/gh/repository
git pull origin master
echo "Job complete."
SIMPLE BASH SCRIPT TO LOOP THROUGH THE DIRECTORY AND CHECK FOR CERTAIN FILE EXTENSIONS.
%%bash
# Checks for certain file extensions (some may be found, some not :))
file_extensions=("ipynb" "csv" "jpg" "pdf")
# No directory specified - SOO, it will check through the local directory (the notebooks folder in this case.)
for extension in "${file_extensions[@]}"; do
echo "Files with .$extension extension:"
find . -type f -name "*.$extension"
echo
done
Files with .ipynb extension:
./2023-08-22-LinuxShellBash.ipynb
./2023-08-22-JavaNotebookIntro.ipynb
./2023-08-23-LinuxShellBash2.ipynb
Files with .csv extension:
Files with .jpg extension:
Files with .pdf extension:
./jimmyjohn.pdf
The above script was partially inspired by something that I have done while competing in cybersecurity competitions.
There are often many insecure file types in a certain business environment, and when competing on a Linux box, I have written scripts to check for these certain file types to search across an entire system. Searching manually takes too much time and is not at all effective, which is why this excerpt of a shellscript is very useful.