Date post: | 04-Jan-2016 |
Category: |
Documents |
Upload: | clyde-short |
View: | 217 times |
Download: | 0 times |
Linux file system
"On a UNIX system, everything is a file; if something is not a file, it is a process."
Sorts of files (on a Linux system)
Directories: files that are lists of other files. Special files: the mechanism used for input and output. Most special files are in /dev.
Links
Sockets and Named pipes: files are used to pass information between applications amongst other applications
The -l option to ls displays the file type
File types in a long list Symbol Meaning - Regular file d Directory l Link c Special file s Socket p Named pipe
File system layout
/
bin etcdevboot procmnt usrlibhome sbinrootopt vartmp
each subdirectory of root have special roles(By tradition):
/bin: executable commands
/sbin: sys adm commands
/etc: system configuration files
/lib shared libraries
/dev peripheral devices
/tmp temporary files
/mnt to mount external devices
/var Storage for all variable files and temporary files
created by users, such as log files
/proc system information
/usr/bin further exe files
/usr/sbin further system-important exe files
/usr/lib further libraries
User-installed programs typically go under the /usr/local hierarchy
The df command
[alaei@node65 ~]$ df -h
Using the df command with a dot (.) as an option shows the partition the current directory belongs to,
[alaei@node65 ~]$ df -h .
In a file system, a file is represented by an inode, a kind of serial number containing information about the actual data that makes up the file: to whomthis file belongs, and where is it located on the hard disk.
The file system in reality
use ls -i to disply indoe numbers
Orientation in the file system
The PATH environment variable lists those directories in the system where executable files can be found
[alaei@node65 ~]$ echo $PATH
The which command
Linux searches for required program in paths and as soon as a match is found, the search is stopped
The export command
The env command
Absolute and relative paths
A path, which is the way you need to follow in the tree structure to reach a given file, can be described as starting from the trunk of the tree (the / or root directory). In that case, the path starts with a slash and is called an absolute path
In the other case, the path doesn't start with a slash and confusion is possible between ~/bin/wc (in the user's home directory) and bin/wc in /usr. Paths that don't start with a slash are always relative. In relative paths we also use the . and .. indications for the current and the parent directory
~ means usr home directory
Manipulating files
more about ls
ls -l
ls -ltr
In most UNIX commands, options can be combined
Color ls default color scheme Color File type blue directories red compressed archives white text files pink images cyan links yellow devices green executables flashing red broken links
Crating and deleting files and directories
nautilus: The default file manager in Gnome, the GNU desktop.
konqueror: The file manager typically used on a KDE desktop.
mc: Midnight Commander, the Unix file manager
mkdir
mkdir -p : creating directories and subdirectories in one step
creating directories
[alaei@node65 ~]$ mkdir 1 2 5
[alaei@node65 ~]$ mkdir -p project/iut/1
Copying files with cp
-i, interactively prompt before overwriting files
-R, -r, --recursive copy directories recursively
Moving Files with mv mv can rename files or directories, or move them to different directories-f, force overwrite, even if target already
exists
-i, ask user interactively before overwriting files
Deleting Files with rm
-f, delete write-protected files without prompting-i, interactive ask the user before deleting files-r, recursively delete files and directories
There is no recycle bin in shell so s file is really gone when you use rm
Finding Files with locate The locate command is a simple and fast way to find files
The locate command searches a database of filenamesThe database needs to be updated regularly Usually this is done automatically with cron But locate will not find files created since the last update Options:-i option makes the search case-insensitive -r treats the pattern as a regular expression, rather than a simple string
Finding Files More Flexibly: find
find <path> name <searchstring>
[alaei@node65 ~]$ find . -name test
find . size +5000k[alaei@node65 ~]$
The grep command
The diff command
File Security
Owner
r w x
Group
r w x
Others
r w xd
.= filed= directoryl= link
File typeExecute
Write
Read
Each type of permission is assigned a access mode code:
read = 4 or r
write = 2 or w
execute = 1 or x
User group codes
user = u
group= g
others= o
The chmod command
The id command
Print information for USERNAME, or the current user.
Operation
+ add
- remove
= set exactly
Before: -rwxr-xr-x archive.sh
Command: chmod o=r archive.sh
After: -rwxr-xr-- archive.sh
Before: -rw-r----- topsecret.inf
Command: chmod g= topsecret.inf
After: -rw------- topsecret.inf
Before: -rw-r--r-- publicity.html
Command: chmod og=rw publicity.html
After: -rw-rw-rw- publicity.html
$ ls -l test_file
-rw-r--r-- 1 eric users
$ chmod o-r test_file
$ ls -l test_file
-rw-r----- 1 eric users
$ chmod g+wx test_file
$ ls -l test_file
-rw-rwx--- 1 eric users
$ chmod u=rw,g=r,o=r test_file
-rw-r--r-- 1 eric users
For changing file permissions in directory trees use -R .
$ chmod -R g-w test_dir
The permission numbers are determined by adding the values of the allowed permissions:
7 = read + write + execute
6 = read + write (but not execute)
5 = read + execute (but not write)
3 = write + execute (but not read)
4 = read (but not write and execute)
2 = write (but not read or execute)
1 = execute (but not read or write)
$ chmod 754 test_file
-rwxr-xr-x 1 eric users
Owner = 4 + 2 + 1 = 7
Group = 4 + 1 = 5
World = 4 = 4
The newgrp , chown and chgrp commands