Disclaimer

This post serves as a cheatsheet going along with the introduction session to Linux I gave to Polytechnique students (slides).

SSH

The first time you try to connect to a computer, you’ll be asked to check if a given certificate is correct. Type y or yes then press enter.

You may find the list of all COMPUTERs on the wikix.

ssh (-i path/private/key) {first}.{last}@{COMPUTER}.polytechnique.fr

Using key

Generate key:

cd ~/.ssh/
ssh-keygen -t ed25519
cat my_key.pub

Upload public key on remote server:

cd ~/.ssh/
nano authorized_keys

SCP

scp my-local.file id@server:~/path/to/copy.file

Commands

ls (-alsh)
pwd
cd path/to
cd (~)
cd -
exit

Managing files

mkdir (-p)
touch
mv
cp (-r)
rm (-rf)
cat
less
tar
zip
unzip

Managing files permissions

ls -l
chown (-R) [user][:group] A
chmod (-R) [ugoa][+-=][rwx] A

Make a file executable for the owner user and then run it:

chmod u+x A
./A

Text editor

nano
vim

Package manager

Here, using apt:

apt update
apt upgrade
apt install A
apt remove A

Help

man command
command --help
command -h

Piping and redirections

command > standard_output_file
command >> concatenated_file
command 2> error_file
command > output_file_standard_and_errors 2>&1
ls | grep my-file

Tips

  • CTRL+C to stop a program
  • command & to start in the background
  • nohup command > output_file 2>&1 to start a program in the background without killing it when closing the SSH session
  • CTRL+Z, fg, bg
  • /dev/null
  • (h)top
  • ps
  • grep
  • sed
  • awk