Friday, 22 January 2016

File and File System



FILE:

The file is a container for storing information.

Unix treat all as file example directory, device, file

three types of files:

ordinary file --- storing information
directory file --- Its directory contains files and other directories, But strictly speacking it contains names and number associated with each name.

device file: all devices and peripherals are represented by files. To read or write device

File System



Change Directory: cd



The tilde (the wavy horizontal line character) is used to represent users' home directories on Unix-like operating systems.

cd ~

cd command in Linux/Unix
cd is a Linux command to change the directory/folder of the terminal's shell.
You can press the tab button in order to auto complete the directory name.
cd syntax
cd examples
cd syntax
$ cd [directory]
cd command examples
Change to home directory (determined by $HOME environment variable):
$ cd
Also change to home directory:
$ cd ~
Change to root directory:
$ cd /
Change to parent directory:
$ cd ..
Change to subdirectory Documents:
$ cd Documents
Change to subdirectory Documents/Books:
$ cd Documents/Books
Change to directory with absolute path /home/user/Desktop:
$ cd /home/user/Desktop
Change to directory name with white space - My Images:
$ cd My\ Images
Or
$ cd "My Images"
Or
$ cd 'My Images'


Present Working Directory: PWD

pwd - print working directory, is a Linux command to get the current working directory.
pwd syntax
pwd examples
pwd syntax
$ pwd [option]
pwd command examples
Change directory to /usr/src directory and print working directory:
$ cd /usr/src
$ pwd
/user/src
Change directory to home directory and print working directory:
$ cd ~
$ pwd
/home/user
Change directory to parent directory of the home directory and print working directory:
$ cd ~/..
$ pwd
/home
Change directory to root directory and print working directory:
$ cd /
$ pwd
/
Home Directory:

A home directory, also called a login directory, is the directory on Unix-like operating systems that serves as the repository for a user's personal files, directories and programs. It is also the directory that a user is first in after logging into the system.

There are several easy ways for a user to return to its home directory regardless of its current directory (i.e., the directory in which it is currently working in). The simplest of these is to use the cd (i.e., change directory) command without any options or arguments (i.e., input files), i.e., by merely typing the following and then pressing the ENTER key:

MKDIR: make directory

Syntax: mkdir foldername
  

mkdir sample

multiple Directories: mkdir a b c

Sub directories: mkdir -p a/b/c

-p Parental


Remove Directory: RMDIR


Syntax: rmdir foldername
  

rmdir sample

multiple Directories: rmdir a b c

remove only c folder rmdir a/b/c

Sub directories: rmdir -p a/b/c   (removes all directoires)

-p Parental


Listing Files:

ls command in Linux/Unix
ls is a Linux shell command that lists directory contents of files and directories.
ls syntax
ls options
ls examples
ls code generator
ls syntax
$ ls [options] [file|dir]
ls command options
ls command main options:
option description
ls -a list all files including hidden file starting with '.'
ls --color colored list [=always/never/auto]
ls -d list directories - with ' */'
ls -F add one char of */=>@| to enteries
ls -i list file's inode index number
ls -l list with long format - show permissions
ls -la list long format including hidden files
ls -lh list long format with readable file size
ls -ls list with long format with file size
ls -r list in reverse order
ls -R list recursively directory tree
ls -s list file size
ls -S sort by file size
ls -t sort by time & date
ls -X sort by extension name
ls command examples
You can press the tab button to auto complete the file or folder names.
List directory Documents/Books with relative path:
$ ls Documents/Books
List directory /home/user/Documents/Books with absolute path.
$ ls /home/user/Documents/Books
List root directory:
$ ls /
List parent directory:
$ ls ..
List user's home directory (e.g: /home/user):
$ ls ~
List with long format:
$ ls -l
Show hidden files:
$ ls -a
List with long format and show hidden files:
$ ls -la
Sort by date/time:
$ ls -t
Sort by file size:
$ ls -S
List all subdirectories:
$ ls *
Recursive directory tree list:
$ ls -R
List only text files with wildcard:
$ ls *.txt
ls redirection to output file:
$ ls > out.txt
List directories only:
$ ls -d */
List files and directories with full path:
$ ls -d $PWD/*

No comments:

Post a Comment