Showing posts with label UNIX. Show all posts
Showing posts with label UNIX. Show all posts

Sunday, 12 November 2017

ls Command


  • The ls is the most widely used command in unix or linux.
  • The ls command is a command-line utility for listing the contents of a directory or directories given to it via standard input.


Tuesday, 10 October 2017

cat command

cat command is use to read the contents of files or displaying them, combining copies of  files and creating file .

See the use of cat command

  Command  Details
cat [options] [filenames] [-] [filenames]Syntax
cat file1cat command is use to read the contents of files
cat file1 > file2">" this is output redirection operator, cat file1 output is written to file2
cat >file1To Write the data into file 1
cat > file2To Write the data into file 2
cat file1 file2concatenate copies of the contents of the two files file1 and file2
cat file1 file2 >file3file1 and file2 data redirect to file3
cat >> file4">>" the append operator , append the data in file4




touch command

In Unix and Linux touch command use for creating empty file,updating access time and modification time.


  Command  Desc
syntax touch [option] file_name(s)
touch file1 file2 file3This command would create three new empty files.
touch -am file3access(-a) and modification(-m) times to the current time
touch -r file4 file5[-r] is use for reference , to use the times of fille4 for file5
touch -d '1 May 2005 10:22' file8To change the last access time of file8 to 10:22 a.m. May 1, 2005
touch -d '14 May' file9[-d] Partial date change Only the date need be provided.

Alias Command in Unix and Lunix

  • Alias is a shortcut to reference a command. 
  • It can be used to avoid typing long commands that are frequently used.
  • For common patterns it can reduce keystrokes and improve efficiency. 
One best example why we will use alias ?
A user want to delete a file with confirm delete option for that we type
rm -i file.txt
remove file.txt? y
But some time we forgot to write -i , to avoid this such issue we use alias.

CommandDesc
Syntax Of aliasalias [-p] [name="value"]
Example:
aliasIt will show you list of alish which is present in system
alias ls="ls -al"lists the names of the files and directories within the current directory
alias df="df -h"size, amount of space used, amount of space available (-h) in MB and GB
alias rm="rm -i"increasing the safety of the system by making commands interactive. It is use for remove files
alias cp="cp -i"increasing the safety of the system by making commands interactive .It is use for copy files
Removing Aliases
Syntaxunalias [-a] name(s)
Example:unalias rm

Unix and Linux Basic Commands



Below are details of Basic Commands


CommandDescription
datedate command is used to print or set the system date and time. Syntax: date options
calcal displays a simple calendar. If arguments are not specified, the current month is displayed. Syntax: cal options
clearclear the terminal screen
pwdpwd command is used to print name of working directory
unameprint system information. Generally used to know the flavor and version of the
operating system
whoshow who is logged on
uptimeTell how long the system has been running.
lsIf you simply execute ls on the command prompt, then it will display the files
and directories in the current directory.You can pass a directory as an argument
to ls command. In this case, the ls command prints all the files and directories in
the specific directory you have passed.Syntax: ls directory
touchThe touch command simply creates an empty file. The below touch command
creates a file_name.txt in the current directory.Syntax: touch file_name.txt
catThe cat command is used to display the contents in a file.
Syntax: cat file_name.txt
headThe head command can be used to print the specified number of lines from the
starting of a file. Syntax: head -3 file_name.txt
tailThe tail command can be used to print the specified number of lines from the end
of a file. Syntax: tail -3 file_name.txt
mkdirThe mkdir command is used to create the specified directory.
cdThe cd command can be used to change from one directory to another directory.
You need to specify the target directory where you want to go.
mvThe mv command is used to rename the files and it also used for moving the files
from one directory into another directory.
cpThe cp command is used to copy the content of source file into the target file.
If the target file already have data, then it will be overwritten.
rmdirremove or delete directories. Syntax: rmdir directory_name
wcwc command can be used to find the number of line, words and characters
in a file.
cutcut remove sections from each line of files. Syntax: cat new_file.txt|cut -c1
manIf you want to know more about all above command then go to man comman Syntaxman command_name.

Monday, 9 October 2017

File Attributes and Permissions

File Attributes

We can observe 7 attribute fields listed for each file. 




The attribute fields are
  1. File name
  2. Modification date
  3. Size
  4. Group:(associated group for the file)
  5. Owner
  6. Number of links(the number of other links associated with this file),
  7. Permission modes: the permissions assigned to the file for the owner, the group and all   others.
File Permissions
The permission field for each file consists of 10 characters as described by the diagram below







Unix File System

The Unix file system has a hierarchical (tree-like) structure with its highest level 
directory called root ( /).
Immediately below the root level directory are several sub-directories, most of which contain system files. 

The following figure shows a typical organization of files in Unix system.




bin - short for binaries, this is the directory where many commonly used 
          executable commands reside
dev - contains device specific files
etc - contains system configuration files
home - contains user directories and files
lib - contains all library files
mnt - contains device files related to mounted devices
proc - contains files related to system processes
root - the root users' home directory (note this is different than /)
sbin - system binary files reside here. If there is no sbin directory on your system, these files most likely reside in etc
tmp - storage for temporary files which are periodically removed from the filesystem
usr - also contains executable commands

Unix File Types 

All files in the Unix file system can be loosely categorized into 3 types, specifically:

  1. ordinary files
  2. directory files
  3. device files

Ordinary Files

Ordinary files hold data and executable programs. Executable programs are the commands
(ls) that you enter on the prompt. The data can be anything and there is no specific format
 enforced in the way the data is stored.
The regular files can be visualized as the leaves in the UNIX tree.

Directories

Directories are files that contain other files and sub-directories. Directories are used to
organize the data by keeping closely related files in the same place. The directories are 
just like the folders in windows operating system.

The kernel alone can write the directory file. When a file is added to or deleted from this directory, the kernel makes an entry. 
A directory file can be visualized as the branch of the UNIX tree.

Special Or Device Files

These files represent the physical devices. Files can also refer to computer hardware such as terminals and printers. These device files can also refer to tape and disk drives, CD-ROM players, modems, network interfaces, scanners, and any other piece of computer hardware. When a process writes to a special file, the data is sent to the physical device associated with it. Special files are not literally files, but are pointers that point to the device drivers located in the kernel. The protection applicable to files is also applicable to physical devices.



User Login Process

When the user is trying to logging into system then Kernel should know who is that user.

Kernel manage this user logging process by running below programs
  1. getty    
  2. loging 
       [getty is short for “get terminal”.]
  • Kernel calls program ‘init’. ‘init’ calls program ‘getty’, which issues a login prompt in the monitor.
  • User enters login and password.‘getty’ calls program ‘login’ which scans file /etc/passwd to match username and password. 
  • After validation, control passes to session startup program /bin/sh .User gets a shell prompt. 
  • If the user fails to provide valid password, the login program returns the control back to the getty program.












What is UNIX ?

UNIX is a operating system which is multi user (multiple user can access Unix system at a same
 time ) and  multitasking (One user can run multiple program). Operating System is an interface
 between hardware and applications software's.

Unix Architecture

1.Shell
  • Human interface point for Unix
  • Program layer – provides an environment for the user to enter commands to get desired results.
  • Korn Shell, Bourne Shell, C Shell are various shells used by Unix users
2. Kernel
  • Heart of The Unix OS.
  • Collection of C programs directly communicating with hardware
  • Part of Unix system loaded into memory when Unix is booted
        Manages:-
  • System resources
  • Allocates time between user and processes
  • Decides process priorities
3.  Hardware

 Unix Boot Process Setps
  1. BIOS    : Basic I/O System Executes MBR.
  2. MBR : Master Boot Record Executes GRUB.
  3. GRUB  : Grand Unified Boot loader executes Kernel.
  4. Kernel : Kernal executes  sbin/Init.
  5. Init          : Init executes run level programs .
  6. Runlevel : Runlevel program executes from /etc/rc .d/rc*.d/rc*.



Friday, 6 October 2017