Plan du site  
pixel
pixel

Articles - Étudiants SUPINFO

Linux Common Commands

Par Fabrizio ASTA Publié le 02/05/2016 à 13:30:01 Noter cet article:
(0 votes)
Avis favorable du comité de lecture

Introduction

Linux is becoming one of the most used operating system nowadays. It is used for everything, it is flexible and can be personalized graphically, with programs that the user loves to use. But it can be difficult to learn if you are a new entry in the Linux world.

The first thing to do if you are starting to use it just now, is to explore his GUI and learn the basics of how the bash works.

This article is going to help you to understand and learn common commands that you can execute from Bash and how they work.

Have fun and I hope you're going to like my article.

Note that almost all of these commands need superuser privileges to work well. I suggest you to use "sudo" command if you want to execute a command with root privileges. Use it only if you are sure that you are not going to change important filesystem's files.

Sudo (Super User DO) Command

SUDO command is a unix or unix-like command that allow an user to execute a program or a command with security privileges of another user, usually the super user.

If you want to execute a command with superuser privileges, type (for example):

sudo reboot

and write down root's password.

You can find more informations about "SUDO" command on my article at this link:

https://supinfo.com/articles/single/1667-sudo-command

Tar Command

tar stores and extracts files from a tape or disk archive. It works exactly like winrar or winzip for Windows.

To create a new tar archive, type:

tar cvf archive_name.tar /path/name

To extract from an existing archive type:

tar xvf archive_name.tar

To view an existing tar archive, without extracting it, type:

tar tvf archive_name.tar

Grep Command

grep searches the named input files or given strings in a file.

To use it from terminal, type:

grep -i "the" /path/to/file

To search for a given string in all files recursively, type:

grep -r "example" *

You can find more informations and commands about "find" on my article at this link:

https://www.supinfo.com/articles/single/1700-grep-command

Find Command

find searches for files in a directory hierarchy. It searches using file name (it can be used with sensitive or insensitive search)

For example:

find -iname "my_file.txt"

To execute commands on the file, type:

find -iname "test.txt" -exec chmod 777 {} \;

To find all empty files in a directory, type:

find ~ -empty

You can find more informations and commands about "find" on my article at this link:

https://supinfo.com/articles/single/1672-find-and-locate-linux

Locate Command

locate is similar to "find" command, but it works a bit different from it. Locate uses his own database to do faster search in the filesystem. The database must be updated with the command:

sudo updatedb

To use it, type:

locate -i "*.txt"

You can find more informations and commands about "locate" on my article at this link:

https://supinfo.com/articles/single/1672-find-and-locate-linux

Sort Command

Sort is able to order files in ascending or descending order.

To sort rows in descending order, type:

sort names.txt

To sort rows in ascending order, type:

sort -r names.txt

Ls (list) Command

ls display files and directories inside a folder in human-readable format

To list files type:

ls

If you want to print the list with more informations, type:

ls -la

Cd (change directory) Command

cd means "Change directory". cd is used to switch through directories to work with your pc from terminal.

To use it, type:

cd /choose/where/you/want/to/go

If you want to go back to root:

cd /

If you want to go directly to your home folder:

cd ~

If you want to go back to the previously folder:

cd ..

Pwd Command

pwd shows you in which directory you are inside at the moment.

This can be used typing:

pwd

Whoami Command

Shows you what user you are. Type whoami to remember which user you are using if you forgot that.

whoami

Shoutdown Command

To shutdown the system and turn the power off immediately, type;

shutdown -h now

If you want to shutdown your pc after 10 minutes:

shutdown -h +10

If you want to reboot you pc using shutdown command, type:

shutdown -r now

Reboot Command

To reboot your pc from terminal, type:

reboot

Cp (copy) Command

cp allows you to copy a file. It works specifying the file you want to copy and the path in which you want to do a copy.

For example:

cp test /home/fabriziosta/Documents/test_copy.txt

In this example I moved my file and I changed his name too.

Rm (remove) Command

It removes a specified file. For example:

rm ~/Documents/test.txt

If you want to remove an empty directory:

rmdir "directory_path"

If you want to remove a directory and all his content:

rm -r "directory_path

Mv (move) Command

It allows you to move files. It works just like "cp":

mv test ~/Documents/test2.txt

Just as cp, you can move and rename your file easily.

Clear Command

Clear allows user to clean up terminal from any output. It is useful if you want to execute a new command and you want to focus on the new output that will come.

To use clear, just type on a terminal:

clear

Chmod (change permissions) Command

chmod is used to change file or directory permissions. With this command it's possible to give or revoke access and execute permissions for users and groups.

If you want to give all permissions (read, write and execute) to user, type:

chmod u+rwx file.txt

If you want to revoke all permissions for the group on a specific file, type:

chmod g-rwx file.txt

If you want to change permissions recursively to all the files in a directory, type:

chmod -R ug+rwx file.txt

Mkdir (make directory) Command

This command allows to create new folders in the filesystem. To create a new directory, type:

mkdir /home/fabriziosta/music

If you want to create nested directories all-in-one:

mkdir -p dir1/dir2/dir3

History Command

Displays all previous commands from terminal:

history

Cat (concatenate) Command

Cat is used to concatenate multiple files at the same time. For example file1 and file2 output will be printed inside the terminal using:

cat file1 file2

Cat can be used to show what's inside a single file:

cat file.txt

Mount Command

This command is used to mount a file system. At first you need to create a new directory as shown:

mkdir /new_directory_name

mount /dev/sdb1 /new_directory_name

You can also add this to the "fstab" for mounting it automatically everytime the system will be restarted:

/dev/sdb1/new_directory_name ext2 defaults 0 2

Chown (change owner) Command

chown is used to change the owner and group of a file. To do it:

chown friends:fabriziosta file.sh

If you want to change ownership of a directory recursively:

chown -R friends:fabriziosta file.sh

Passwd Command

It is used to change user password from command line. It will request to insert the old password:

passwd

If you want to change another user password, type:

passwd USERNAME

If you want to remove password for a specified user:

passwd -d USERNAME

Ifconfig Command

ifconfig allows user to view and configure a network interface on Linux systems.

To view all the interfaces with status:

ifconfig -a

To start a specific interfaces, use up or down like this:

ifconfig eth0 up

or:

ifconfig eth0 down

Iwconfig Command

It is used to configure a wireless network interface. It is similar to ifconfig but this command is dedicated interely to wireless interfaces.

For example, if you want to change wireless "mode", type:

iwconfig eth0 mode Managed

another example:

iwconfig eth0 mode Ad-Hoc

Uname Command

Uname is used to display important informations regarding the system like Kernel name and release number, Host name, Processor Type and so on.

Type:

uname -a

Whatis Command

To display a single line description about a command:

whatis sudo

But if you want to read the full manual, use "man" instead.

Man (manual) Command

If you want to read everything about a specific command, type:

man "command"

You can find description of every single option available for a command.

Tail Command

tail prints the last 10 lines of a file by default, but this number can be greater or lower.

To use it, type:

tail file.txt

or:

tail -n 99 file.txt

Less Command

less is used for viewing huge log files and read it.

less massive_file.log

Use CTRL+F to move forward.

Use CTRL+B to move backward.

Ping Command

It is used to ping a remote host by sending 5 packets:

ping 8.8.8.8

Free Command

Displays RAM details in Linux:

free

Top Command

Displays CPU processes:

top

"q" can be used to exit.

Df (display filesystem) Command

Displays information about disk space usage of all mounted filesystems:

df - h

Du (directory usage) Command

Displays the size of a directory and all of his subdirectories:

du -h

Su Command

su stands for Super User. It is used to switch from an user to another one and receive his privileges. Commonly it is used to become root. To use it, type:

sudo su

and digit password. If you want to become another user:

su Philipp

and type Philipp's password.

Date Command

Date command is used to set or show the sytem date. To show date, type:

date

To set the system date, type:

date -s "05/05/2016 23:59:59"

Now, you should synchronize your hardware clock with the system date, in this way:

hwclock -systohc

hwclock --systohc -utc

Wget Command

This command is used to download softwares, music and videos from internet through terminal:

wget http://www.website/download/something/from/internet.fr

Apt-get (Debian and his derivates only) Command

Apt-get is a "free package management" command line program, that is used to work with Ubuntu’s APT (Advanced Packaging Tool) library to perform installation, removing packages, upgrading of existing software packages and upgrading the entire operating system.

To list all available packages:

apt-cache pkgnames

To search a package name using apt-cache, type:

apt-cache search "package"

To update your repository:

apt-get update

To upgrade your packages:

apt-get upgrade

To install something in your Linux System:

apt-get install "package"

To install multiple packages:

apt-get install "package1" "package2" .. "package50"

To remove a package from the system, type:

apt-get purge "package" or:

apt-get remove --purge "package_name"

If you want to remove a package and all his dependencies:

apt-get autoremove "package_name"

To clean and free up the disk space, type:

apt-get clean

To clean apt-get cache, type:

apt-get autoclean

To check if there are broken dependencies, type:

apt-get check

(Extra) Easter egg

It is an easter egg that can be found on Debian and his derivates only. To be sure if you are able to launch this easter egg, type:

apt-get help

Something like this should appear:

Last line gives you information about this Easter Egg. I can use it. Now type:

apt-get moo

Now start to add -v option and see what will happen...

apt-get -vv moo

apt-get -vvv moo

apt-get -vvvv moo

apt-get -vvvvv moo

apt-get -vvvvvv moo

And now let's start to insult everyone with sudo!

Insult users with sudo command

If you want that sudo insult all users for you, we must configure it using sudoers file with a tool called "visudo":

sudo visudo

At the top of the file, add this line:

Defaults insults

Save and close the file.

Now, empty the cache that stores passwords for a certain amount of time and try to write your password incorrectly:

sudo -k

sudo su

Conclusion

In conclusion, these are only few commands of the ocean of options and instructions that you can use in Linux terminals. Of course you have to do lot of experience before consider yourself an Expert Linux User, but I assure you that after have learned all this commands, you can consider yourself a beginner and you are not a "new entry" anymore.

Below you can find an image that shows the most common commands for Linux as a summarize of this article.

I hope this article was informative for you and I would like to thank you!

A propos de SUPINFO | Contacts & adresses | Enseigner à SUPINFO | Presse | Conditions d'utilisation & Copyright | Respect de la vie privée | Investir
Logo de la société Cisco, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société IBM, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Sun-Oracle, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Apple, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Sybase, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Novell, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Intel, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Accenture, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société SAP, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Prometric, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo de la société Toeic, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management Logo du IT Academy Program par Microsoft, partenaire pédagogique de SUPINFO, la Grande École de l'informatique, du numérique et du management

SUPINFO International University
Ecole d'Informatique - IT School
École Supérieure d'Informatique de Paris, leader en France
La Grande Ecole de l'informatique, du numérique et du management
Fondée en 1965, reconnue par l'État. Titre Bac+5 certifié au niveau I.
SUPINFO International University is globally operated by EDUCINVEST Belgium - Avenue Louise, 534 - 1050 Brussels