head : used to view first 10 lines of a file
syntax : head <filename>
ex: head /etc/passwd
To view 4 lines of a file
head -n <no of lines> <filename>
ex: head -4 /etc/passwd
Tail : is used to view last ten lines of a file
syntax: tail <filename>
ex: tail /etc/passwd
To view last 10 lines of a file
tail -10 /etc/passwd
more : used to see the content pagewise but we cannot scroll up
syntax: more < file name>
ex: more /etc/passwd
less: used to see the content pagewise we can scroll up&down
syntax: less <filename>
ex: less /etc/passwd
date: used to view current date&time
to change date
date <mm-dd-hr-min-year>
ex: date 120111452013
it means 12th month 01 date 11:45 11 hours 45 minutes 2013 year
or
date -s <content>
date -s "wed june 20 20:46:51 IST 2013"
cal : cal is used to view present months calender
cal to view a particular month,particular years calender
cal <Month> <year>
cal 5 1986 -------------> to view may 1986 calender
cal 2050 ----------------> to view entire 2050 year calender
| --------> this symbol is called as pipe it is used to link conmmands
ex: ls | grep pot
grep : is used to skip something specially from the output
here in example from output of ls we are grepping pot
ll | grep "^d" ---------> here from the out put of ll we are greping only directories
mkdir <directory name> -----> to create a directory
ex: mkdir mahesh
To create multiple directories :
mkdir <dir1> <dir2> <dir3>
ex: mkdir d1 d2 d3
To create nested directory
mkdir -p <dir1/dir2/dir3>
mkdir -p world/asia/india/ap/vskp/mahesh
To change the directory
cd < path of directory>
To change directory one level back
cd ..
To change directory two levels back
cd ../..
Removing a file or directory
to remove a file
rm <filename>
to remove an empty directory
rmdir <dir-name>
To remove directory recursively & forcefully
rm -rf -> to delete directory with out asking yes or no
copying a file
cp <sorce> <destination> -----> to copy a file
ex: cp file1 /etc/
cp -rf <source > <destination> ---> to copy entire directory along with subdirectories & files
ex: cp -rf mahesh /opt/
cp -a <source> <destination> -----> to copy a file or directory along with permissions
ex: cp -a Server /var/ftp/pub
To move a file or directory
mv < source> <destination>
mv mahesh /opt/users/
To rename a file or directory
mv <oldname> <newname>
To create chain commands
In linux we can execute "n" number of commands at a single command line
syntax: command1;command2;command3;
ex: date;cal2013;date 120111452013;mkdir mahesh;cd mahesh;cd
No comments:
Post a Comment