290 likes | 628 Views
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
E N D
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 SymbolMeaning - Regular file d Directory l Link c Special file s Socket p Named pipe
File system layout / dev bin boot etc home lib mnt opt proc root sbin tmp usr var
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 .
The file system in reality 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 whom this file belongs, and where is it located on the hard disk. 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 Linux searches for required program in paths and as soon as a match is found, the search is stopped The which command 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 Filetype 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
creating directories mkdir mkdir -p : creating directories and subdirectories in one step [alaei@node65 ~]$ mkdir -p project/iut/1 [alaei@node65 ~]$ mkdir 1 2 5
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 filenames The 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 [alaei@node65 ~]$ find . size +5000k
The grep command The diff command
File Security Owner Group Others d r w x r w x r w x Execute File type Write .= file d= directory l= link 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 id command Print information for USERNAME, or the current user. The chmod command 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
$ chmod 754 test_file -rwxr-xr-x 1 eric users Owner = 4 + 2 + 1 = 7 Group = 4 + 1 = 5 World = 4 = 4 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)