0% found this document useful (0 votes)
136 views7 pages

Shell Script Commands List

This document provides summaries of Linux commands for file management, directory navigation, text editing and processing, system information, users and permissions. It describes commands for viewing calendars and dates, creating/deleting files and directories, copying/moving files, viewing file contents and properties, finding and searching files. It also summarizes commands for system monitoring, installing packages, setting file permissions, managing users and groups, and performing basic calculations and conditional checks.

Uploaded by

Satya Codes
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
136 views7 pages

Shell Script Commands List

This document provides summaries of Linux commands for file management, directory navigation, text editing and processing, system information, users and permissions. It describes commands for viewing calendars and dates, creating/deleting files and directories, copying/moving files, viewing file contents and properties, finding and searching files. It also summarizes commands for system monitoring, installing packages, setting file permissions, managing users and groups, and performing basic calculations and conditional checks.

Uploaded by

Satya Codes
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 7

cal : show calendar

cal <int month> <int year> : show calendar in certain month


cal <str month> <int year> : show calendar in certain month
date : show curent date

touch <filename> : create a new filename


pwd : show current path working directory
mkdir <directoryfilename> : create new directoryfilename folder
cd <directoryfilename> : change to the directoryfilename

cat > <filename> : create and insert text into the new filename
ctrl-d : exit from file
cat <filename> : show the content of the filename
cat < <filename> : take the content from the filename and show it on the screen
cat <filename1> <filename2> > <filename3> : merge the contents of filename1 and
filename2 into filename3
cat >> $<variable> : append the user input into the variable

mv <filename1> <filename2> : move filename1 into filename2, delete the filename1


after finish moving into filename2

rm <filename> : remove filename


mkdir <directoryfilename> : make new directoryfilename
rm -r <directoryfilename> : remove everything recursively in the directoryfilename
rmdir <directoryfilename> : remove directoryfilename

cp <filename1> <directoryfilename>/ <filename2>: copy filename1 into


directoryfilename with the new name as filename2, did not replace or delete the
filenaname1 unlike the mv command

clear : clear the linux terminal


ctrl-l : clear the linux terminal

ln <filename1> <filename2>: create hard link for filename1 with filename2, if


either one of the contents inside the file changed, both contents will change,
nothing will effect if either file deleted from the system

ln -s <filename1> <filename2> : create soft link, reference or pointer between


filename1 and filename2, if filename1 deleted, the filename2 cannot be open since
it depends, addressed, pointed to the filename1

ls <directoryfilename> : list and show what is within directoryfilename


ls : list and show what is within current path working directory
ls -l : long listing what is within current path working directory with number of
memory blocks occupied by all the files and folders combined together, and also
show the permission for each files.
ls -l <filename> : long listing for filename and the number of memory blocks
occupied by all the files and folders combined together, and also show the
permission for each files.
ls -lh : long listing what is within current path working directory with number of
memory blocks occupied by all the files and folders combined together, and also
show the permission for each files in human readable format
ls -lh <filename> : long listing for filename and number of memory blocks occupied
by all the files and folders combined together, and also show the permission for
each files in human readable format
ls -s : show the size for the current directory
ls -s * : show the size for the current directory and all its contents
ls -sh : show the size for the current directory in human readable format
ls -sh * : show the size for the current directory and all its contents in human
readable format
ls -s <filename> : show the size for filename
ls -sh : show the size for filename in human readable format

du : show the directories


du -s : show the size of all directories
du * : show all the directories within
du -s * : show the size of all directories
du -sh : show the size of all directories in human readable format
du -sh * : show the size of all the directories within in human readable format

* a block is basically a unit of memory that is used for memory organization by


UNIX/Linux operating system

ctrl-h : show hidden files


ls -a : list and show all the files included the hidden (starting from .) hidden
files

free : show all information of the system memory


free -h : show all information of the system memory to be readable by human
watch free -h : show all information of system memory in real time

hostname : show the host name

apt-get install <modulename> : get the modulename and install it into the system

chmod <numeric value> : change the permission of the file


* read | r = 4
* write | w = 2
* execute | x = 1

* owner | group | all users

whoami : show who is currently log into the system

uname : unix name, shows the name of operating system used


uname -a : unix name, shows all the information about the system

adduser <username> : add username to the system


userdel <username> : delete username from the system

cat /etc/passwd : show the content of user password and other related information

passwd <username> : change the password for the username

groupadd <groupname> : add new groupname from system


groupdel <groupname> : delete groupname from system

adduser <username> <groupname> : add username into groupname


deluser <username> <groupname> : delete username from groupname

vim /etc/group : show contents of existing groups in vim editor

chmod <permission number> <filename> -R : change the permission mode for the
filename recursively
chmod <permission number> <directoryfilename> -R : change the permission mode for
the directoryfilename recursively including all its subfolders
chmod <permission number> <directoryfilename> -r : change the permission mode for
the directoryfilename recursively under the directoryfilename but not all of its
subfolders

* drwxrwxrwx
* <directory><owner><group<others/all users>
* <directory><(read)(write)(execute)><(read)(write)(execute)><(read)(write)
(execute)>
* <directory><(4)+(2)+(1)><(4)+(2)+(1)><(4)+(2)+(1)>
* <directory><7><7><7>

chown -R <username> <directoryfilename> : change owner recursively for


directoryfilename and all its subfolders
chgrp -R <groupname> < directoryfilename> : change group recursively for
directoryfilename and all its subfolders.

file * : list all files and its type

wc <filename> : count the contents in filename


* <number of lines> <number of words> <number of characters> <file name>

wc -l <filename> : count the lines in filename


wc -w <filename> : count the words in filename
wc -c <filename> : count the characters in filename

sort : sort the input from user


sort <filename> : sort the text in filename in alphabetical order

cut -d"<delimiterused>" -f"<numberoffield>" <filename> : cut the text in filename


and only left the numberoffield

dd if=<filename1> of=<filename2> conv=<format> : data definition which convert


input filename1 into filename2 in certain format

ls /dev : list Linux drivers


ls /proc : list Linux processes

*gp = globally print


*g/re/p = globally print regular expression

find -name <extension> : find the list of files that ends with extension
find -name <extension> -type d : find list of directories that ends with extension

apt-get install tree : install Linux tree module into Linux machine

tree : list the tree file diagram for the Linux file system

apt-get install htop : install Linux htop module into Linux machine

htop : shows what is going on the Linux machine in colour

man <command> : show the manuals for the command

apt-get install sysvbanner : install the Linux sysvbanner module into local machine

banner <input> : show fancy test for input

apt-get install ncompress : install Linux ncompress module into the machine

compress -v <filename> : reduce the file size of filename into filename.Z


zcat <filename.Z> : show the contents of filename.Z

uncompress <filename.Z> : uncompress the filename.Z into filename with its original
size and contents

echo * : show all the files in the current working path


echo <string>* : show all the files that start with the string
echo *<string> : show all the files that end with the string
echo [[:upper]] : show all the files that start with uppercase letter
echo ~ : show the current user
echo $(<mathoperation>) : show the result of current mathoperation, answer will
ignore the floating point

sh <filename.sh> : execute filename.sh shell script

set <input> : set positional parameters for input


echo $<number> : show the positional parameters of certain input
echo $* : show all positional parameters of the input
echo $# : count the number of command line arguments

expr <mathematicalexpression> : calculate the mathematicalexpression


echo expr <mathematicalexpression> : show the result of mathematicalexpression
calculation

echo 'echo <arithmetic> | bc' : show the result of arithmetic calculation in


floating point arithmetic format

echo "<text1> \r<text2>" : consider text1 as rubbish, useless, only print text2
echo "<text1> \t<text2>" : print text1, tab and print text2
echo "<text1> \n<text2>" : print text1, make new line and print text2
echo "<text1> \b<text2>" : print text1, do backspace and print text2

echo "\033[1m<text1>\033[0m" : print text1 in bold mode


echo "\033[4m<text1>\033[0m" : print text1 in underline mode
echo "\033[7m<text1>\033[0m" : print text1 in highlight mode

tput lines : show current number position of columns on Linux


terminal
tput rows : show current number position of rows on Linux
terminal
tput cup <number1> <number2> : put the cursor on the columns <number1> and rows
<number2> on Linux terminal

echo $? : will output 0 if the command executed is successful, will output 1


if the command executed is unsuccessful
read <input> : read the input

if <statement> : if execute statement


else <statement> : else execute statement
elif <statement> : else if execute statement
fi <statement> : end if statement

-lt <number> : less the number


-gt <number> : greater than number
-eq <number> : equals the number
-le <number> : less and equals to number
-ge <number> : greater and equals to number
-ne <number> : not equals to number
-f $<variable> : check for files
-d $<variable> : check for directory files
-c $<variable> : check for character files
-b $<variable> : check for block files
-r $<variable> : check for read permission
-w $<variable> : check for write permission
-x $<variable> : check for execute permission
-s $<variable> : check for file size

chmod -r <filename> : take away read permission from filename


chmod -w <filename> : take away write permission from filename
chmod -x <filename> : take away execute permission from filename

chmod +r <filename> : give filename read permission


chmod +w <filename> : give filename write permission
chmod +x <filename> : give filename execute permission

[ "$<variable1>" = "$<variable2>" ] : check if variable1 is equals to variable2


[ "$<variable1>" != "$<variable2>" ] : check if variable1 is not equals to
variable2
[ -n "$<variable>" ] : check if variable got a value number
[ -z "$<variable>" ] : check if variable is zero

if [ <statement1> -a <statement2> ] : check if statement1 and statement2 are true

if [ `echo $<variable> | wc -c` <logicaloperation> <number> ] : word counts the


characters in the variable to match the logical operation and the number

*Linux also count end of line as a character

if [ $<variable> = <character1> -o $<variable> <character2> ] : check if the


variable is equal to character1 or proceed to check if the variable is equal to
character2

case $<variable> in : check user case statement in the variable

[a-z]) : check user case statement whether it is from a to z lowercase


character
[A-Z]) : check user case statement whether it is from A to Z uppercase
character
[0-9]) : check user case statement whether it is from 0 to 9 character
?) : check user case statement whether it is a special case symbol
*) : check user case statement whether it is more than one
character
[aeiou]* | [AEIOU]* : check user case statement whether it starts from a vowel

;; : break from the user case


esac : exit from user case statement

while [ $<variable> <logicaloperator> <number> ] : do while statement for the


variable that fit with the logical operation based on number and logical operator
until [ $<variable> <logicaloperator> <number> ] : do until statement for the
variable that fit with the logical operation based on number and logical operator

for item in * : search all files in Linux current path working directory

do : enter the loop statement


done : exit from the loop statement
then : execute the following statement
for item in * : search all files in Linux current path directory

grep <text> <textfile> : search the text in textfile

-i : case insensitive
-n : show the line number
-c : count

-v <text> <textfile> : show the line in textfile that do not match the text

grep ^'<text>' <textfile> : show text that is at the start of the lines in the
textfile
grep '<text>'^ <textfile> : show text that is at the end of the lines in the
textfile
grep $'<text>' <textfile> : search word that starts with the text in the textfile
grep $'<text>' <textfile> : search word that ends with the text in the textfile

grep 'th..' <textfile> : search for word that have th and any two more other
characters on it in the textfile

grep '[0-9]\{<number1>,<number2>}' <textfile> : search for number 0 till number 9


for the number1 and number2 digit in the textfile

grep '\<<text>\>' <textfile> : search for specific text in the textfile

!! : run the previous command


-e : escape, take the next command as a pattern
-n : show number of lines

history : show history of the Linux terminal commands

sed 's<delimiter><text1><delimiter><text2>' <oldfile> > <newfile> :


replace the text1 with text2 from oldfile to newfile
sed 's<delimiter><text1><delimiter><text2><delimiter>g' <oldfile> > <newfile> :
replace the text1 with text2 from oldfile to newfile globally

cat /etc/passwd : show the password storage contents in the Linux system

* <username>:<password>:<userid>:<commentsfield>:<homefolder>:<defaultshell>

IFS=<userinput> : set the Internal Field Separator with userinput

tty : command that contain information about Linux terminal

read <variable> : read from variable by line

sleep <number> : sleep the execution of command for number seconds

man <command> >> <filename> : store the manual for command into filename

break : break out from the loop statement


continue : skip the current statement and then continue the loop

<command1>;<command2>;<command3> : execute command1 then execute command2 then


execute command3

grep <command1> && <command2> : execute command2 if command1 is successful


grep <command1> || <command2> : execute command2 even though command1 is
unsuccessful

chmod +x <functionshellscript> : give the functionshellscript an executable


permission

. <functionsehellscript> : execute the functionshellscript

unset <function> : remove the function from the shells command

You might also like