+ - 0:00:00
Notes for current slide
Notes for next slide

A very short list of some useful commands

Now we will present you small bunch of Linux commands and how to use them. There is a lot of... so don't hesitate to search yourself.

There is also short/condensed version of this page here.

1 / 18

General

man / tldr / explainshell.com / history

2 / 18

man : an interface to the reference manuals

It's still the absolute reference : RTFM & RTMF

man [command]

Example :

[user@localhost ~]$ man more
MORE(1) User Commands MORE(1)
NAME
more - file perusal filter for crt viewing
SYNOPSIS
more [options] file...
DESCRIPTION
more is a filter for paging through text one screenful at a time.
...

But sometimes

  • it's not so easy
  • even if you read the manuel : you are not sure how to use the command
  • some new commands/software come event without man (--help option)
  • GIYF/GETA : Google is your friend/Google est ton ami
3 / 18

tldr : Modern days man

tldr-pages : online collection of community-maintained help pages, that aims to be a simpler complement to traditional man pages.
tldr : a client to use tldr-pages directly from shell (command line)

[user@localhost ~]$ tldr more
more
Open a file for interactive reading, allowing scrolling and search. More information:
https://manned.org/more.
- Open a file:
more path/to/file
- Open a file displaying from a specific line:
more +line_number path/to/file
- Display help:
more --help
- Go to the next page:
<Space>
[skip]
  • Online (or offline cache)
  • much more simple and with very useful example
  • sometimes is not available
  • just a simple version for the man page, it's NOT an alternative. Sometimes, you should read the man pages patiently ;)
4 / 18

Another useful site/tool

https://explainshell.com/

💡 NOTE

90% of this presentation were prepared using tldr and explainshell

5 / 18

history : Command-line history.

- Display the commands history list with line numbers:
history
- Display the last 20 commands (in `zsh` it displays all commands starting from the 20th):
history 20
  • Check $HISTSIZE, $HISTFILESIZE
  • Check $HISTTIMEFORMAT (export HISTTIMEFORMAT='%F %T ')
  • !numero de command : relaunch the command
6 / 18

Files

cd / ls / pwd / chmod / find / less / cat / tail / du / df / which

7 / 18

cd path/to/directory : change the current (working) directory

  • cd : Go to the home directory of the current user

ls : list directory contents

  • ls -a : list all files, including hidden files
  • ls -l : long format list (permissions, ownership, size, and modification date)
  • ls -lh : same as "-l" but size displayed using human-readable units (KiB, MiB, GiB)
  • or even ls -alh

pwd : print name of current/working directory (where am I ?)

[paul@localhost ~]$ cd git
[paul@localhost git]$ pwd
/home/paul/git
8 / 18

chmod : change file (everything is a file) rights (mode bits)

  • chmod 777 file : give all rights for owner, his group and all others
  • chmod u+x file : give the [u]ser who owns a file the right to e[x]ecute it
  • chmod u+rw file : give the [u]ser rights to [r]ead and [w]rite to a file/directory
  • chmod g-x file : remove e[x]ecutable rights from the [g]roup
  • chmod -R 740 directory : set rights for directory and all files inside (owner=all, group=read, others=nothing)
  • bits mode : rwx = 7 = 4(r) + 2(w) + 1(x)
9 / 18

find : search for files in a directory hierarchy

  • find . -name '*.ext' find files by extension in current directory (.)
  • find root_path -type d -iname '*lib*' find directories matching given name, in case-insensitive mode in root_path
  • find /home/user/tmp/ -type f -empty -delete find empty (0 byte) files and delete them in /home/user/tmp (Be Careful!!!)

grep : print lines matching a pattern

  • grep "pattern" file : search pattern in file
  • grep -Ri "pattern" : search (ignore-case) in all files in current directory (and sub-directories)
  • grep -Ril "pattern" : as above, but just print files with match
  • grep -in "pattern" file : search pattern in file and print line-numbers
  • pcregrep : a grep with Perl-compatible regular expressions
  • ripgrep : grep written in Rust : faster and powerful (but not everywhere)
10 / 18

less : Open a file for interactive reading, allowing scrolling and search.

😉 less is opposite of more

- Open a file:
less source_file
- Page down / up:
<Space> (down), b (up)
- Go to end / start of file:
G (end), g (start)
- Forward search for a string (press `n`/`N` to go to next/previous match):
/something

cat : print file on the standard output (and concatenate files)

😉 dog is not opposite of cat, opposite of cat is tac

- Print the contents of a file to the standard output:
cat file
- Concatenate several files into the target file:
cat file1 file2 > target_file
- Number all output lines:
cat -n file
11 / 18

tail : output the last part (last N lines) of files

  • tail -n num file : show last 'num' lines in file
  • tail -c num file : show last 'num' bytes in file
  • tail -f file : keep reading file until Ctrl + C (catch cat by tail; never more cat ; cat ; cat ;)

head : output the first part (first N lines) of files

  • head -n num file : show first 'num' lines of a file
  • head -c num file : show first 'num' bytes of a file
12 / 18

du : disk usage (estimate file space usage)

  • du -h path/to/directory : list the sizes of a directory and any subdirectories, in human-readable form

df : gives an overview of the filesystem disk space usage

  • df -h : in human-readable form

which : locate a command/programm in the user's path

  • which executable : search $PATH variable matching executable
  • which -a executable : if there are multiple executables which match, display all
[user@localhost ~]$ which df
/usr/bin/df
13 / 18

Processus

top / htop / ps / kill

14 / 18

top/htop : display live current system state (tasks) / modern version of top

15 / 18

ps : report a snapshot of the current processes

  • ps aux : list all running processes (BSD syntax)
    • ~= ps aux
    • ~= ps -aux (Unix syntax)
  • ps -aef : almost the same (list all running processes), but change format

16 / 18

kill : send a signal to a process (usually to kill/stop it)

- Terminate a program using the default SIGTERM (terminate) signal
kill [process_id]
- Terminate a background job
kill %[job_id]
- Signal to immediately terminate a program (no chance to capture the signal)
kill -s 9 [process_id]
- Terminate a program using the SIGINT (interrupt) signal
kill -2 [process_id]

Some useful codes :

  • 9 = SIGKILL
  • 15 = SIGTERM (default)
  • 2 = SIGINT (Ctrl-C)
17 / 18

Some others very useful commands without explanation

  • cp, mv, rm, cut, sed
  • tar, gzip/gunzip
  • ip a, ping, wget/curl
18 / 18

General

man / tldr / explainshell.com / history

2 / 18
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow