DVS Linux Commands
DVS Linux Commands
ls -1
3. clear
Clear Terminal screen
Ctrl + L (shortcut)
4. man
format and display the on-line manual pages
man ls
cp origfile /directory/subdirectory/newfile
cp *.jpg /directory/subdirectory
cp -R /one/two /three/four
Copy the directory two (located in the directory /one), and everything two
contains, into the destination directory /three/four. The result will be called
/three/four/two. The directory /three must already exist for the command to
succeed. If the directory four does not already exist in the directory /three, it
will be created.
9 move/rename file
11. CAT command (to create/append file or display the content of the file)
12. MORE is a filter for paging through text one screen at a time
13. Less same as more only but forward and backward both possible
tail /var/log/Xorg.0.log
tail -15 /var/log/Xorg.0.log (Display the last 15 lines)
tail -f ==> Output the contents of the file as it grows. Useful to monitor
log
16. sed ==> stream editor for filtering and transforming text
sed -n '5,10p' myfile.txt (prints 5 to 10 lines)
sed '10,15d' myfile.txt (exclude line 10 to 15)
sed -n -e '5,7p' -e '10,13p' myfile.txt
sed 's/unix/linux/' myfile.txt (s-substitution)
sed 's/unix/linux/g' myfile.txt (global)
sed 's/unix/linux/gi' myfile.txt (global)
sed '5d' myfile.txt (excludes 5th line)
sed '$d' myfile.txt (excludes last line)
sed '5,8d' myfile.txt (excludes 5th-8th line)
sed '5,$d' myfile.txt (excludes 5th to last line)
17. Grep
grep stands for "global regular expression print
grep 'word' filename
grep 'word' file1 file2 file3
21. chown:
changing ownership of a file/directory
ls -l file1.txt (to check ownership)
sudo chown training file1.txt (give permission to training user)
22. shortcuts
Ctrl+C � Cancels the currently running command.
Ctrl+D � log out of current session, similar to exit
Ctrl+W � erases one word in the current line(useful in editors)
Ctrl+U � erases the whole line(useful in editors)
23. history -list the last 1000 successful commands with unique id.
history 20 ( list the last 20 commands)
history | less
history | head
history | tail
history -c (to clear the history)
!21 (To run 21st command from history)
date
date -d today
yesterday,tomorrow,sunday,last-sunday,last-week,next-week,last-month,next-
month,last-year,next-year)
date --date="next mon"
date --date="yesterday"
date --date="1 month ago"
date --date="1 year ago"
cal
cal 2015
cal 2 2015
cal -3 (the previous, current and next month)
cal -y (calendar for whole year)
cal -m (monday as first day)
cal -s (sunday as first day)
i Inserts text before the current cursor location(goes into insert mode)
a Write after cursor (goes into insert mode)
A Write at the end of line (goes into insert mode)
o Creates a newline for text entry belowcursor location (goes into insert
mode)
O Creates a new line for text entry above cursor location (goes into insert
mode)
esc Terminate insert mode
Create a file using a vi editor(or any other editor). Name script file with
extension .sh
Start the script with #! /bin/sh (meaning that the script should always be run
with bash)
Write some code.
Save the script file as filename.sh
For executing the script type bash/sh filename.sh
step1: vi script1.sh
step2: #!/bin/sh
ls
step3: sh scriptsample.sh
The first line tells Unix that the file is to be executed by /bin/sh
The only exception is when the very first line of the file starts with #!
# for comment
x="hello"
echo $x
#!/bin/sh
echo "what is your name?"
read name
echo "How do you do, $name?"
read remark
echo "I am $remark too!"
41. CRON
The basic usage of cron is to execute a job at a specific time
Copy your shell script �script.sh` or �script� into one of the directories above.
If you need to run the script hourly
Give the shell script the correct permission. For example, if script is called
�script.sh�, set permission as follows:
cd /etc/cron.daily/
chmod 755 script.sh
crontab -u training -e
su to go to root user
* means every
0 1 * * 5 /bin/execute/this/script.sh
(Execute every Friday 1AM)
0 1 * * 1-5 /bin/execute/this/script.sh
(Execute on workdays 1AM)
MAILTO="yourname@yourdomain.com"