Image1311.Basic Command Memo

Debian GNU/Linux systems have all the graphical applications needed to perform your daily tasks, so why use the command line?

This section gathers some basic commands. For a more complete list, visit the Debian documentation: https://wiki.debian.org/ShellCommands .

The ultimate command : man

11.1.Browse directories

command

action

pwd

Print Working Directory

cd rep

Change Directory to rep

cd

Change Directory to /home/$USER or ~/

cd ..

Browse the parent directory

ls rep

List information about file(s) in rep

ls -a

ls with hidden files displayed

ls -l

ls with size and rights

11.2.Action on files or directories

command

action

mv source target

move the file from source to target

cp source target

copy the file from source to target

cp -R source target

copy the directory source to target

ln source link

create a hard link from source to link

ln -s source lien

create a symbolik link from source to link

touch file

create the file file or update its modification date

mkdir rep

create a repertory rep

mkdir -p rep/rep2

mkdir with creation of parent directory if needed

rm file

remove file

rm -f file

remove the write-protected file

rmdir rep

remove an empty directory

rm -R rep

remove a directory

du -h file or rep

display size of the file file or the directory rep

11.3.View/Compare files

command

action

wc file

Print byte, word and line counts of file

cat file

display the contents of a file

more file

displays file page by page. 'Space'=next page, 'Enter'=next line, 'u'=up

less file

displays file with fine navigation Left/Right/Up/Down/PageUp/PageDown

head -n x file

displays 'x' first lines of file

tail -n x file

displays 'x' last lines of file

tail -f file

dynamicaly display last line of file

diff file1 file2

Displays differences between two text files

diff -u file1 file2

Displays differences between two text files with patch syntax

comp file1 file2

compares two binary files

comp file1 file2 n N

compare two files, file1 from the octet n , and file2 from octet N

11.4.Users and goups

command

action

whoami

Print the current user id and name

who

Print all usernames currently logged in

id

Print user and group id's (uid & gid)

id user

Print user and group id's (root only)

finger user

Print informations about user

write user

Print a message on user 's terminal

tty

Print the current terminal's name

su - sudo

Switch to administrator mode, superuser

passwd

Change the password of the current user

adduser

add a user

deluser

delete a user

addgroup

add a group

delgroup

delete a group

11.5.Process

command

action

ps

Process Status. Lists running process

ps ax

Print all running processes

ps aux

Print all process identified by users

pstree

Print all process in a tree

top

List processes running on the system in a semi-graphical table

kill signal pid

kill a process using its pid

pkill signal name

kill a process using its name

Signals used kill/pkill

signal

action

-1 (HUP)

Reload the process configuration file

-2 (INT)

Interrupt the process

-3 (QUIT)

Quit the process

-9 (KILL)

Kill the process (to avoid, try '-15' first)

-15 (TERM)

Complete the process properly

-18 (STOP)

Freeze the process

-20 (CONT)

Resume execution of a frozen process

11.6.Hardware

command

action

lsusb

Lists connected USB devices

lspci

Lists connected pci devices

cat /proc/cpuinfo

Displays processor information

cat /proc/partitions

Displays mounted partitions

Examples: (sources linuxtrack)

command

action

lspci | egrep "3D|Display|VGA"

Display the model of the graphics card

lspci | grep -i "net" | cut -d: -f3

Show the model of the Wifi card

lspci | grep -i audio | cut -d: -f3

Show the soundcard model

11.7.Network

command

action

hostname

Print or set system name

ping machine

send a ping to a machine on the network (local or not)

traceroute machine

displays a traceroute through machine

netstat

Displays the use of the network by the processes

netstat -a

netstat with the display of the server processes

lsof

Detailed list of file and network usage

ifconfig

Displays the configuration of the network interfaces

ifconfig interface IP masque

configure the network identified by interface

route

Displays the routing table

command

action

curl ifconfig.me

display its public IP

ip address show eth0 | grep "inet " | tr -s " " ":" | cut -d: -f3

displays its locap IP on eth0

/sbin/ifconfig eth0 | grep "inet " | tr -s " " ":" | cut -d: -f4

ip address show eth0 | grep "inet " | tr -s " " ":" | tr -s "/" ":" | cut -d: -f3

11.8.Search

command/option

action

locate pattern

search for file with a pattern name

updatedb

update locate database

find path options

search for file corresponding to options in path

find -name pattern

search for file with a pattern . ex: find -name '*.html'

find -type f/d/l

search by filetype where f=file, d=directory et l=link

find -exec cmd

execute cmd to found files

Example : search for all png files in the 'Images' directory, then copy all files to tmp directory ( '{}' stands for found files).

find $HOME/Images -name "*.png" -exec cp {} $HOME/tmp/ \;

11.9.Archives

format

compress

extract

.tar.bz2, .tbz2

tar -cvjf archive.tar.bz2 directory

tar xvjf

.tar.gz, .tgz

tar -cvzf archive.tar.gz directory

tar xvzf

.bz2

bzip2 file

bunzip2

.rar

-

unrar x

.gz

gzip file

gunzip

.tar

tar -cvf archive.tar files

tar xvf

.zip

zip -r archive.zip files

unzip

.Z

compress files

uncompress

.7z

7z a files

7z x

.xz

xz -z directory

unxz

11.10.Kernel

command

description

cat /proc/version

Version of the Linux kernel used, its name, the version of the compiler used.

uname -r

Version of the Linux kernel used.

dpkg -l | egrep "linux-(header|image)"

List all kernels installed on your machine.

11.11.Links and references

129 https://debian-facile.org/doc:systeme:commandes:gnu_linux

130 https://debian-facile.org/viewtopic.php?id=6190

131 https://www.debian.org/doc/manuals/debian-reference/ch01.html

132 http://www.epons.org/commandes-base-linux.php