You are on page 1of 33

Lab4

Finding Things ,
Directory & File
compression

T / Ebtisam ALselwi 1
Finding Things

Function
Command

which Shows the full path of shell commands found in your


path. For example, if
you want to know exactly where the “grep” command
is located on the
filesystem, you can type “which grep”. The output
should be something
like: /bin/grep
whereis Locates the program, source code, and manual page
for a command (if all
information is available). For example, to find out
where “ls” and its man
page are, type: “whereis ls” The output will look
something like:
ls: /bin/ls /usr/share/man/man1/ls.1.gz

T / Ebtisam ALselwi 2
Finding Things(con…)

Function
Command

locate A quick way to search for files anywhere on the


filesystem. For example, you
can find all files and directories that contain the name
“mozilla” by typing:
locate mozilla
find A very powerful command, but sometimes tricky to
use. It can be used to
search for files matching certain patterns, as well as
many other types of
searches. A simple example is:
find . -name \*mp3
This example starts searching in the current directory
“.” and all subdirectories,
looking for files with “mp3” at the end of their names

T / Ebtisam ALselwi 3
Commands type
- Bulit in Shell

- External ( (in other folder in system ))

T / Ebtisam ALselwi 4
which Command std@ubuntu:~$ type –a ls
/bin/ls

std@ubuntu:~$ which ls std@ubuntu:~$ type –a fdisk


/sbin/fdisk

/bin/ls

std@ubuntu:~$ which fdisk

/sbin/fdisk

T / Ebtisam ALselwi 5
which Command std@ubuntu:~$ type –a cd
cd is a shell builtin

std@ubuntu:~$ which cd std@ubuntu:~$ type –a history


history is a shell builtin

std@ubuntu:~$

std@ubuntu:~$ which history

std@ubuntu:~$

T / Ebtisam ALselwi 6
whereis Command

std@ubuntu:~$ whereis ls

ls: /bin/ls /usr/share/man/man1/ls.1.gz

Where :

ls : source
/bin/ls : path
/usr/share/man/man1/ls.1.gz : manual page

T / Ebtisam ALselwi 7
whereis Command(con…)

std@ubuntu:~$ whereis -m ls

ls: /usr/share/man/man1/ls.1.gz

Where :

/usr/share/man/man1/ls.1.gz manual page

T / Ebtisam ALselwi 8
whereis Command(con…)

std@ubuntu:~$ whereis -b ls

ls: /bin/ls

Where :

/bin/ls path

T / Ebtisam ALselwi 9
whereis Command(con…)

std@ubuntu:~$ whereis -s ls

ls:

Where :

ls: source

T / Ebtisam ALselwi 10
Locate Command(con…)
A quick way to
search for files
std@ubuntu:~$ locate test anywhere on
the filesystem

/usr/share/cups/templates/de/test-page.tmpl
/usr/share/cups/templates/es/test-page.tmpl
/usr/share/cups/templates/fr/test-page.tmpl
/usr/share/cups/templates/it/test-page.tmpl
/usr/share/cups/templates/ja/test-page.tmpl
/usr/share/cups/templates/pt_BR/test-page.tmpl
/usr/share/cups/templates/ru/test-page.tmpl
.
.
.
.

T / Ebtisam ALselwi 11
find Command
A quick way to
search for files
std@ubuntu:~$ find test anywhere
( the Files that
follow the
user)

test
test/2
test/1

T / Ebtisam ALselwi 12
find Command(con…)

std@ubuntu:~$ find *.txt *.docx *.xlsx

sample.txt
1.docx
2.xlsx

T / Ebtisam ALselwi 13
Directory & File compression

T / Ebtisam ALselwi 14
Directory compression

Command Function

tar It is used to archive and display the contents of the archive and to
decrypt the archive. So that they are Files and folders are
archived under the extension .tar.
Options :
cvf:
-c: Create archive
-v :display progress while creating archive
-f: Archive File name

T / Ebtisam ALselwi 15
Options

Directory compression Directory Extract

tar -cvf tar -xvf


tar -zcvf tar - zxvf
tar - czvf tar -xzvf
tar -cjvf tar -xjvf

T / Ebtisam ALselwi 16
Directory compression:
compression

std@ubuntu:~$ tar -cvf Ebtisam.tar Ebtisam

Ebtisam/

T / Ebtisam ALselwi 17
Directory compression:
compression

std@ubuntu:~$ tar -cvf Ebtisam1.tar Ebtisam1

Ebtisam/
Ebtisam/file2.txt
Ebtisam/sample1.txt
Ebtisam/test.txt
Ebtisam/sample.txt
Ebtisam/file1.txt
Ebtisam/sample2.txt
std@ubuntu:~$

T / Ebtisam ALselwi 18
T / Ebtisam ALselwi 19
Directory compression: compression

std@ubuntu:~/test$ tar -cvf test1.tar test1


test1/
test1/sample1.txt

T / Ebtisam ALselwi 21
Directory compression: compression

std@ubuntu:~$ tar -zcvf Ebtisam.tar Ebtisam1

Ebtisam/
Ebtisam/file2.txt tar -zcvf archive-name.tar.gz directory-name
Ebtisam/sample1.txt option:
Ebtisam/test.txt -z : Compress archive using gzip program
Ebtisam/sample.txt -c: Create archive
Ebtisam/file1.txt -v: Verbose i.e display progress while creating
Ebtisam/sample2.txt archive
std@ubuntu:~$ -f: Archive File name

T / Ebtisam ALselwi 22
Directory compression: compression

std@ubuntu:~$ tar -czvf Ebtisam1.tar Ebtisam


Using gzip
Ebtisam/
Ebtisam/file2.txt
Ebtisam/sample1.txt
Ebtisam/test.txt
Ebtisam/sample.txt
Ebtisam/file1.txt
Ebtisam/sample2.txt
std@ubuntu:~$

std@ubuntu:~$ tar -zcvf Ebtisam.tar.gz Ebtisam

Ebtisam/

T / Ebtisam ALselwi 23
Directory compression:

Using gzip

T / Ebtisam ALselwi 24
Directory compression: compression

std@ubuntu:~$ tar -cjvf Ebtisam2.tar Ebtisam


Using bzip2

Ebtisam/
Ebtisam/file2.txt
Ebtisam/sample1.txt
Ebtisam/test.txt
Ebtisam/sample.txt
Ebtisam/file1.txt
Ebtisam/sample2.txt
std@ubuntu:~$

T / Ebtisam ALselwi 25
Directory compression: Extract

std@ubuntu:~$ tar -xvf Ebtisam.tar


display the contents of the archive and to decrypt the
archive

Ebtisam/
Ebtisam/file2.txt
Ebtisam/sample1.txt
Ebtisam/test.txt
Ebtisam/sample.txt
Ebtisam/file1.txt
Ebtisam/sample2.txt

std@ubuntu:~$ tar -zxvf Ebtisam.tar.gz

Ebtisam/

T / Ebtisam ALselwi 26
Directory compression: Extract

std@ubuntu:~$ tar -xzvf Ebtisam.tar


display the contents of the archive and to decrypt the
archive

Ebtisam/
Ebtisam/file2.txt
Ebtisam/sample1.txt
Ebtisam/test.txt
Ebtisam/sample.txt
Ebtisam/file1.txt
Ebtisam/sample2.txt

std@ubuntu:~$ tar -zxvf Ebtisam.tar.gz

Ebtisam/

T / Ebtisam ALselwi 27
Directory compression: Extract

std@ubuntu:~$ tar -zxvf Ebtisam.tar


display the contents of the archive and to decrypt the
archive

Ebtisam/
Ebtisam/file2.txt
Ebtisam/sample1.txt
Ebtisam/test.txt
Ebtisam/sample.txt
Ebtisam/file1.txt
Ebtisam/sample2.txt

T / Ebtisam ALselwi 28
Directory compression: Add file to Archive

std@ubuntu:~$ tar -rvf Ebtisam.tar file.txt

file.txt

std@ubuntu:~$ mkdir Ebtisam


std@ubuntu:~$ tar -cvf Ebtisam.tar Ebtisam
Ebtisam/
std@ubuntu:~$ tar -rvf Ebtisam.tar file.txt
file.txt

T / Ebtisam ALselwi 29
File compression:

Command Function

gzip zip a file

gunzip unzip a file

T / Ebtisam ALselwi 30
File compression:
std@ubuntu:~$ gzip file.txt

T / Ebtisam ALselwi 31
File compression:
std@ubuntu:~$ gunzip file.txt

T / Ebtisam ALselwi 32
File compression:
std@ubuntu:~$ gzip -l file.txt.gz
Display information of file
after zip file

compressed uncompressed ratio uncompressed_name


51 22 -9.1% file.txt

T / Ebtisam ALselwi 33
End ….
T / Ebtisam ALselwi 34

You might also like