Linux commands

Usefull Linux commands :

Linux version :

cat /etc/*release
more /etc/*release

CPU infos :

cat /proc/cpuinfo
lscpu
dmesg -h
dmesg | more

Specific directories :

/etc -> General configuration files
/opt -> Additionnal non system libraries
/srv -> Servers : www, nfs, ftp, smaba

Directory stack :

pushd -> Push a directory on the top of the stack (pushd /etc/...)
popd -> Get the last pushed directory from the stack

Finding files and contents :

Will find in « /etc » files with name like « *.service » and adding the string « -devoxx » to the basename of the file :

find /etc -name "*.service" -exec basename {}-devoxx \;

Will find all files in the « /etc » path having the word « system » in it :

grep -rnw /etc -e 'system'

Locate command will find files but in a database where files are indexed. Finding will be faster (find files with « bluetooth » in the name) :

locate bluetooth

Update the ‘locate’ database :

updatedb

System processes :

ctrl + Alt + F1 – F6 : Changes the tty (bus)

List all the the tty :

ps aux | grep tty

stty -> Current tty configuration.

Pseudo tty slave :

ps -aux | grep sty

Permissions :

Permissions are written in the following order : user owner / group owner / others

File informations :

stat /etc/hosts

The first character tells if it’s a file or a directory (File = « -« , Directory = « d »)
(4 == 001 in binary)

List all the connected users :

users

List all the connected users with the associated tty (pts/0 is the X Server) :

who

/etc/passwd -> This file contains all the user passwords and the corresponding shell.

Commands help :

Man command help (You can use the man as in VI. The commands are the same for search…) :

man man

Man command for any shell commands (Java in this example) :

man java

Lists all the commands having the name like the search string :

apropos java

Shows the path of my binary :

which java

Follows a symlink :

readlink /bin/java

Network :

List the active internet connections :

netstat -taupe

Call a specific server, see if he is responding :

ping www.google.fr

Follows a specific server through the network :

nslookup www.google.fr

Hard disks and mount :

Disk usage in MB on the current partition :

du -hsBM .

Disk usage in MB on a spectific partition ordered by weight :

du -hsBM /var | sort -n

Disk usage and free space for all the system (sorted) :

df -h | sort

List all partitions of a specific drive :

fdisk -l /dev/sda

LVM Local Volume Manager :

Creation of Volume Group (vg0) and mount logical devices inside.
To increase the disk space you can add a physical disk in the Volume Group and then resize the logical disks.

Creation of 3 physical disks :

pvcreate /dev/sdb1 /dev/sdb1 /dev/sdb3

List the physical disks :

pvdisplay

Create a Volume Group with 2 disks :

vgcreate vg1 /dev/sdb1 /dev/sdb2

List the Volume Groups :

vgdisplay

Create a logical disk in the volume group (size : 150 Mo) :

lgcreate -l 150M vg1 -n lv1

List the Volume Groups :

lvdisplay

Create a specific file system (Ext4 or other) :

mkfs.ext4 /dev/sdb1
mount ...

Extending an existing volume group :

vgextend vg1 /dev/sdd3

Resize a logical drive (100 Mo) :

lvresize -l 100M /dev/vg1/lv1

Remove a logical drive :

lvremove /dev/vg1/lv1

Remove a volume group :

vgremove /dev/vg1

Remove a physical disk :

pvremove /dev/sdb1

Boot options :

Add parameters to the bootloader :

boot grub + <e>

Load kernel modules :

modeprobe <MODULE_NAME>

Unload kernel modules :

modeprobe -r <MODULE_NAME>

Run level :

0 : Halt
1 : Single User
2-5 : Multiuser
6 : Reboot

Example : /etc/rc.0 -> script launched while shutdown

Systemd & systemctl :

Service status :

systemctl status httpd

Start a service :

systemctl start httpd

Recursively show control group contents (control group ls) :

systemd-cgls

Service tree view (can be exported as image) :

pstree 

Packaging :

yum
apt-get
apt-cache
apt-cache-search

Installation and dependencies :

rpm
dpkg-*

History of shell commands :

History of user commands :

history 

Search in command history : ctrl + r (Up arrow to show items).

Launch the last command beginning with a string :

!<BEGIN_STRING>
!<NUMBER_IN_THE_HISTORY>

Other stuff :

/dev/null -> Redirection to nothing.

 

Publicités

Une réflexion au sujet de « Linux commands »

Laisser un commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s