Вы находитесь на странице: 1из 19

File Management

 File system standard  Create/edit file


 Show current directory  Display file content
 Directory navigations  Removing file
 Creating directory  Copy/move file
 List directory's content  Static links
 Removing directory  Symbolic links
 Copy/move directory  Searching file

Version 1.0 linuxslides.blogspot.com


Showing file system standard

Version 1.0 linuxslides.blogspot.com


File system hierarchy standard

Version 1.0 linuxslides.blogspot.com


Show current directory

To see your current directory position:

$ pwd
or

$ pwd .

The dot “.” is a symbol of current directory position.

Version 1.0 linuxslides.blogspot.com


List directory's content
To see or list current directory's content:
$ ls
To display more complete information, use option “-l” :
$ ls -l
To see the size of files, use option “-sh”
$ ls -sh

To see other directory's content:


$ ls -l /etc
To see complete options for ls command:
$ man ls
To display full information, use option “-lisa” :
$ ls -lisa
Version 1.0 linuxslides.blogspot.com
Understanding List Informations
$ ls -lisa
210 2 d rwxr-xr-x 2 john enginner 4096 2009-09-24 11:50 secret_project/

file/direktory name
last modified
size in bytes
group
user
number of link
permissions
type (file/direktori)
size in blocks
inode

Version 1.0 linuxslides.blogspot.com


Directory Navigations
To move up one level:
$ cd ..
If a dot “.” means current directory, then double dots “..”
mean directory above.

Navigating into directory below:


$ cd <directory-name>
Navigating back into home directory:
$ cd
or
$ cd ~

Version 1.0 linuxslides.blogspot.com


Absolute and relative path
Navigate into home directory, then check current
position and see the contents:
$ cd
$ pwd
$ ls
Notice there's a directory named “Documents”. There
are two ways to enter the directory:
First, using an absolute path (from root “/”):
$ cd /home/linux/Documents
Second, using a relative path (from current position):
$ cd Documents
IMPORTANT: We can use the auto complete feature for
auto completing the file/directory name, by pressing TAB
Version 1.0 linuxslides.blogspot.com
Creating directory
Creating a directory “lab1”:

$ mkdir lab1
Creating two directory at the same time:

$ mkdir lab2 lab3

Creating directory “lab2a” under directory “lab2”:


$ mkdir lab2/lab2a

QUIZ: Create directory a3 under a1


directory a2, which is directory
a2 under directory a1 (only with a2
single command) a3
Version 1.0 linuxslides.blogspot.com
Create hidden directory
Creating hidden directory by adding “.”:

$ mkdir .secret_docs
To look at hidden directories add option “-a” after ls command:

$ ls -a

Version 1.0 linuxslides.blogspot.com


Removing directory
To remove an empty directory:

$ rmdir lab1

To remove a non empty directory:

$ rm -rf lab2

WARNING: Be Careful with command above, because it


could remove all files without confirmation. And never
used “rm -rf /” command by accident because it could
erase entire file system.

Version 1.0 linuxslides.blogspot.com


Copy/move directory

Copy directory lab3 to lab4:


$ cp -a lab3 lab4

QUIZ: Copy directory lab4 to directory test4 under /tmp

Move directory /tmp/test4 to the current directory:


$ mv /tmp/test4 .

Version 1.0 linuxslides.blogspot.com


Create/edit file
To create/edit a file use text editor below:
$ gedit myfile.txt
or
$ pico myfile.txt
or
$ vi myfile.txt
Inside vi you are in command mode, to enable editing you
have to change to edit mode, by pressing “i” or Insert
button.
Get used with vi, because it's a standard text editor in
Linux/Unix, and almost all of system/networking setting are
done with vi.
Version 1.0 linuxslides.blogspot.com
Creating file also can be done with redirection:
$ echo “Hallo, pa kabar?” > myfile2.txt

Creating an empty file:


$ touch myfile3.txt

Displaying content of file:


$ cat myfile3.txt
Removing a file:
$ rm myfile3.txt

Copy/move file:
$ cp myfile2.txt myfile2-backup.txt
$ mv myfile2-backup.txt ~/Documents

Version 1.0 linuxslides.blogspot.com


Static link
Static link is a file which is linked with another file, so
both of them connected reciprocally. If there's a
modifications in any of those file, other will also change
automatically.
But if any of those file was removed, the other file still
existed.
Format:
ln <original-file> <link-file>
$ echo “Hallo world” > original.txt
$ ln original.txt original-static.txt
$ ls -li
Take a look at inodes and sizes of both files. Try to
edit/remove one of them, and check if the change
affected the other file.
Version 1.0 linuxslides.blogspot.com
Symbolic link
Symbolic link is the same with static link, the only
difference is that the link file acts as a shortcut for the
original file. And if the original file was removed, then the
link file become useless.
Format:
ln -s <original-file> <link-file>

$ echo “Hallo world again” > original2.txt


$ ln -s original2.txt original2-symbolic.txt
$ ls -li

Take a look at inodes and sizes of both files. Try to


edit/remove one of them, and check if the change
affected the other file.
Version 1.0 linuxslides.blogspot.com
Lab: Symbolic link in directory

Create several directories like below:


$ cd ~
$ mkdir a1 a1/a2 a1/a2/a3
Create a symbolic link “a” from a1/a2/a3 directory:
$ ln -s a1/a2/a3/ a
$ ls -l
Now create a file under “a” :
$ touch a/testing
Take a look at a1/a2/a3 :
$ ls -l a1/a2/a3
Conclusions?
Version 1.0 linuxslides.blogspot.com
Find system's files

To find system's files (linux) named “ls” :


$ whereis ls

To find system's files (linux) contained “ls” :


$ locate ls

Sometimes you have to update the locate's database:


$ updatedb

But command above can't find user files, e.g:


$ whereis original2.txt

Version 1.0 linuxslides.blogspot.com


Find user's files
To find files named ori* :
$ find / -name “ori*”
Searching can be narrowed with specifying the file type
and the directory:
$ find /home -type f -name “ori*”
You can search all files with 3MB size and more:
$ find / -size +3000k

Even you can add “ls -sh” to know the exact file size:
$ find / -size +3000k -exec ls -sh {} \;

For further information, take a look at find manual:


$ man find
Version 1.0 linuxslides.blogspot.com

Вам также может понравиться