First steps with Bash and Linux

Bash is the most standard shell on Unix systems (Linux, MacOS, ...). A shell is a basic programming language to interact with the computer and launch commands.

There are standard commands (corresponding to programs) to do many basic tasks. You can read this short document https://files.fosswire.com/2007/08/fwunixref.pdf.

For example to get the current working directory, one can use:

In [1]:
pwd
/home/pierre/Output/Teach/intro-python/ipynb

We see that we ask pwd and we get an answer (as a string).

There are also commands that do something but does not returb anything, for example cd (for "change directory"):

In [2]:
cd ..
In [3]:
ls
check_env.py  ipynb        Makefile  README.md
install.md    LICENSE.txt  pyfiles   requirements.txt
In [4]:
ls -l
total 32
-rw-r--r-- 1 pierre pierre  641 Sep 25 14:40 check_env.py
-rw-r--r-- 1 pierre pierre 3715 Sep 25 15:31 install.md
drwxrwxr-x 4 pierre pierre 4096 Sep 25 15:42 ipynb
-rw-rw-r-- 1 pierre pierre 1499 Sep 25 14:40 LICENSE.txt
-rw-r--r-- 1 pierre pierre  938 Sep 25 15:10 Makefile
drwxr-xr-x 4 pierre pierre 4096 Sep 25 14:44 pyfiles
-rw-rw-r-- 1 pierre pierre 1655 Sep 25 15:35 README.md
-rw-r--r-- 1 pierre pierre  196 Sep 25 14:52 requirements.txt
In [5]:
ls -a
.   check_env.py  .hg         ipynb        Makefile  README.md         .vscode
..  .gitignore    install.md  LICENSE.txt  pyfiles   requirements.txt
In [6]:
ls -la
total 52
drwxrwxr-x 6 pierre pierre 4096 Sep 25 14:59 .
drwxr-xr-x 7 pierre pierre 4096 Sep 25 13:50 ..
-rw-r--r-- 1 pierre pierre  641 Sep 25 14:40 check_env.py
-rw-r--r-- 1 pierre pierre  190 Sep 25 14:44 .gitignore
drwxrwxr-x 6 pierre pierre 4096 Sep 25 15:40 .hg
-rw-r--r-- 1 pierre pierre 3715 Sep 25 15:31 install.md
drwxrwxr-x 4 pierre pierre 4096 Sep 25 15:42 ipynb
-rw-rw-r-- 1 pierre pierre 1499 Sep 25 14:40 LICENSE.txt
-rw-r--r-- 1 pierre pierre  938 Sep 25 15:10 Makefile
drwxr-xr-x 4 pierre pierre 4096 Sep 25 14:44 pyfiles
-rw-rw-r-- 1 pierre pierre 1655 Sep 25 15:35 README.md
-rw-r--r-- 1 pierre pierre  196 Sep 25 14:52 requirements.txt
drwxrwxr-x 2 pierre pierre 4096 Sep 25 14:59 .vscode
In [7]:
cd ipynb
In [8]:
pwd
/home/pierre/Output/Teach/intro-python/ipynb
In [9]:
cd ..
In [10]:
ls
check_env.py  ipynb        Makefile  README.md
install.md    LICENSE.txt  pyfiles   requirements.txt
In [11]:
mkdir toto
In [12]:
ls
check_env.py  ipynb        Makefile  README.md         toto
install.md    LICENSE.txt  pyfiles   requirements.txt
In [13]:
rm -rf toto
In [14]:
which ls
/bin/ls
In [15]:
echo "toto"
toto
In [16]:
echo $PATH
/data0/opt/miniconda3/condabin/app:/home/pierre/.pyenv/shims:/home/pierre/.pyenv/bin:/home/pierre/.pyenv/versions/3.8.2/bin:/home/pierre/.pyenv/libexec:/home/pierre/.pyenv/plugins/python-build/bin:/data0/opt/miniconda3/condabin/app:/home/pierre/.pyenv/shims:/home/pierre/.pyenv/bin:/home/pierre/.cargo/bin:/data0/opt/miniconda3/condabin/app:/data0/opt/miniconda3/condabin:/home/pierre/.pyenv/shims:/home/pierre/.pyenv/bin:/home/pierre/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/pierre/opt/env_xonsh/bin/
In [17]:
echo $HOME
/home/pierre
In [18]:
ls
check_env.py  ipynb        Makefile  README.md
install.md    LICENSE.txt  pyfiles   requirements.txt
In [19]:
echo "toto" > tmp.txt
In [20]:
ls
check_env.py  ipynb        Makefile  README.md         tmp.txt
install.md    LICENSE.txt  pyfiles   requirements.txt
In [21]:
cat tmp.txt
toto
In [22]:
echo "titi" >> tmp.txt
In [23]:
cat tmp.txt
toto
titi
In [24]:
mv tmp.txt tmp2.txt
In [25]:
ls
check_env.py  ipynb        Makefile  README.md         tmp2.txt
install.md    LICENSE.txt  pyfiles   requirements.txt
In [26]:
mv tmp2.txt ..
In [27]:
ls ..
coursem1_pa_instabilities_turbulence  py-training-2017             tmp2.txt
intro-python                          intro-python  training-hpc
In [28]:
rm -f ../tmp2.txt
In [29]:
ls ..
coursem1_pa_instabilities_turbulence  py-training-2017             training-hpc
intro-python                          intro-python