108-Linux Shell Scripting
108-Linux Shell Scripting
ls list
ls -al list of hidden & all detail
cd .. Go one level up
cd ../.. Go two level up
cd directoryname(path) Go to specified directory(path)
cal for calender by day
cal -y for calender completely
who Print all usernames currently logged in
whoami who is current user
ls -al | less use | for get output from prior command and give it to
input of next comman (paging)
mkdir directoryname make directory
example : mkdir kianoosh make kianoosh folder
mkdir kianoosh rezaee make two folder kianoosh & rezaee
mkdir kianoosh\ rezaee make one folder kianoosh rezaee
clear clear the screen shortcut ctrl+l
touch filename create file with specified name
example : touch zanjan create file with zanjan name
touch kia{1,2,3} create three file kia1 kia2 kia3
touch kia{1..3} create three file kia1 kia2 kia3
echo “hello” print the hello in the output
echo “hello” > zanjan write hello in zanjan file (overwrite)
echo “hello” >> zanjan append hello to zanjan
cat zanjan to read file content
ls -al | grep zanjan to find zanjan in list of current path
grep -rin “test” . To find a string (test) in the file in current path
-r recursive
in insensetive
. current path
man commandname manual of command
example : man grep to see how to use grep or manual of grep
history to see history of command used in this computer up to now
example : history | grep ls |wc -l count of the ls command in history
wc word count
-l line
cp test1 test2 (test1,2 is file) copy the content of test1 to test2
cp -r folder1 folder2 copy folder1 to folder2
remaining -r recursive
example : cp folder1/folder2 . Copy folder2 to current path
mv test2 test5 rename the test2 to test5
mv test3 folder move or cut the test3 to folder or directory
rm test1 remove the test1
notice : evry thing in linux is file.
Cat /proc/cpuinfo see cpu information and performance
cat /proc/meminfo see memory information and performance
head -n3 /prco/meminfo to see 3 first line of memory information and performance
tail -n5 /proc/meminfo to see 3 last line of memory information and performance
find /home -iname “*.pdf” search in /home to finde all file with .pdf extention
remaining -i insensetive
VI Editor Commands
Vi has two modes insert mode and command mode.
The editor begins in command mode, where cursor movement and copy/paste editing occur.
Most commands execute as soon as typed except for "colon" commands which execute when
you press the return key.
Switch to Insert mode:
Change word cw
Replace one character r
Delete word dw
Delete text at cursor x
Delete entire line (to buffer) dd
Delete (backspace) text at cursor X
Delete 5 lines (to buffer) 5dd
Delete current to end of line D
Delete lines 5-10 :5,10d
Copy n
Copy line yy nyy Copy lines 1-2/paste after 3 :1,2t 3
lines
Paste above current line P
Paste below current line p Move lines 4-5/paste after 6 :4,5m 6
Join previous line J
Search
Search backward for string ?string forward for /string Find next string occurrence n
string
% (entire file) s (search and
replace) /old text with new/ c :%s/oldstring/newstring/cg Ignore case during search :set ic
(confirm) g (global - all)
Undo
Repeat last command . previous u Undo all changes to line U
command