0% found this document useful (0 votes)
19 views

11 Lab Manual Working With Files and Directories

Uploaded by

harin9079
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)
19 views

11 Lab Manual Working With Files and Directories

Uploaded by

harin9079
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/ 9

WORKING WITH FILES & DIRECTORIES

In Linux/Unix operating system everything is considered a file. Even


directories are files, files are files, and devices like mice, keyboards, printers,
etc are also files. File management commands are used to manage the files.
In this lab manual, you will understand some file management commands.
Follow the below-given steps to execute these commands.
1. Connect to the kali Linux machine, created by you, using the RDP
protocol.
2. When prompted for the username and password, enter root as
username and toor as password. The root is the administrator user of
the machine.

3. click on the black box icon (Terminal Emulator) in the top left corner of the Kali
Linux Desktop.

1
Running the terminal while using the root account, allows you to run various
commands with administrator rights.

Let’s Understand some navigation file management one by one.


1. LS Command
The 'ls' command is used to list files and directories. The contents of your
current working directory, which is just a technical way of stating the
directory that your terminal is presently in, will be listed if you run the "ls"
command without any further options.
a) Sort by Last Edited File Using
ls -t

b) Hidden Files Using


ls -a

c) Display All information Using


ls -l

2
d) Display File Size In Human Readable Format using
ls -lh

2. CAT COMMAND
The cat command is a utility command in Linux. One of its most common
usages is to print the content of a file onto the standard output stream.
Other than that, the cat command also allows us to write some texts into a
file.
a) To view Single File
cat newfile.txt

b) To view Multiple File


Cat newfile.txt vi.txt

c) To view File with Line Numbers


Cat -n newfile.txt

3
d) Create a file
Cat createfile

e) Copy Content of one file to another


Cat newfile.txt > createfile
Cat createfile

3. TOUCH COMMAND
The touch command's primary function is to modify a timestamp.
Commonly, the utility is used for file creation, although this is not its primary
function. The terminal program can change the modification and access time
for any given file. The touch command creates a file only if the file doesn't
already exist.
a) To Create File only
touch createfile

b) To check file created or not


touch -c

4
c) To change file Modification time only
touch -m

d) 4. To update access and modification time


touch -c -d

4. MKDIR COMMAND
The mkdir command in Linux/Unix allows users to create or make new
directories. mkdir stands for “make directory.” With mkdir, you can also set
permissions, create multiple directories (folders) at once, and much more
a) To Create Single Directory
Mkdir directory name

5
b) To Create Multiple Directories
Mkdir -p directory name

5. RM COMMAND
Use the rm command to remove files you no longer need. The rm
command removes the entries for a specified file, group of files, or certain
select files from a list within a directory. User confirmation, read permission,
and write permission are not required before a file is removed when you use
the rm command.

a) To remove file
rm filename

6
b) To recursively delete a directory and all its contents
rm -r

6. CP COMMAND
You can use the cp command for copying files from one location to another.
This command can also copy directories (folders). [file/directory-sources]
specifies the sources of the files or directories you want to copy. And the
[destination] argument specifies the location you want to copy the file to.

cp [OPTION] Source Destination


cp [OPTION] Source Directory
cp [OPTION] Source-1 Source-2 Source-3 Source-n Directory 7
a) To recursively copy a directory and all its contents
cp-r

b) To copy all files and directories


cp * dir

7. MV COMMAND
Use the mv command to move files and directories from one directory to
another or to rename a file or directory.

a) To move one or more files or directories from one place to another in


a file system like UNIX.

8
mv c.txt d.txt

b) To force mv by overwriting destination file without prompt


mv –f c.txt d.txt

You might also like