=!hostname
hn0] hn[
'Jupiter-2.local'
Nice Linux tutorial.
There are many shells one can use, Mac default is zsh
(located at /bin/zsh
). I set up PyCharm to use it as well in the Preferences\Tools\Terminal\Shell Path
Bash/zsh comment is the same as python: #
# To open Pycharm/VSCode from terminal:
open -na "PyCharm.app" .
open -na "Visual Studio Code.app" .
# To open a finder from terminal:
open .
To open terminal from folder I added a shortcut: Control + Alt + Shift + T
To see hidden files on Mac in finder: Command + Shift + .
history
: To see command history
!10
: to call command on line 10
!!
to call last command
!string
to call last command that starts with string
history -c
to clear history
To replace chars inside a string:
ls
commandTo count files in a folder from terminal:
recursively:
find <directory> -type f | wc -l
for example:
ls '/Users/nenad.bozinovic/work/Frame/elasticity_logs' | head -4
to see file sizes:
to see size of the whole folder:
to see hidden files:
Sorts by the last date modified:
goes to previous folder:
tree
commandTo see tree of directories use tree
command:
To install on Linux:
to install on Mac:
To zip/unzip gz:
Install gnu-tar if seeing warning with the tar
, then use gtar
:
To zip:
gtar -zcvf myfolder.tar.gz myfolder
gzip filename # zip it back
gzip -k filename # to zip it and keep original
to see the content of a zipped file:
to unzip:
To download a file from URL:
From Google drive (FILE_ID can be found in the sharable link between /d
and /view
):
Print path:
Homebrew is a package manager for macOS, it might have some unique packages that pip doesn’t have, to install wget
for example:
To install package:
When using []
with pip
it is important to use ""
to avoid shell parsing for example:
To see version of the package installed:
To see all packages installed:
Command | Explanation |
---|---|
i |
insert mode |
Esc | exit insert mode |
:w |
Saves the file you are working on |
:w [filename] |
Allows you to save your file with the name you’ve defined |
:wq |
Save your file and close Vim |
:q! |
Quit without first saving the file you were working on |
v |
visual mode, this allows you to select the text you want to copy |
y |
yank (i.e. copy) |
p |
paste |
To be able to use ip
:
Before you generate ssh key pair check if you have one:
In order to establish ssh connection with other servers (GitHub, Paperspace, etc) one must set exchange ssh public keys.
To generate ssh key pair (rsa
type) use:
(you should see id_rsa
and id_rsa.pub
files that relate to private and public keys).
To print public key:
You can directly copy the key to the remote machine if you know username and the server address (use whoami
and hostname
to get user@server):
To see all remote machines added to local computer:
cat ~/.ssh/config
To change the prompt when ssh into a machine edit .bashrc
file:
vim ~/.bashrc
Look for the line that sets the PS1
variable, which defines the shell prompt. It may look something like this:
PS1="\u@\h \w $ "
The \u
represents the username, \h
represents the hostname, and \w
represents the current working directory.
Modify the PS1
line to include the desired alias instead of the hostname. For example:
PS1="\u@alias_name \w $ "
To apply the changes, either log out and log back in, or run the following command:
source ~/.bashrc
This will reload the shell configuration file and update the shell prompt.
Use lscpu
to get info about CPU installed (or cat /proc/cpuinfo
). On Mac (sysctl -n machdep.cpu.brand_string
)
Use nvidia-smi
to see GPU stats (nvidia-smi -L
for GPU full name).
Gives for example: /opt/conda/bin/python
Use scp. For example, to copy file to server:
scp fiename.txt root@ip_address:/home/user
scp fiename.txt root@ip_address:/home/user
scp fiename.txt root@ip_address:~ # into home directory
scp fiename.txt root@ip_address:~/new_name.txt
to copy file from server:
scp root@ip_address:~/filename.txt local_path
scp root@ip_address:~/filename.txt . # into current directory
For folders add -r
:
To see status of the copying:
Delete directory:
To get IP address on Linux, use curl this:
lsb_release -a # gives system info like Linux version
uname -a # gives system info like Linux version
cat /etc/os-release # gives system info like Linux version
hostname
whoami
To get a hostname in Jupyter:
To search for a specific file recursively:
where . is current directory.
To hide error messages:
To search for “text” in all filename.txt files:
To get a shasum of a file:
To do this via pipe:
Check if there is x
in front of the name with:
Take from here:
As usual first:
Then find out the GPU driver version:
then install the recommended driver:
you will need to reboot the system after the installation.
sudo reboot
finally check the driver version: