0% found this document useful (0 votes)
26 views5 pages

File System Organization-2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views5 pages

File System Organization-2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

File System Organization

Unix File System Distribution

Types of Files
Types of Files in Linux:

In Linux everything is treated as File.

All files are divided into 3 types→

1) Normal or Ordinary files:These files contain data. It can be either text files (like abc.txt) OR binary
files (like images, videos etc).

For More Details and Other Course Call Us on 97072 50260


2) Directory Files:These files represent directories.In windows, we can use folder terminology where as
in linux we can use directory terminology. Directory can contains files and sub directories.

3) Device Files:In Linux, every device is represented as a file. By using this file we can communicate with
that device.Note: short-cut commands to open and close terminal

• ctrl+alt+t → To open terminal


• ctrl+d→To close Terminal

Creating Files
• Touch Command (Create empty files)-for creating normal or ordinary files.
Eg – touch sample1
➔ When creating multiple files – touch sample1 sample2 sample3
➔ When displaying a particular file –cat filename
➔ When listing (whether the file is present or not)- ls –l filename
• Cat > sample
Write the text here
And then press CTRL d
• Vi editor
Vi filename

Indulging in File Play and directory play


• Copy a file
cp file1 file2(This will copy the contents of file1 to file2 .If file2 does not exist it will be created
automatically).
• Copy multiple files in 1 file
cp file1 file2 file3
• Removing a file
rm –i filename (-i option removes files interactively i.e you are asked for confirmation before
deleting the files).
• Removing a directory
rm –r dir1 (This command recursively removes all the contents of dir1 and also dir1 itself).
rm –rf dir1 (-f option is for forcefully removal).
• Moving a file(Renaming a file )
mv test sample
• Making a directory
mkdir dir1
• Removing a directory
rmdir dir1
• Change directory

For More Details and Other Course Call Us on 97072 50260


cd dir1
cd /usr/local/bin
Changes to the directory /usr/local/bin.
From this directory, you can cd to the directory /usr/home/amrood
using the following relative path −
cd ../../home/amrood

Listing files and Directories


The ls command is used to list files or directories in Linux and other Unix-based operating systems.Just
like you navigate in your File explorer or Finder with a GUI, the ls command allows you to list all files or
directories in the current directory by default, and further interact with them via the command line.

• List files in current working directory→ls


• List files in another directory→ls dirname
• List files in root dir→ls
• list the contents in the users's home directory→ls ~
• List files recursively→Type the ls -R command to list all files and directories with their
corresponding subdirectories down to the last file.
• List files with their sizes→Type the ls -s command (the s is lowercase) to list files or directories
with their sizes.
• List files in long format→Type the ls -l command to list the contents of the directory in a table
format with columns including:
1. content permissions
2. number of links to the content
3. owner of the content
4. group owner of the content
5. size of the content in bytes
6. last modified date / time of the content
7. file or directory name
• list files including hidden files→ls –a
• list files and output the result to a file → ls > output.txt
• Display all files and directories in reverse of alphabetical order→ls -r
• ls|more→To display content line by line(To come out we have to use q)
• ls | pg→To display content page by page.Each page contains 20 lines of content.(To come out
we have to use q)
• ls –t→To display all files based on last modified date and time. Most recent is at top and old are
at bottom.
• ls –rt→To display all files based on reverse of last modified date and time. Old files are at top
and recent files are at bottom.
• ls –a→a means all.To display all files including hidden files. Here . and .. also will be displayed.
• ls –F→ To display all files by type.

For More Details and Other Course Call Us on 97072 50260


1. directory /
2. executable file *
3. link file @
4. Eg: initctl@ Link File
5. pts/ Directory
6. ls* Executable File
• ls –i→ To display all files including inode number.
• ls –h→display in human readable format.

File System Navigation Commands:


1) Every directory implicitly contains 2 directories . and ..

• . Represents Current Directory


• .. Represents Parent Directory

2) $ cd . →Changes to Current Directory (Useless)

3) $ cd .. →Changes to Parent Directory

4) $cd → If we are not passing any argument, then changes to user home directory.

5) $ cd ~ → ~ Means User Home Directory.It will Changes to User Home Directory.($HOME)

6) $ cd - →- Means Previous Working Directory.It will Changes to Previous Working Directory.

2. tac Command:

It is the reverse of cat.

It will display file content in reverse order of lines. i.e first line will become last line and last line will
become first line.This is vertical reversal.

durga@durga-VirtualBox:~$ cat abc.txt

CAT

RAT

MAT

durga@durga-VirtualBox:~$ tac abc.txt

MAT

RAT

CAT

For More Details and Other Course Call Us on 97072 50260


3. Rev Command:

rev means reverse.Here each line content will be reversed.It is horizontal reversal.

VirtualBox:~$ cat abc.txt

CAT

RAT

MAT

VirtualBox:~$ rev abc.txt

TAC

TAR

TAM

Note:

cat command will display total file content at a time. It is best suitable for small files. If the

file contains huge lines then it is not recommended to use cat command. We should go for

head, tail, less and more commands.

For More Details and Other Course Call Us on 97072 50260

You might also like