The document provides an overview of file management and directory structures in UNIX/Linux systems, explaining how files are organized into directories in a tree-like structure. It covers commands for listing files, creating, editing, copying, renaming, and deleting files and directories, as well as the use of meta characters and hidden files. Additionally, it discusses navigating the filesystem, understanding pathnames, and managing directories effectively.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0 ratings0% found this document useful (0 votes)
38 views6 pages
Linux File Management and Directories
The document provides an overview of file management and directory structures in UNIX/Linux systems, explaining how files are organized into directories in a tree-like structure. It covers commands for listing files, creating, editing, copying, renaming, and deleting files and directories, as well as the use of meta characters and hidden files. Additionally, it discusses navigating the filesystem, understanding pathnames, and managing directories effectively.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
Linux File Management and Directories
A data in UNIX ws organized into ies. All files are organized into directories
These directories are organized into @ tree-lke structure i
filesystem,
the
ks to ther ete,
You lok at working with ordinary thes:
re both special and ordinary fles, For users
105, UNIK directors ae equ alent to folders.
les — Some special files provide access to hardware such 35 hard
(CD-ROM cnves, modems, and Ethernet adapters. Other spec
The command Is supports the I option which would help you to get more
Information about the listed files ~
+ Second Column: represents the number of memory blocks taken by the fe or
rectory
+ Third Cohim: represents owner of the file. This 6 the Unix user who created
this fe
+ Fourth Column: represents group ofthe owner. Every Uni user would have an
associated group,
+ Fith Column represents fle sze in bytes.
+ etn Column: represents date and tine when this Me was created or modified
laste,
‘+ Seventh Column: represents fle or directory name.
Im the Is -1 listing example, every file line began with a 4, -, or 1. These
characters indicate the type of file that's ised.nary executable, oF ard
lock speci fe, Block mpufoutt device We Such asa physica
Symbolic ink le, Links on any regular te,
. Socket used for iterprocess communcation
Meta Characters
Meta characters have special meaning in Unix. For example * and ? are
‘metacharacters. We use * to match 0 or more characters, a question
‘mark matches with single character.
For Example ~
1 files whose name start with ch and ends with .doc ~
ar-a.coc epere.dee enr.coe — en0-2.000
Here * works as meta character which matches with any character. If you
want to display al the files ending with just .doc then you can use following
‘command ~
Hiden Fes
An invisible file is one whose first character isthe dot or period character (,).
UNIX uding the shell) use most of these files to store
configuration information
‘Some common examples of hidden files include the files ~
+ Double dt .. This represents parent decry,
(Creating Fes
‘You can use vieditor to create ordinary fles on any Unix system. You
simply need to give folowing command =
‘Above command would open a file with the given filename. You would need
to press ‘come Into edit mode. Once you are in edit mode you can
start writing your content inthe file as below ~
Ta going to save Git
Once you are done, do the following steps ~
rst thee.
+ Press key esc to come outof edt mode.1+ ress two keys Shift + 2z togetner to come out ofthe file completely
Now you would have file created with filename in the current
You can edit an existing file using vi editor. We would cover this in detail in
2 separate tutorial. But in short, you can open existing file as follows ~
S64 folenae
‘Once file is opened, you can come in edit mode by pressing key i and then
le as you like. If you want to move here and there inside a fle
ressing key esc and then
‘you can use following keys to move inside a fi
+ ey to move tothe right side
1+ key to move to the let ide
+ kchey to move up sie in the fe,
1+ Sey to move down side n the fe.
So using above keys you can position your cursor where ever you want to
edit. Once you are positioned then you can use I key to come in edit mode.
ait the file, once you are done press esc and finally two keys Shift +
ZZ together to come out of the file completely.
Depiay Content ofa Fle
You can use cat command to see the content of a fi
simple example to see the content of above created file
nis is unir file. created £8 for the first thee.
eon to save his Content in tus fide
5
‘You can display line numbers by using -b option along with eat command
as follows ~
Contig odin Fe
You can use the we command to get a count of the total number of lines,
‘words, and characters contained in a file. Following is the simple example to
see the information about above created file ~
Sue fetenane
Here isthe detail of all the four columns —
+ First Column: represents total numberof tines in the fe,
+ Second Column represents total number of words inthe fle.
‘+ Third Column: represents total number of bytes inthe file, This Is actual sie of
the file.
+ Fourth Column: represents fle name.
You can give multiple files at a time to get the information about those file.
Here is simple syntax ~
1 ve Llanes FLlenaned erased
Comings:
To make a copy of a file use the cp command. The basic syntax of the
‘command is —
5 ep source Fite sestination He
Following is the example to create a copy of existing file filename.Now you would find one more file copyfile in your current directory. This
file would be exactly same as original file filename.
eran Fes
To change the name of a file use the my command, Its basic syntax is —
the example which would rename existing
ame tonewfile:
Sev tenses neve
‘The mv command would move existing file completely into new file. So in
this case you would fine only newfie in your current directory.
Dakar Fe
To delete an existing fle use the rm command. Its basic syntax is ~
5 00 eiLeane
‘Caution: It may be dangerous to delete a file because it may contain useful
‘formation. So be careful while using this command. It is recommended t
Luse+i option along with rm command.
Following is the example which would completely remove existing
filefilename:
5 re filename
‘
You cen remove multiple files ata tle as follows —
Linux Directories
A directory is a file whose sole job is to store file names and related
information. All files, whether ordinary, special, or directory, are contained
In directories,
the slash character (/), and all other directories are contained below
Hoe Decry
The directory in which you find yourself when you first login is called your
home directory.
You will be doing much of your work In your home directory and
Subdirectories that you'll be creating to organize your fies,
‘You can go in your home directory anytime using the following command —
.se
;
Here ~ indicates home directory. If you want to go in any other user's
home directory then use the following command ~
‘To go in your last directory you can use following command —
fries are arranged in a hierarchy with root (/) at the top. The position
Within the hierarchy is described by its pathname,
Elements of a pathname are separated by a /. A pathname is absolute If it
's described in relation to root, so absolute pathnames always begin with a /.
‘These are some example of absolute filenames.
‘A pathname can also be relat
pathnames never begin
‘some pathnames might look
to your current working directory. Relative
to user amrood' home directory,
ine where you are within the filesystem hierarchy at any time,
enter the command pwd to print the current working directory ~
i
Jusera/none sao
‘
Using recs
(Gating Drees
Directories are created by the following command ~
Stir strane
Here, directory is the absolute or relative pathname of the directory you
want to create. For example, the command ~
‘axate myttr
This command creates the directory tes
‘The mkdircommand produces no output
requested directory.
If you give more than one directory on the command line, mkdir creates
each of the directories. For example ~
Smuate aoce pub
CCreates the directories docs and pub under the current directorycosting Pare Ores
Sometimes when you want to create a directory, its parent directory or
directories might not exist. In this case, mkdir issues an error message os
follows —
In such cases, you can specify the -p option to the mkdir command. It
the necessary directories for you. For exemple ~
1 /ap/aaoos
‘Above command creates all the required parent directories.
Directories can be deleted using the rmdir command as follows —
Note - To remove a directory make sure It Is empty which means there
should not be any file oF sub-directory Inside this directory.
‘You can remove multiple directories at a time 2s follows ~
sr
5
‘Above command removes the directories dirnamet, dimame2, and
dirname2 if they are empty. The rmdir command produces no output if itis
successful
Cargng Deere
You can use the ed command to do more than change to a home directory:
to change to any directory by specifying a vali absolute or
The syntax is as follows ~
Changes to the directory /usr/local/oin. From this directory you can cd to
the directory /usr/home/amrood using the following relative path ~
ea snone/areod
‘The rectors. (et and ot on)
“The filename . (dot) represents the current working directory; and the
filename .. (dot dot) represent the directory one level above the current
working directory, often referred to as the parent directo