UBUNTU FILE SYSTEM

Table of Content

  1. Navigating the Linux File System
  2. How to modify the permissions of a file or directory
  3. How to check filetype and permissions of a file and how to update them ?
  4. Ubuntu Powerful File System Commands
  5. Conclusion

Navigating the Linux File System?

Have you ever wondered why “.” files are not included in ls command ? The reason is they are mostly configuration files which are very less likely accessed or are not accessed frequently.

Understanding the file permissions

Let us understand the permissions of a file/directory as shown below and understand its all attributes.

drwxr-xr-x   2     sam sam 4096 2015-05-16 17:07 Documents
  1. d is a filetype where d is the directory however it can also have - which represents a file or c that represents character device and finally b represents block device
  2. rwxr-xr-x are the permissions of user, group and others respectively where r is read, w is write and x is execute permission. User has rwx permissions, group has r-x permissions and others have r-x permissions.
  3. l is the number of links that a file contains.
  4. sam is the owner of the file that is documents is owned by the user sam. Group contains multiple users and sam user is part of the sam group which is his primary group.
  5. 4096 is the size of the file.
  6. 2015-05-16 17:07 displays when was file last accessed.
  7. Documents is the file name
  • r represents read permission and it has 4 octal value.
  • w represents write permission and it has 2 octal value.
  • x represents execute permission and it has 1 octal value.
  • u represents user, g represents group , o represents others and a represents all( user, group and others)

How to modify permissions of a file or directory ?

Chmod: To change the permissions on file use the chmod command. Lets learn how to work with chmod command.

  • chmod a-w file.txt – Subtracting the write permission from all user, group and others.
  • chmod u+rwx file.txt – Adding the read, write and execute permission for user.
  • chmod g-r file.txt – Subtracting the read permission from group
  • chmod 666 file.txt – Granting the read and write access to all user, group and others
  • chmod 714 file.txt
    • Granting the read, write and execute permissions to user.
    • Granting the execute permission to group.
    • Granting the read and write access to others.

umask : Umask command works like a filter which masks your permissions.

  • 0 represents that it has all the permissions ie. read, write and execute
  • 7 represents no permissions that means it masks all the actual values.
  • UMASK 037 will create a file with -rwxr—– permissions
  • UMASK 000 will create a file with -rwxrwxrwx permissions
  • UMASK 222 will create a file with -r-x-r-x-r-x

How to check filetype and permissions of a file and how to update them?

Everything in Linux or ubuntu is a file . Files should have proper permissions and access.

  • To check the filetype of a file use the file command.
file name_of_the_file
  • To check the permissions of the file use the getfacl command.
 getfacl name_of_the_file

  • To set the permissions of the file use the setfacl command.

Here we are setting rwx permission for user sam on name_of_the_file

setfacl -m u:sam:rwx name_of_the_file

Ubuntu Powerful File System Commands

SNOCommandsDescriptionExample
1findThis command searches files and directories according to conditions. Here Find all .mp3 files with more than 
10MB and delete them using one single command
find / -type f -name *.mp3 -size +10M -exec rm{} \;
2gzipIt compresses the file sizegzip file_name
3chattrIt helps in alter attributes of files but only with root user. For Ex: Make directory(+i) and sub files(-R) immutablechattr -R +i temp/
4chownChange the owner of a file or directorychown -R tomat:tomcat /opt
5mksfsIt makes file systems. mkfs.ext2 ~/tmp.img
6unzipunzip command extracts all files from specified ZIP achieves.unzip myfile.zip
7mountUse mount command to attach file systems to a directorymount /dev/sda1 media/usb
8ddIt converts and copies file. Here we are backing the MBR partitioned system, where size is 512b where “if” is input source and “of” is output filesudo dd if=/dev/sda bs=512 count=1 of=mbr.img
9fdiskStands for Format disk, You can create, view m resize , delete and change the partitions on a hard drive.fdisk /dev/sda
10sortSort command helps in sorting the lines of text files or arranging them. Here we are using sort and storing values in new file using -o option.sort -o output.txt file.txt
11swaponDevices on which swapping are paging are enabled.swapon /dev/sda1
12swapoffDevices on which swapping are paging are disabled.swapoff /dev/sda1
13tartar(Tape Archive) is also used to compress files which is known as tarballtar cjvf abc.tar.gz directory1
14uniqIt filters or removes repeated lines in a file. Her -c option specifies how many uniq lines were removed.uniq -c file.txt

Conclusion

This concludes Ubuntu File System. In this Tutorial you learnt everything in Linux or Unix is a file. You always need a File System to work with various file and to work with these files there are some powerful utilities and command which work together.

Finally, I would like to suggest to assign or grant proper permissions as discussed above to your files or directories, in case you give incorrect permissions that can corrupt your file system or cause security breaches.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s