My linux world » File System Survival Guide

File System Survival Guide



Manage partition

# to create a partition for the disk /dev/sda:
cfdisk /dev/sda
# to format your partition /dev/sda1 in ext4
mkfs.ext4 -j /dev/sda1

Extend partition

# Add 100G to /dev/sda1:
lvextend -L +100G /dev/sda1

Mount FileSystem

Mount local disk

In your /etc/fstab, add this lines:

/dev/sda1 /mnt/my-local-disk                     ext4    defaults        1 1

Mount windows shared directory

using smbfs

#install Samba File System:
yum -y install smbfs smbclient
# create directory to mount the shared directory:
mkdir /mnt/windows
# mount :
mount -t smbfs //my/windows/shared/directory /mnt/windows -o username=username,password=password

using cifs

#install Samba File System:
yum -y install cifs-utils
# create directory to mount the shared directory:
mkdir /mnt/windows
# mount :
mount -t cifs //my/windows/shared/directory /mnt/windows -o username=username,password=password,defaults,auto,rw,users,exec
# add this line to /etc/fstab
# //my/windows/shared/directory         /mnt/windows      cifs username=username,password=password,defaults,auto,rw,users,exec            0 0

Mount ssh directory

#install Samba File System:
yum -y install sshfs
# create directory to mount the shared directory:
mkdir /mnt/ssh
# mount :
mount -t sshfs root@myserver:/var/www /mnt/ssh

* Mount ext4 (add this line to /etc/fstab):

sshfs#root@myserver:/var/www       /mnt/ssh      fuse   defaults 0 0


fuse: bad mount point `/mnt/mountpoint’: Transport endpoint is not connected

umount -l /mnt/mountpoint
mount /mnt/mountpoint

Mount nfs

echo "install nfs"
yum -y install nfs-utils nfs-utils-lib
echo "start nfs on startup"
chkconfig rpcbind on
chkconfig nfs on
echo "start service"
service rpcbind start
service nfs start
# add this line to /etc/fstab
# myserver:/remote/export  /local/directory   nfs      rw,sync,hard,intr  0     0

Mount ftp

echo "install curlftpfs"
yum -y install curlftpfs
# mount:
curlftpfs ftp://ftpuser:ftppassword@myftpserver /mnt/ftp

Mount cdrom

mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom


Find a file containing a string

find /my/path -name "*" -exec grep -Hn "mystring" {} \;

Remove all *.tmp files

find /my/path -name "*.tmp" -exec rm -rf {} \;

Get the top 10 disk use

du -sh * | sort -h -r | head -10

Only list folders

ls -d -- */

Retrieve bash script execution directory (to use under your bash script)

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

Get the most recent element in the current directory

ls -Art | tail -n 1

Copy files by extension recursively

find /path/to/srcdir -name '*.txt' | cpio -pdm /path/to/destdir
# Note: we can use '-updm' for overwrite destination content.

Remove files older than 5 days

find /path/to/files* -type f -mtime +5 -exec rm {} \;

You can also write :

find /path/to/files* -type f -mtime +5 -delete

find all files that does not have 777 permissions

find /path/to/files* -not -perm 0777

Copyright © 2023 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.

Fork me on GitHub