df command reports free disk space for each file system separately
df -h: Reporting large units like MB/GB.
df -h / /usr : Reports on / and /usr file systems
du: Disk usage in a directory(not entire file system)
du -s: summary of disk usage
du -s /home/*
It will return space consumed by each user
uname: What's my Unix system name, OS,CPU? [anandy@traninteractive-1101]~% uname -a
Linux traninteractive-1101.vdc.amazon.com 2.6.18-128.1.14.el5a02xen #1 SMP Thu Jun 25 08:09:23 UTC 2009 i686 athlon i386 GNU/Linux
finger : Account info of logged in users Difference b/w echo ** and echo * * [anandy@traninteractive-1101]~% echo **
afiedt.buf db dbtool dbtool.tar drop.xsl ed.hup lat1.sql lat.sql myqueue.sql mytool new_dbtool out progname.pl remedy remote-command Shipping Sqllogin.sh sqlnet.log
[anandy@traninteractive-1101]~% echo * *
afiedt.buf db dbtool dbtool.tar drop.xsl ed.hup lat1.sql lat.sql myqueue.sql mytool new_dbtool out progname.pl remedy remote-command Shipping Sqllogin.sh sqlnet.log afiedt.buf db dbtool dbtool.tar drop.xsl ed.hup lat1.sql lat.sql myqueue.sql mytool new_dbtool out progname.pl remedy remote-command Shipping Sqllogin.sh sqlnet.log
Create group and user: Group: sudo groupadd -g 241 amazon User: sudo useradd -u 211 -g amazon -c "amazon group" -d /home/anand -s /bin/ksh -m anand
cd /home/anand sudo mkdir perl chown -hR anand:amazon perl Inode:
how to find out inode of a file?
ls -1
How to find out hard links of a file?
ls -i
Example:
Anand> ls -li
Hard Links:
How to create hard link:
ln original_file Linked_file
ln Anand.txt linkedAnand.txt
ln Anand.txt ../Anand.txt
If two files have same inode, it means those file are same but different link created for that file.If you make changes to one file , it will automatically reflect to another file.
Copy of same file will have different inode number.
Benefits of hard links:
Re-usability,maintainability,security
Limitations of Hard link:
1. You can't have two linked file names in two different systems. Example one in /usr and another in /home.
2. You can't link a directory even within the same file system.
Symbolic links:(Soft links):Symbolic links can be created across the file systems. Symbolic link will have different inode number.
How to create symbolic link: ln -s File1 sm_Files
Symbolic link can be identified by character l in the permissions field. It's length is characters of actual file.
Permissions of a directory:
read(r): if you don't have read permissions, you cannot ls a directory.
Write(w): If you don't have write permissions to a directory, you cannot create or remove files from a directory.
Execute (x): If you don't have exe permissions of a dir. you cannot cd inside it or cat inside directories.It is kind of search permissions.
* To create or remove a file inside a dir. you should have write and execute both permissions.
Modifications and access time:Time of last modification: ls -l
Time of last access: ls -lu
Time of last inode modification: ls -lc
Touch:touch emp.lst: creates new file if it does not exists.
find: command to find files satisfying specified criteria.
It recursively examines a directory tree to look for files matching criteria and take some action on the selected files.
Syntax: find path_list selection_criteria action
Example seach name saratrag in all files come under home directory.
[anandy@traninteractive-1101]/home% pwd
/home
[anandy@traninteractive-1101]/home% find ./-name saratrag -print
Note*: all file operators start with - and path_list can never contain one.
Find selection criteria:find command to return files above 1 MB.
find /home -size +2048 -print
find command to return files above 1 MB and below 4 MB
find /home -size +2048 size -8192 -print
Q.Search all files with extension .c starting from current dir.
Ans: find . -name "*.c" print
Q. Search all files starting with upper letter.
Ans: find . -name '[A-Z]*' -print
Q. Find out all hard links for a file?
Ans: find / -inum 23323 -print
Explanation: -inum is a option to search all files having same inode number.
Q.Search file by type or permissions?
Ans:
type:
cd ; find . -type d -print 2>/dev/null
Explanation: -type option followed by letter -f(file), -d(dir.) or l(sim link)
If you do not have directory permissions you will get errors , you can redirect standard errors to /dev/null dir.
Permissions:
find $HOME -perm 777 -type d -print
Q. Find out all directories having all permissons to everyone?
cd; find . -perm 777 -type d -print
Find more options:
-user uname: if owned by uname
-group gname: if owned by group
-size +x[c]
-mtime -x: if modified after x time
-atime x: if accessed after x time
Find command actions:
-print :print selected file on standard output
-ls: list files
-exec cmd: Executes unix command cmd followed by {} \;
Q. List all files modified b/w 2 to 5 days?
Ans: find $HOME -type f -mtime +2 -mtime -5 -ls
Q. why you use {} \; in -exec action of find command?
Ans:{} is a place holder of file names. \; is for reuse previous find command.
Q. Remove all files not accessed from last one year.
Ans: find ./ -type f -atime +365 -exec rm {} \;
Note : -ok action will be used in place of -exec if you want to take action interactively.
Filters in Unix:
Head:display from the top of file(default 10 lines from top if no value given)
head -n 3 emp.lst
It will display top 3 lines from a file.
Tail:It will display end of the file.(default 10 lines from top if no value given)
tail -n 3 emp.lst: display last 3 lines
tail +11 emp.lst: Display 11th line onwards
To check logs or file growth:
-f option:
tail -2000f abc.log: display last 2000 lines from the file
cut: Cut columns from a fileAssume file is :Deployment.lst
Deployment to CarrierRoutingService/US/ABE2/Prod succeeded.
Deployment to CarrierRoutingService/US/ABE3/Prod succeeded.
Deployment to CarrierRoutingService/US/AVP1/Prod succeeded.
Deployment to CarrierRoutingService/US/BOS1/Prod succeeded.
Deployment to CarrierRoutingService/US/BWI1/Prod succeeded.
Deployment to CarrierRoutingService/US/CVG1/Prod succeeded.
Deployment to CarrierRoutingService/US/CVG2/Prod succeeded.
Deployment to CarrierRoutingService/US/DFW1/Prod succeeded.
Deployment to CarrierRoutingService/US/IND1/Prod succeeded.
Deployment to CarrierRoutingService/US/IND2/Prod succeeded.
Deployment to CarrierRoutingService/US/IND3/Prod succeeded.
Deployment to CarrierRoutingService/US/LAS2/Prod succeeded.
Deployment to CarrierRoutingService/US/LEX1/Prod succeeded.
Deployment to CarrierRoutingService/US/LEX2/Prod succeeded.
Deployment to CarrierRoutingService/US/PHL1/Prod succeeded.
Deployment to CarrierRoutingService/US/PHL3/Prod succeeded.
Deployment to CarrierRoutingService/US/PHL4/Prod succeeded.
Deployment to CarrierRoutingService/US/PHL5/Prod succeeded.
Deployment to CarrierRoutingService/US/PHL6/Prod succeeded.
Deployment to CarrierRoutingService/US/PHX3/Prod succeeded.
Deployment to CarrierRoutingService/US/PHX5/Prod succeeded.
Deployment to CarrierRoutingService/US/PHX6/Prod succeeded.
Deployment to CarrierRoutingService/US/RNO1/Prod succeeded.
Deployment to CarrierRoutingService/US/SDF1/Prod succeeded.
Deployment to CarrierRoutingService/US/SDF2/Prod succeeded.
Deployment to CarrierRoutingService/US/SEA6/Prod succeeded.
Deployment to CarrierRoutingService/US/TFC1/Prod succeeded.
Deployment to CarrierRoutingService/US/TUL1/Prod succeeded.
Cutting columns:-c optionNow get only environment name from this file:
cut -c 15-48 Deployment.lst
Get envirorment name and status:
cut -c 15-48,50-58 Deployment.lst
both together:It will display all after 15th character.
cut -c 15- Deployment.lst
cutting fileds:-f option.(Default delimiter is tab)
Here you have to use two options
-d for delimiter and -f for field list
Select all environments using cut fields:
cut -d" " -f 3 Deployment.lst
Q. Display only users names for this system.
Ans:who |cut -d " " -f1
tee:It saves the output to a file as well display it on terminal.
cut -d" " -f 3 Deployment.lst | tee envlist
paste:It is just opposite to cut .(Default delimiter is tab)
Example:
paste Deployment.lst envlist
It display both files side by side.
Use delimiter while pasting:
paste -d "|" Deployment.lst envlist
cut -d " " -f4 Deployment.lst | paste -d " " envlist -It will add 4th field from Deployment.lst file to the end of envlist file.
cut -d " " -f4 Deployment.lst | paste -d " " - envlist
It will add 4th field from Deployment.lst file to the starting of envlist file.
Joining lines using paste command:(-s) option
We can join multiple lines using paste command.
paste -s -d "||\n" envlist
It will join three consecutive lines in a single line.
No comments:
Post a Comment