Linux File Systems

Linux Commands to Manage File Systems

These commands will help you manage various aspects of file systems in Linux. Remember to use them with caution, especially when dealing with important data or system files.

List directory contents

ls /path/to/directory
or
cd /path/to/directory
ls

Change directory

cd /path/to/directory

Come to previous directory

cd ..

Come to main directory

cd

Print working directory

pwd

Make directory

mkdir new_directory

Remove directory

rmdir directory_to_remove

Create an empty file

touch new_file.txt

The different rm command options include:

-f: Forces the removal of all files or directories.
-i: Prompts for confirmation before removing.
-I: Prompts once before removing more than three files or when removing recursively.
-r: Removes directories and their content recursively.
-d: Removes empty directories.
-v: Provides a verbose output.
--help: Displays the help text.
--version: Displays the command version.

Delete or Remove files

rm /path/file.text

Delete empty directory or folder

rmdir /path/temp
OR
rm -d /path/temp

Delete directory with sub directories and files

rm -r /path/temp

Copy files and directories

cp source_file destination_file

Move or rename files and directories

mv old_file new_location

Concatenate and display or read file content

cat file.txt

Display output one screen at a time

more file.txt

Display output one screen at a time, backward and forward

less file.txt

Display the beginning of a file

head file.txt

Display the end of a file

tail file.txt

Edit file using Nano editor

nano file.txt

Edit file using vim editor

vim file.txt

Change file permissions

chmod 755 file.txt

Change file owner and group

chown user:group file.txt

Display disk usage

du -h

Display free disk space

df -h

Mount a filesystem

mount /dev/sdb1 /mnt

Unmount a filesystem

umount /mnt

Search for files in a directory hierarchy

find /path/to/search -name "*.txt"

Search for a pattern in files

grep "pattern" file.txt

Pattern scanning and processing language

awk '/pattern/ {print}' file.txt

Stream editor for filtering and transforming text

sed 's/old/new/g' file.txt

Create links between files

ln -s /path/to/file link_name

Archive files

tar -cvf archive.tar /path/to/files

Compress files

gzip file.txt

Decompress files

gunzip file.txt.gz

Package and compress files

zip archive.zip file1 file2

Extract files from a zip archive

unzip archive.zip

Remote file and directory synchronization

rsync -avz source/ destination/

Create links between files

ln -s /path/to/file link_name

Make a filesystem

mkfs.ext4 /dev/sdb1

Filesystem consistency check and repair

fsck /dev/sdb1

Adjust filesystem parameters

tune2fs -l /dev/sdb1

Change the label on an ext2/ext3/ext4 filesystem

e2label /dev/sdb1 new_label

List information about block devices

lsblk

Display UUID of filesystems

blkid

Partition table manipulator

fdisk /dev/sdb

Disk partitioning tool

parted /dev/sdb

Set up a Linux swap area

mkswap /dev/sdb1

Enable devices and files for paging and swapping

swapon /dev/sdb1

Disable devices and files for paging and swapping

swapoff /dev/sdb1

Secure copy files between hosts on a network

scp file.txt user@remote_host:/path/to/destination

Securely transfer files between computers

sftp user@remote_host

Download files from the internet

wget https://example.com/file.txt

Transfer data from or to a server

curl -O https://example.com/file.txt

List open files

lsof -u username

Identify processes using files or sockets

fuser -u /path/to/file

Synchronize cached writes to persistent storage

sync

Shrink or extend the size of a file to the specified size

truncate -s 1G file.txt

Display disk usage and limits

quota -u username

Edit user disk quotas

edquota -u username

Change file attributes on a Linux file system

chattr +i file.txt

Display file or file system status

stat file.txt

Call block device ioctls from the command line

blockdev --getsz /dev/sdb

Display XFS file system information

xfs_info /dev/sdb1

Change parameters of an XFS filesystem

xfs_admin -L new_label /dev/sdb1

Turn filesystem quotas on

quotaon /dev/sdb1

Turn filesystem quotas off

quotaoff /dev/sdb1

Set disk quotas

setquota -u username 100M 200M 0 0 /dev/sdb1

Summarize quotas for a filesystem

repquota /dev/sdb1

Discard blocks on a device

blkdiscard /dev/sdb1

Wipe filesystem, raid or partition table signature from a device

wipefs -a /dev/sdb

Inform the OS of partition table changes

partprobe /dev/sdb

Show the status of modules in the Linux Kernel

lsmod

Add or remove modules from the Linux Kernel

modprobe module_name

Remove modules from the Linux Kernel

rmmod module_name

Insert modules into the Linux Kernel

insmod module_name

List USB devices

lsusb

List block devices

lsblk

List file attributes on a Linux second extended file system

lsattr file.txt

Report on file fragmentation

filefrag file.txt

Get file access control lists

getfacl file.txt

Set file access control lists

setfacl -m u:user:rw file.txt

Display disk usage and limits

quota -u username

Edit user disk quotas

edquota -u username

Turn filesystem quotas on

quotaon /dev/sdb1

Turn filesystem quotas off

quotaoff /dev/sdb1

Set disk quotas

setquota -u username 100M 200M 0 0 /dev/sdb1

Summarize quotas for a filesystem

repquota /dev/sdb1

Discard blocks on a device

blkdiscard /dev/sdb1

Wipe filesystem, raid or partition table signature from a device

wipefs -a /dev/sdb

Inform the OS of partition table changes

partprobe /dev/sdb

Show the status of modules in the Linux Kernel

lsmod

Add modules from the Linux Kernel

modprobe module_name

Remove modules from the Linux Kernel

rmmod module_name

Insert modules into the Linux Kernel

insmod module_name

To check directory size

du -sh *
or
du -sh /*

To check partition size

df -Th
or
df -h

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *