Navigation
pwd
pwd
Affiche le dossier courant.
ls
ls -lah
Liste les fichiers et dossiers.
cd
cd /etc cd ~ cd .. cd -
Change de dossier.
Fichiers et dossiers
mkdir
mkdir test mkdir -p parent/enfant
Crée un dossier. -p crée aussi les dossiers parents manquants.
touch
touch fichier.txt
Crée un fichier vide ou met à jour sa date.
cp
cp fichier.txt copie.txt cp -r dossier/ sauvegarde/
Copie un fichier ou dossier.
mv
mv ancien.txt nouveau.txt mv fichier.txt /tmp/
Déplace ou renomme.
rm
rm fichier.txt rm -r dossier rm -rf dossier
Supprime un fichier ou dossier.
⚠️ rm -rf est dangereux. Vérifie toujours le chemin.
Lecture / édition
cat
cat /etc/hosts
Affiche tout le contenu.
less
less /var/log/syslog
Lit page par page.
head
head -n 20 fichier.log
Affiche le début.
tail
tail -f /var/log/syslog
Affiche la fin. -f suit en direct.
nano
nano fichier.txt
Éditeur simple.
vim
vim fichier.txt
Éditeur puissant mais moins intuitif.
Recherche
find
find /home -name "*.txt" find . -type f find /var/log -mtime -7
Recherche fichiers/dossiers selon nom, type, date.
grep
grep "erreur" log.txt grep -i "apache" log.txt grep -r "password" /etc
Recherche du texte.
xargs
find . -name "*.log" | xargs grep "error"
Transforme une liste en arguments pour une commande.
Redirections et pipes
| Syntaxe | Rôle | Exemple |
|---|---|---|
| | Envoie la sortie vers une autre commande | ls -l | grep .txt |
> | Écrit en écrasant | echo test > fichier.txt |
>> | Ajoute en fin de fichier | echo test >> fichier.txt |
2> | Redirige erreurs | commande 2> erreurs.log |
&> | Redirige sortie + erreurs | commande &> tout.log |
Archives
tar
tar -czvf backup.tar.gz dossier/ tar -xzvf backup.tar.gz
Crée ou extrait des archives tar/gzip.
zip
zip archive.zip fichier1 fichier2
Crée une archive zip.
unzip
unzip archive.zip
Extrait une archive zip.