Hi fellas,Today we will talk about basic command ..whoever want to learn Linux he/she must be master with basic or daily route en commands.I seen many peoples who do symlink or bypass passwd file etc.. but they do not even know how to set a permisson on file or how to rename a file in linux..well.. i will discuss few command which is usefull for begginers.Lets start..
CP command
Well maybe you knows it already that cp command use for copy file or folder one place to another.
Syntax: cp option source destination
cp filename /tmp/filename # it will copy a file to /tmp/ directory
cp -r directory /tmp/directory # it will copy a directory with all the file content in it to /tmp/
cp -v filename /tmp/filename # it will show you copy information on terminal while copying (v=verbose)
cp -f filename /tmp/filename # forcefully copy (f=forcefully)
Now suppose you have an old file called AR.txt now you want to copy it to diffrent location..but you do not want to change timstamp. i mean you do not want to change permission,owner,time.
cp -p filename /tmp/filename # it will copy file to diffrent location without changing owner, permission,timestamp
wc command
syntax: wc -option
wc command is very usefull command when you are playing with log's file.
wc -l # it use for show count of line in a file. suppose i want know how much line is in a file
cat filename | wc -l # it will show you count's of line in file
wc -w # it will show you words in file
wc -c # shows characters in file
tail command
tail command is use for view content of a file .it will display line bottem to up. mostly this command use when you are monitoring logs.
tail -n 20 filename # it will display 20 line from file (n=number of lines)
tail -f access.log # it will display line in flow.suppose you have a log file called access.log and you want to monitor live. so it will show you in flow.
head command
head command is also like tail use for display file content.but opposite to tail it will display upper to bottem.
head -n 20 filename # display 20 line from a file
head -n 5 filename # display 5 lines
grep command:
grep use for pattern maching.
syntax: grep -option word filename
suppose we have a file and we want to search a word called David and we want to display that work only from that file.
$grep "David" filename or cat filename | grep "David"
$cat filename | grep -i "David" # 'i' use for casesensitive.
$cat filename | grep -iv "David" # it will not show the word david but will show others.
$cat filename | grep -A2 -B2 "David" # it will show 2 line before the pattern mach and 2 line after the patten macth. i mean 2 line before the david word and 2 lines after.
$netstat -tulnp |grep -E --color "httpd" # it will display httpd word with color. try this so u will understand.
find command
As name suggest fine command use for find a file or directory in system. now matter whatever location is of a file.
$find / -name indishell.txt # "/" is root "name" is for define filename. so it will find a file called indishell.txt in /(root)
$find / -iname indishell.txt # "iname" used for casesenseitive search
suppose you want to search all ".pdf files in root partition. then use this command.
$find / -name *.pdf # it will search all pdf file availaible in /(root)
$find / -name *mp3 # it will search all .mp3 extention files in root
#Find all files in ur home directory which has read permission to user.
$find . -perm -u=r -type f -exec ls -l {} \;
#Find all files in home directory which has read permission only to group.
$find . -perm g=r -type f -exec ls -l {} \;
#Find all empty files in your home directory
$ find ~ -empty
#Find files bigger than 100MB size
$find ~ -size +100M
Find files smaller than 10M size
$find ~ -size -100M
mkdir command
used for creat directory.
$mkdir directoryname
$mkdir -p /home/ar/directoryname # create parent directory
mv command
move a file or directory or rename
$mv indishell.txt /tmp/ # it will move a file indishell.txt to /tmp/
$mv indishell.txt ar.txt # it will rename indishell.txt to ar.txt
rm command
used for remove a directory or file
$rm filename # remove filename
$rm -r #Remove an entire directory as well as its included files and subdirectories
$rm -f # remove forcefully
touch command
used for creat an empty file
$touch filename
CP command
Well maybe you knows it already that cp command use for copy file or folder one place to another.
Syntax: cp option source destination
cp filename /tmp/filename # it will copy a file to /tmp/ directory
cp -r directory /tmp/directory # it will copy a directory with all the file content in it to /tmp/
cp -v filename /tmp/filename # it will show you copy information on terminal while copying (v=verbose)
cp -f filename /tmp/filename # forcefully copy (f=forcefully)
Now suppose you have an old file called AR.txt now you want to copy it to diffrent location..but you do not want to change timstamp. i mean you do not want to change permission,owner,time.
cp -p filename /tmp/filename # it will copy file to diffrent location without changing owner, permission,timestamp
wc command
syntax: wc -option
wc command is very usefull command when you are playing with log's file.
wc -l # it use for show count of line in a file. suppose i want know how much line is in a file
cat filename | wc -l # it will show you count's of line in file
wc -w # it will show you words in file
wc -c # shows characters in file
tail command
tail command is use for view content of a file .it will display line bottem to up. mostly this command use when you are monitoring logs.
tail -n 20 filename # it will display 20 line from file (n=number of lines)
tail -f access.log # it will display line in flow.suppose you have a log file called access.log and you want to monitor live. so it will show you in flow.
head command
head command is also like tail use for display file content.but opposite to tail it will display upper to bottem.
head -n 20 filename # display 20 line from a file
head -n 5 filename # display 5 lines
grep command:
grep use for pattern maching.
syntax: grep -option word filename
suppose we have a file and we want to search a word called David and we want to display that work only from that file.
$grep "David" filename or cat filename | grep "David"
$cat filename | grep -i "David" # 'i' use for casesensitive.
$cat filename | grep -iv "David" # it will not show the word david but will show others.
$cat filename | grep -A2 -B2 "David" # it will show 2 line before the pattern mach and 2 line after the patten macth. i mean 2 line before the david word and 2 lines after.
$netstat -tulnp |grep -E --color "httpd" # it will display httpd word with color. try this so u will understand.
find command
As name suggest fine command use for find a file or directory in system. now matter whatever location is of a file.
$find / -name indishell.txt # "/" is root "name" is for define filename. so it will find a file called indishell.txt in /(root)
$find / -iname indishell.txt # "iname" used for casesenseitive search
suppose you want to search all ".pdf files in root partition. then use this command.
$find / -name *.pdf # it will search all pdf file availaible in /(root)
$find / -name *mp3 # it will search all .mp3 extention files in root
#Find all files in ur home directory which has read permission to user.
$find . -perm -u=r -type f -exec ls -l {} \;
#Find all files in home directory which has read permission only to group.
$find . -perm g=r -type f -exec ls -l {} \;
#Find all empty files in your home directory
$ find ~ -empty
#Find files bigger than 100MB size
$find ~ -size +100M
Find files smaller than 10M size
$find ~ -size -100M
mkdir command
used for creat directory.
$mkdir directoryname
$mkdir -p /home/ar/directoryname # create parent directory
mv command
move a file or directory or rename
$mv indishell.txt /tmp/ # it will move a file indishell.txt to /tmp/
$mv indishell.txt ar.txt # it will rename indishell.txt to ar.txt
rm command
used for remove a directory or file
$rm filename # remove filename
$rm -r #Remove an entire directory as well as its included files and subdirectories
$rm -f # remove forcefully
touch command
used for creat an empty file
$touch filename
some other usefull commands
$pwd #used for display current working directory
$cat filename # used for view content of file
$cd /directory # used for go into directory
$cd .. # go back from current directory
$cd - # used for go to previous directory
$clear #Clear a command line screen/window for a fresh start.
$date #Display system date
$df -h #Display used and available disk space.
$file file_name #Determine what type of data is within a file.
$ls directory #List directory contents.
$who #
List logged-in users
$whoami #Display current user
$finger username #Displays info about user username
$command& #
Execute command in the background
$ps #list all process
$free -m #Display RAM+Swap usage
Post made by AR AR bhai ji (Thanks to him :) )
:D (Y) badia
ReplyDelete