Learning Basic Linux Commands
Learning Basic Linux Commands
Information Technology
Laboratory
Report
Of
Operating System
Submitted By : Submitted To :
Name : Basanta Rai Department Of Computer
Semester : 4th Science
Section : B
Rollno : 23473
Lab 1: Learning basic Linux commands
OS Used: Ubuntu(22.04 LTS)
Commands Used:
➢ ls -> lists all the unhidden files and directories within current
directory
➢ ls laravel -> lists all the files and directories of laravel directory
➢ ls -l cc -> lists files in long listing format which includes:
○ The file type.
○ The file permissions.
○ Number of hard links to the file.
○ File owner.
○ File group.
○ File size.
○ Date and Time.
○ File name.
Output:
1.2. Command Name: cd
Commands Used:
➢ cd cc -> change working directory to cc
➢ cd presentations -> change directory to presentations
➢ cd .. -> get back to cc directory
➢ cd 4th-sem/toc -> change directory to 4th-sem/toc
➢ cd ../.. -> move to upper directory
➢ cd ~ -> move to home directory
Output:
Commands Used:
➢ grep html index.html -> prints the whole line of matched term
➢ grep -o body index.html -> prints only matched term
➢ grep -n head index.html -> prints matched content with line number
➢ grep -s container index.html -> suppress error message if any
Output:
Commands Used:
➢ sudo -i -> runs login shell for current user (basanta)
➢ whoami -> prints current user name associated with current
effective user ID
➢ sudo whoami -> prints root user
➢ sudo -u layla whoami -> runs whoami command as another user
(layla)
➢ sudo apt-get update -> resynchronizes the package index files from
their sources
➢ sudo apt-get upgrade -y -> install the newest versions of all
packages
Output:
Commands Used:
➢ pwd -> prints current working directory
➢ pwd - - help -> prints help menu for pwd
➢ pwd -P -> prints the physical directory without symbolic links
Output:
1.6. Command Name: mv
Commands Used:
➢ mv styles.css css/ -> moves styles.css file to css directory
➢ mv errors.html error.html -> renames errors.html file as error.html
➢ mv -v blogs.html blog.html -> explains what is being done
Output:
1.7. Command Name: cp
Commands Used:
➢ cp index.html error.html -> copies contents of index.html to
error.html
➢ cp -r src web/ -> recursively copies src directory to web directory
➢ cp src/main.js js/ -> copies main.js file to js directory
Output:
1.8. Command Name: rm
Commands Used:
➢ rm blog.html -> removes blog.html file
➢ rm -v error.html -> removes error.html and explains what is being
done
➢ rm -rd src/ -> removes src folder
➢ rm -vrdf js -> removes directory and files contained by it
➢ rm -ird css/ -> removes directory and files contained and prompts
before every removal
Output:
1.9. Command Name: mkdir
Commands Used:
➢ mkdir html -> creates html directory
➢ mkdir -v css -> creates css directory and prints message for it
➢ mkdir -m 567 js -> creates js directory with 567 mods
Output:
1.10. Command Name: rmdir
Commands Used:
➢ rmdir js/ -> removes js directory
➢ rmdir -v css/ -> removes css directory and prints message for it
Output:
Commands Used:
➢ chmod +rwx index.html -> adds read,write and execute permission
to index.html
➢ chmod -rwx index.html -> removes read,write and execute
permission from index.html
➢ chmod +x file.bash -> adds executable permission to file.fash file
Output:
1.12. Command Name: cat
Commands Used:
➢ cat index.html -> prints the content of index.html
➢ cat -b index.html -> numbers non empty lines
➢ cat -s index.html -> suppresses repeated empty output lines
➢ cat -n index.html -> number all output lines
Output:
1.13. Command Name: chown
Usage: used for changing the user and group ownership of file
Commands Used:
➢ chown layla index.html -> changes ownership of index.html file to
layla
➢ chown -v root index.html -> changes ownership to root and prints
diagnostics for it
➢ chwon layla:developers error.html -> changes owner as well as
group (user->layla , group->developers)
➢ chown - - reference=error.html index.html -> copies ownership from
error.html to index.html
➢ chown - - from=:developers basanta index.html error.html ->
changes group from one to another
Output:
1.14. Command Name: echo
Commands Used:
➢ echo Mark -> prints Mark
➢ echo -n “Hello MOM” -> do not output the trailing newline
➢ echo -e "Khonshu \bGod \bof \bMOON" -> removes all the spaces
between words
➢ echo -e “Apple \nBall \nCat” -> outputs each word in new line
Output:
1.15. Command Name: wc
Usage: used for printing newline, word, and byte counts for each FILE
Commands Used:
➢ wc Dockerfile -> prints number of lines, words and characters in
Dockerfile
➢ wc -c Dockerfile -> prints byte counts in Dockerfile
➢ wc -m Dockerfile -> prints the character counts in Dockerfile
➢ wc -w Dockerfile -> prints the word counts in Dockerfile
➢ wc -l Dockerfile -> prints the newline counts in Dockerfile
Output:
1.16. Command Name: man
Commands Used:
➢ man echo -> displays manual page for echo
➢ man -f grep -> displays short description about grep
➢ man -k mkdir -> searches the given command as a regular
expression in all the manuals and it returns the manual pages
with the section number in which it is found
➢ man -w pkill -> returns the location in which the manual page
of a pkill command is present
Output:
1.17. Command Name: history
Commands Used:
➢ history -> lists previously executed commands
➢ history 10 -> shows the limited number of previously executed
commands
➢ !! -> shows most recently executed command
➢ history -d 2003 -> removes history by event number
➢ history -c -> removes all history
Output:
1.18. Command Name: clear
Syntax: clear
Commands Used:
➢ clear -> cleans terminal screen
Output:
Commands Used:
➢ touch detail.txt hello.txt random.txt -> creates files named as
details.txt,hello.txt and random.txt
➢ touch -c help.txt -> does not creates any file
➢ touch -d 2022 khonshu.txt -> uses string (2022) instead of current
time
Output:
Commands Used:
➢ locate random.txt -> searches for random.txt file
➢ locate “*.blade.php” -n 10 -> limits search query to specific number
(10)
➢ locate “*.html” -l 5 -> stops searching after limit (5) matches have
been found
Output:
1.21. Command Name: df
Commands Used:
➢ df -a -> displays all the file systems
➢ df -h -> prints sizes in powers of 1024
➢ df -T -> prints the file system type
➢ df ~/.vimrc -> shows mount information of particular file (.vimrc)
Output:
1.22. Command Name: du
Usage: summarizes disk usage of the set of FILEs, recursively for directories
Commands Used:
➢ du ushits -> prints disk usages
➢ du -s ushits -> prints summary of file system
➢ du -c ushits -> prints total size
➢ du -sh ushits -> prints summary of file system in human readable
format
➢ du -a ushits -> write counts for all files, not just directories
Output:
1.23. Command Name: passwd
Commands Used:
➢ passwd -> change current user’s password
➢ sudo passwd layla -> change layla’s password
➢ sudo passwd -d layla -> delete user’s password
➢ sudo passwd -e layla -> immediately expires an account’s
password
➢ sudo passwd -q mark -> quiet mode
➢ sudo passwd -u mark -> unlocks the password of the named
account
Output:
1.24. Command Name: lsblk
Usage: used for listing information about all available or the specified block devices
Commands Used:
➢ lsblk -> lists block devices
➢ lsblk - a -> lists empty devices and RAM disk devices as well
➢ lsblk -b -> prints the SIZE column in bytes
➢ lsblk -f -> outputs info about filesystems
➢ lsblk -i -> use ASCII characters for tree fromatting
Output:
1.26. Command Na
me: useradd
Commands Used:
➢ useradd khonshu -> creates a new user with the name khonshu
➢ useradd -m mark -> creates the user’s home directory
➢ useradd layla -c “Layla is cute” -> adds short description of login
➢ useradd -G developers steven -> adds user steven to the
developers group
Output:
Output:
Commands Used:
➢ apt-get update -> resynchronizes the package index files from their
sources
➢ apt-get upgrade -y -> install the newest versions of all packages
currently installed on the system from the sources
➢ apt-get install gimp -> installs gimp software
➢ apt-get purge gimp -> uninstalls gimp
➢ apt-get autoclean -> clears out the local repository of retrieved
package files
➢ apt-get autoremove -> removes packages that were automatically
installed to satisfy dependencies for other packages and are now
no longer needed
Output:
1.29. Command Name: ping
Commands Used:
➢ ping google.com -> pings google.com
➢ ping -c 3 google.com -> stops after sending 3 ECHO_REQUEST
packets
➢ ping -4 -c 5 google.com -> uses ipv4 only and stops after sending 5
ECHO_REQUEST packets
➢ ping -6 -c 5 google.com -> uses ipv6 only and stops after sending 5
ECHO_REQUEST packets
➢ ping -i 10 -c 3 google.com -> send 3 ECHO_REQUEST packets in
the interval of 10 seconds
Output:
1.30. Command Name: find
Commands Used:
➢ find ~/.vimrc -> searches for `.vimrc` file
➢ find ~/.config/nvim -type d -> find all directories in the
`~/.config/nvim` directory
➢ find ~/.config/polybar -mtime +10 -daystart -> list all files in the
~/.config/polybar directory that were modified 10 or more
days ago
Output:
Commands Used:
➢ head ~/.vimrc -> prints the first 10 lines of `.vimrc` file
➢ head -v ~/.vimrc -> prints first 10 lines of `.vimrc` file with header
giving file name
➢ head -n 5 ~/.vimrc -> prints the first 5 lines of `.vimrc` file
Output:
1.32. Command Name: uname
Commands Used:
➢ uname -s -> prints the kernel name
➢ uname -n -> prints the hostname
➢ uname -v -> prints the kernel version
➢ uname -r -> prints the kernel release
➢ uname -m -> prints machine hardware name
➢ uname -p -> prints the processor type
➢ uname -i -> prints the hardware platform
➢ uname -o -> prints the operating system
Output:
1.33. Command Name: tail
Commands Used:
➢ tail ~/.bashrc -> prints the last 10 lines of the `.bashrc` file
➢ Tail -n 5 ~/.bashrc -> prints the last 5 lines of the `.bashrc` file
➢ Tail -v ~/.bashrc -> prints last 10 lines of the `.bashrc` file along with
filename as a header
cat
Output:
1.34. Command Name: tac
Commands Used:
➢ cat nlone.js -> prints file content from `nlone.js` in normal form
➢ tac nlone.js -> prints file content from `nlone.js` in reverse
➢ tac nltwo.js nlone.js -> prints file contents in reverse
➢ tac -b nlone.js -> attach the separator before instead of after
➢ tac -s nlone.js nltwo.js -> use string as separator instead of newline
➢ tac -r nlone.js nltwo.js -> interpret the separator as regular
expression
Output:
1.35. Command Name: comm
Commands Used:
➢ cat nlone.js -> print contents of nlone.js file
➢ cat nltwo.js -> print contents of nltwo.js file
➢ comm nlone.js nltwo.js -> compares two files
➢ comm --nocheck-order nlone.js nltwo.js -> compares two files and
suppresses warning
➢ comm -1 --nocheck-order nlone.js nltwo.js -> suppress column 1
and display column 2 only
➢ comm -12 --nocheck-order nlone.js nltwo.js -> suppress column 1
and 2
➢ comm --total --nocheck-order nlone.js nltwo.js -> output summary
➢ comm --zero-terminated nlone.js nltwo.js -> line delimiter will be null
not a new line
➢ comm --output-delimiter=--- nlone.js nltwo.js -> separate columns
with - - -
Output:
1.36. Command Name: cut
Usage: used for cutting parts of a line by field, delimiter, byte position, and character
and printing the result to standard output
Commands Used:
➢ cut -c 1 sample.txt -> extracts first character from each line
➢ cut -c 1,3 sample.txt -> extracts two character from each line
➢ cut -d: -f 1,6 /etc/passwd -> returns each user in the system and
their home directory, corresponding to fields 1 and 6, respectively
Output:
1.37. Command Name: sort
Commands Used:
➢ sort sample.txt -> sort the content of `sample.txt`
➢ sort -r sample.txt -> sort contents of `sample.txt’ in reverse order
➢ sort -c sample.txt -> checks whether the file is already sorted or not
➢ sort -u sample.txt -> sorts the contents and removes the duplication
Output:
1.38. Command Name: date
Commands Used:
➢ Date -> prints the current date
➢ date -R -> prints date in RFC format
➢ date +’%a, %b %d’ -> print date in given format
➢ date -d yesterday -> prints yesterday's date
➢ date -u -> prints in UTC format
Output:
Commands Used:
➢ time
➢ time -p prints time in POSIX format\
➢ time sleep 5
Output:
Syntax: host [-aACdlnrsTUwv] [-c class] [-N ndots] [-p port] [-R number] [-t type] [-W
wait] [-m flag] [ [-4] | [-6] ] [-v] [-V] {name} [server]
Commands Used:
➢ host -4 google.com -> uses ipv4 for query
➢ host -t ns google.com -> specifies type of the query
➢ host -a google.com -> enables verbose output
Output:
1.41. Command Name: id
Usage: used for printing the user and group information for each specified USER
Commands Used:
➢ id -> prints the user and group information for current user(basanta)
➢ id - a layla -> prints user and group information for layla
➢ id -G basanta -> prints all group IDs
➢ id -G layla -> prints all group ID
Output:
1.42. Command Name: ps
Syntax: ps [options]
Usage: used for displaying information about a selection of the active processes
Commands Used:
➢ ps -> displays processes for the current shell
➢ ps -t -> selects the processes associated with terminal
➢ ps -u -> selects the processes whose effective user name or ID is in
userlist
➢ ps -s -> displays process in signal format
➢ ps ax -> displays every process on the system using BSD syntax
Output:
1.43. Command Name: top
Syntax: top -hv|-bcEeHiOSs1 -d secs -n max -u|U user -p pids -o field -w [cols]
Usage: used for displaying system summary information as well as a list of processes
or threads currently being managed by the Linux kernel
Commands Used:
➢ top -> displays user processes for current user(basanta)
➢ top -u layla -> displays user processes for specified user(layla)
Output:
1.44. Command Name: kill
Commands Used:
➢ kill -9 3396 -> kill all process of id 3396
➢ kill -l -> lists signal name
➢ kill 13986 -> process receives a kill signal
Output:
1.45. Command Name: pkill
Usage: used for sending signals to the processes of a running program based on given
criteria
Commands Used:
➢ pkill polybar -> kills processes for polybar
➢ pkill -e chromium-browse -> displays name and PID of the process
being killed (chromium-browse)
Output:
1.46. Command Name: killall
Syntax: killall [-Z, --context pattern] [-e, --exact] [-g, --process-group] [-i, --interactive]
[-n, --ns PID] [-o, --older-than TIME] [-q, --quiet] [-r, --regexp] [-s, --signal SIG‐
NAL, -SIGNAL] [-u, --user user] [-v, --verbose] [-w, --wait] [-y, --younger-than TIME]
[-I, --ignore-case] [-V, --version] [--] name ...
Commands Used:
➢ killall nautilus -> kills all process having name nautilus
➢ killall -v gnome-calculator -> reports if signal is sent successfully or
not
➢ killall -i gnome-calculator -> interactively asks for confirmation
before killing
Output:
1.47. Command Name: bg
Commands Used:
➢ jobs -> lists all jobs
➢ bg %1 -> moves stopped job having id 1 to background
➢ bg “%ping” -> moves stopped job to background
Output:
Syntax: fg [job_spec]
Commands Used:
➢ fg %- -> brings previous job to foreground
➢ fg %1 -> brings job having id 1 to the foreground
Output:
Usage: used for create Archive and extract the Archive files
Commands Used:
➢ tar cvf blog.tar *.html -> creates a tar file called `blog.tar` which
is the Archive of all .html files in current directory
➢ tar xvf blog.tar *.html -> extracts files from Archives
Output:t
1.50. Command Name: gzip
Commands Used:
➢ gzip index.html -> creates a compressed file of index.html named
as index.html.gz and deletes the original file
➢ gzip -k error.html -> creates compressed file of error.html named
as error.html.gz and also keeps the original file
➢ gzip -L contact.html -> displays the gzip license
➢ gzip -r html -> compresses every file in the colder and its subfolders
➢ gzip -v blog.html -> displays the name and percentage reduction
for each file compressed
➢ gzip -d blog.html.gz -> decompress a file
➢ gzip -vd contact.html.gz -> displays the name and percentage
reduction for each file decompressed
Output: