Basic Linux commands

In this course, you will find a summary of all the basic Linux commands to start your career as a Linux system administrator. To master these basic commands, use them regularly on your virtual machine.

For beginners, here is a guide to help you install an Ubuntu virtual machine on VirtualBox.

Here are the basic Linux commands for beginners by category:

System commands

Displays Linux system information:

$ uname

Display kernel version information :

$ uname -r

Shows how long the system has been running, including
average load :

$ uptime

See the host name of the system:

$ hostname

Displays the IP address of the system:

$ hostname -i

See the system reboot history:

$ last reboot

Displays the current system date and time:

$ date

Query and modify the system clock :

$ timedatectl

Displays the month and day of the current calendar:

$ cal

View users currently logged into the system:

$ who

Displays under which name you are logged in:

$ whoami

View user information:

$ finger username

Commands to see the disk usage

Displays the free space on the mounted systems:

$ df -h

Show free inodes on file systems :

$ df -i

View disk partitions, sizes and types

$ fdisk -l

Displays the disk usage in the current directory

$ du -sh

Show target mount point for all file systems

$ findmnt

File management commands

Create a new directory

$ mkdir nomdurepertoire

List files – normal and hidden files and their permissions.

$ ls -al

Displays the file path of the current directory

$ pwd

Delete a file

$ rm nomdufichier

Forcibly deleting a file

$ rm -f nomdufichier

Delete a directory recursively

$ rm -r nomdurepertoire

Forcefully and recursively delete a directory

$ rm -rf nomdurepertoire

Copy the content of file1 to file2

$cp file1 file2

Recursively copies directory1 to directory2. directory2 is created if it is not the case

$ cp -r repertoire1 repertoire2

Rename file1 to file2

$ mv file1 file2

Create a new file

$ touch nomdufichier

Places the standard input in a file

$ cat > nomdufichier

Displays the content of a file

$ more nomdufichier

Display the first 10 lines of a file

$ head nomdufichier

Display the last 10 lines of a file

$ tail nomdufichier

Encrypt a file

$ gpg -c nomdufichier

Decrypt a file

$ gpg nomdufichier.gpg

File transfer

Securely copy file1.txt to server2 in the /tmp directory

$ scp fichier.txt serveur2/tmp

Synchronize the contents of the /home/apps directory with the /backup directory

$ rsync -a /home/apps /

Switch from one directory to another

Move up one level in the directory tree

$ cd ..

Change directory to $HOME

$ cd

Switch from a directory to a /test directory

$ cd /test

File authorization

Change the file permissions of the octal file

$ chmod octal nomdufichier


Set rwx permissions on the owner, group, and everyone (anyone else who has access to the server)

$ sudo chmod 777 /data/test.txt

Set rwx on the owner and r_x on the group and everyone

$ sudo chmod 755 /data/test.txt

Define rwx for the owner, rw for the group and everyone

$ sudo chmod 766 /data/test.txt

Change the owner of the file

$ sudo chown proprietaire sonfichier

Compression or Archive

Create an archive file called “text.tar” from the “text” file

$ tar -cf text.tar text

Extract the archive file ‘file.tar’.

$ tar -xf file.tar

Compress a file with the .gz extension

$ gzip fichier

System Connection Commands

Securely connect to the host as a user using ssh

$ ssh user@host

Securely connect to the host using a specified port

$ ssh -p portnumber user@host

Securely connect to the system via the default SSH port 22

$ ssh host

Connect to the host via the default telnet port 23

$ telnet host

Network configuration commands

Displays IP addresses and all network interfaces

$ ip addr show 

Assigns the IP address to the eth0 interface

$ ip address add dev

Display IP addresses of all network interfaces

$ ifconfig

The ping command sends an ICMP echo request to establish or test a
connection between equipment

$ ping host

Retrieve more information about a domain name

$ whois domain

Retrieves DNS information about the domain

$ dig domain

Performs a reverse search on a domain

$ dig -x hote

Perform an IP search for the domain name

$ host

Displays the local IP address

$ hostname -i

Download a file from an online source

$ wget link_to_file

Displays all active listening ports

$ netstat -pnltu

User management commands

Displays the details of the active user, for example: uid, gid and groups

$ id

Display the last connections in the system

$ last

Indicates who is connected to the system

$ who

Adds the admin group

$ groupadd admin

Adds the user Sam

$ adduser Sam

Delete user Sam

$ userdel Sam

To change / modify user information

$ usermod

Search Commands

Search for a given pattern in files

$ grep 'pattern' file

Recursively search for a pattern in a given directory

$ grep -r pattern repertoire

Find all instances of the file

$ locate fichier

Find the file names that start with “index” in the /home folder

$ find /home/ -name

Find files larger than 80000k in the start folder

$ find /home -size

Installing package

Installing an rpm package

$ rpm -i fichier.rpm

Delete an rpm package

$ rpm -e fichier

Install the package using the dnf utility

$ dnf install fichier

Install a source file (compilation)

$ ./configure
make install

Process Related Commands

Show currently active processes

$ ps

Search for the process ID ‘telnet’.

$ ps aux | grep ‘telnet’

Displays the process memory map

$ pmap

Show all running processes

$ top

Terminate the process with a given pid

$ kill pid

Kill or Terminate all processes named proc

$ killall proc

Sends a signal to a process with its name

$ pkill nomduprocessus

Resumes suspended work in the background

$ bg

Brings suspended processes to the forefront

$ fg

Putting the n process first

$ fg n

Lists files opened by processes

$ lsof

Runs a process with a very low priority

$ renice 19 PID

Find Firefox Process ID

$ pgrep firefox

Visualization of processes in a tree model

$ pstree

Commands for information Material

Displays startup messages

$ dmesg

Show more information about the processor, e.g. model, model, name, cores, vendor ID

$ cat /proc/cpuinfo

Displays more information about the hardware memory, e.g. Total and free memory

$ cat /proc/meminfo

Displays information about the system hardware configuration

$ lshw

See information on block devices

$ lsblk

Displays the free and used memory in the system (indicator -m indicates the memory in MB)

$ free -m

Display PCI devices in a tree diagram

$ lspci -tv

View USB devices in a tree diagram

$ lsusb -tv

Displays BIOS hardware information

$ dmidecode

Display information about the data on the disk

$ hdparm -i /dev/xda

Performs a read speed test on the xda device

$ hdparm -tT /dev/xda

Test the unreadable blocks on the disk

$ badblocks -s /dev/xda

Domain Search – Domain Tools

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.