Once in a while, as programmers or system administrators, we face the need of issuing commands we might not remember by heart. So I came out with the following list (to be constantly updated) related to this topic.
I have been using mostly the CentOS and Ubuntu distros, so most of them may be applied in most Linux flavours.
Finding files and content
Find a file, by filename recursively:
find . -name “composer*”
Find a file, by filename, recursively, case insensitive
find . -print | grep -i composer.phar
To search inside symbolic links:
find -L . -name “composer*”
For find only FILES, mention -type f
find -L . -type f -name “composer*”
For find with REGEX
find -L . -type f -iname “composer.
Find file containing a text (pattern) -r = recursive, -n number of line -w stand for all word -l could be lower case
My prefered
grep -rnw ‘/path/to/somewhere/’ -e ‘pattern’
grep -rnw . –color –exclude-dir={custom,vendor} -e ‘$_GET’
Showing only folders when needed
grep -r [regex to find] [path to search] | awk -F: ‘{print $1}’ | uniq
Replacing recursively a text for another recursively
find /path/to/files -type f -exec sed -i ‘s/oldstring/new string/g’ {} \;
Check directory and files size in Linux
View directories
du -h dirunix/
View directories and files
du -ah dirunix/
View a summary
du -sh dirunix/
Empty big huge great files content in Linux
#du -sh access.log
1.1G
#> access.log
or
#true > access.log
or
#cat /dev/null > access.log
or
#cp /dev/null access.log
or
#echo -n “” > access.log # -n stands for null
or
#truncate -s 0 access.log
#du -sh access.log
0
ZIP File operations
Include just cetain types of files or directories
zip -r foo website_folder -i ‘*.php’ ‘*.html’ ‘*.js’ ‘*.css’
Exclude files or dir: -x e.g.
Directory: zip -r archivename.zip directorytozip -x “*.git*”
File: zip -r archive.zip directory -x “*.jpg”
Superfind – replace for rebuild a current line
chech the name of the disks you have:
fdisk -l
Disk /dev/vda: 406.9 GB, 406948155392 bytes, 794820616 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0004d19d
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 209715207 103808004 8e Linux LVM
Run the following sequence of commands:
E.g. fdisk /dev/vda (command n),(command p), (partition number – next free number), (enter for the cilinders) , (command t), (number of the instance 4), type 8e (Linux LVM), print part table (command p) write (command w) reboot
partprobe
pvcreate /dev/sda4
vgextend (volumeName) /dev/sda4
To check the volume name
vgs
e.g.
VG #PV #LV #SN Attr VSize VFree
vg_main 1 5 0 wz–n- <99.00g 1.00g
e.g. vgextend centos /dev/sda4
pvscan
lvsdisplay
lvextend /dev/centos/root /dev/sda4
resize2fs /dev/centos/root (not working)
xfs_growfs /dev/centos/root
References:
https://www.rootusers.com/how-to-increase-the-size-of-a-linux-lvm-by-expanding-the-virtual-machine-disk/