Skip to content

Linux (Debian, Ubuntu)🔗

Packages🔗

Réf. : http://doc.ubuntu-fr.org/apt-get

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
-- Search installed packages
dpkg -l | grep postgresql

-- Search a package
apt-cache search postgresql

-- Package information
sudo apt-cache show postgresql-server-9.4

-- Remove a package (and its configuration files)
sudo apt-get purge postgresql-server-9.4

-- Remove installation packages (clean)
sudo apt-get clean

Files & folders🔗

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
-- Search a file by name
sudo find /home/xavier -name my_file -print
locate my_file

-- Search a file by content
grep -rnw /path/to/somewhere -e my_pattern

-- Refresh file index database (used by the locate command)
sudo updatedb

-- Compress a file or folder with tar ('tape archiver')
tar -zcvf my_archive.tar.gz my_folder/

-- Uncompress
tar -zxvf my_archive.tar.gz

-- x : extract
-- c : create archive
-- f : use file passed as an argument
-- v : verbose mode
-- z : Gzip compression

-- View the content of a compressed file

-- Method #1
gzip -dc /var/log/syslog.7.gz
-- Method #2
zcat /var/log/syslog.7.gz

Vim Cheatsheet🔗

VIM modes🔗

  • command:
  • is the default mode when vim is opened
  • ESC to go back to command mode

  • insertion:

  • i to enter insertion mode
  • ESC to go back to command mode

Exit VIM🔗

Go back to command mode (ESC) if your are in insertion mode !

Command Description
:q Exit
:q! Exit without saving
:wq Save and exit
Command Description
CTL+B Page up
CTL+F Page down
nG Go to line n
G Go to file end
g Go to first line
^ Go to line start
$ Go to line end
{ Go to paragraph start
} Go to paragraph end
e ou E Go to word end
b ou B Go to previous word
w ou W Go to next word

Actions🔗

Command Description
dw Delete a word
dd Delete a line
x Delete current char
. Repeat last command
5. Repeat last command 5 times

Search in VIM🔗

  • enter the command mode if you are in insertion mode (ESC)
  • / + your search pattern. Eg /ERROR
  • ? + your search pattern to make a new search. Eg ?WARNING
Command Description
ENTER Find first match
n Next match
N Previous match
GN Last match

Useful commands🔗

Software & Hardware configuration (uname)🔗

1
2
3
4
5
6
-- Linux kernel version (ex: 3.13.0-71-generic)
uname -r
-- Processor family (ex: x86_64)
uname -p
-- Hardware platform (ex: x86_64)
uname -i

Know your distrib🔗

1
cat /etc/os-release
1
2
3
4
5
6
7
8
9
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
1
cat /etc/debian_version
1
9.12
1
cat /proc/version
1
2
3
4
5
-- LSB : Linux Standard Base (Information about the Linux distrib)
lsb_release --all
-- Description: Ubuntu 20.04.1 LTS
-- Release:     20.04
-- Codename:    focal

List listening ports🔗

1
sudo netstat -anp

The screen command🔗

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
-- Create a named screen
screen -S my_screen
-- Exit screen
CTL A then CTL D
-- List running screens
screen -ls
-- Go back to screen
screen -r my_screen
-- Exit and close current screen
exit;

Last update: December 20, 2024