Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
13 views

Learning Basic Linux Commands

Uploaded by

prazu6
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Learning Basic Linux Commands

Uploaded by

prazu6
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

Bachelor of Science in Computer Science and

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)

1.1. Command Name: ls

Syntax: ls [options] [file]

Usage: used for listing directory contents

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

Syntax: cd [-L|[-P [-e]] [-@]] [dir]

Usage: used for the shell working directory

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:

1.3. Command Name: grep

Syntax: grep [option] patterns [file]

Usage: used for searching patterns in each file

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:

1.4. Command Name: sudo

Syntax: sudo [option]

Usage: used for executing command as a super user or other user

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:

1.5. Command Name: pwd

Syntax: pwd [option]

Usage: used for printing the name of current working directory

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

Syntax: mv [option] SOURCE DESTINATION

Usage: used for moving/renaming files

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

Syntax: cp [option] SOURCE DESTINATION

Usage: used for copying files and directories

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

Syntax: rm [option] [file]

Usage: used for removing files and directories

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

Syntax: mkdir [option] DIRECTORY

Usage: used for making directories

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

Syntax: rmdir [option] DIRECTORY

Usage: used for removing empty directory

Commands Used:
➢ rmdir js/ -> removes js directory
➢ rmdir -v css/ -> removes css directory and prints message for it

Output:

1.11. Command Name: chmod

Syntax: chmod [MODE] FILE


r -> read
w-> write
x-> execute

Usage: used for changing file mode/permissions

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

Syntax: cat [option] FILE

Usage: used for concatenating and printing on the standard output

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

Syntax: chown [option] [owner] [:[group]] FILE

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

Syntax: echo [option] [string]

Usage: used for printing string to standard output

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

Syntax: wc [option] [file]

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

Syntax: man [command]

Usage: used for displaying manual page for commands

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

Syntax: history [option]

Usage: used for viewing the list of previously executed commands

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

Usage: used for clearing the terminal screen

Commands Used:
➢ clear -> cleans terminal screen

Output:

1.19. Command Name: touch

Syntax: touch [option] FILE

Usage: used for creating, changing and modifying timestamps of a file

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:

1.20. Command Name: locate or plocate

Syntax: locate [option] PATTERN

Usage: used for finding files by name, quickly

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

Syntax: df [option] [file]

Usage: used for reporting file system disk space usages

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

Syntax: du [option] [file]

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

Syntax: passwd [option] [login]

Usage: usef for changing the user password

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

Syntax: lsblk [option] [device]

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

Syntax: useradd [options]

Usage: used for creating new users

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:

1.27. Command Name: userdel

Syntax: userdel [options]

Usage: used for removing user


Commands Used:
➢ userdel khonshu -> removes user with the name khonshu
➢ userdel -f steven -> forces the removal of user’s(steven) account
➢ userdel -r mark -> mark’s home directory will be removed along
with mark’s mail spool

Output:

1.28. Command Name: apt-get

Syntax: apt-get [options]

Usage: used for handling packages

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

Syntax: ping [options] {destination}

Usage: used for sending ICMP ECHO_REQUEST to network hosts

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

Syntax: find [options] [path] [expression]

Usage: used for searching for files in a directory hierarchy

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:

1.31. Command Name: head

Syntax: head [options] [file]

Usage: used for printing the first part of file

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

Syntax: uname [option]

Usage: used for printing system information

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

Syntax: tail [option] [file]

Usage: used for printing the last 10 lines of a file

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

Syntax: tac [option] [file]

Usage: used for concatenating printing files in reverse

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

Syntax: comm [option] FILE1 FILE2

Usage: used for comparing different files

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

Syntax: cut [option] [file]

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

Syntax: sort [option] [file]

Usage: used for sorting the content of files

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

Syntax: date [option] [format]

Usage: used for displaying current date in given format

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:

1.39. Command Name: time

Syntax: time [option] [command]

Usage: used for printing the a summary of system resource usage

Commands Used:
➢ time
➢ time -p prints time in POSIX format\
➢ time sleep 5
Output:

1.40. Command Name: host

Syntax: host [-aACdlnrsTUwv] [-c class] [-N ndots] [-p port] [-R number] [-t type] [-W
wait] [-m flag] [ [-4] | [-6] ] [-v] [-V] {name} [server]

Usage: used for DNS lookup operations

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

Syntax: id [option] [user]

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

Syntax: kill [option] <pid>

Usage: used for sending a signal to a process

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

Syntax: pkill [options] pattern

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 ...

Usage: usef for killing process by 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

Syntax: bg [job_spec ...]

Usage: used for moving jobs to the background

Commands Used:
➢ jobs -> lists all jobs
➢ bg %1 -> moves stopped job having id 1 to background
➢ bg “%ping” -> moves stopped job to background

Output:

1.48. Command Name: fg

Syntax: fg [job_spec]

Usage: used for moving job to the foreground

Commands Used:
➢ fg %- -> brings previous job to foreground
➢ fg %1 -> brings job having id 1 to the foreground
Output:

1.49. Command Name: tar

Syntax: tar [options] [archive-file] [file or directory to be


archived]

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

Syntax: gzip [Options] [filenames]

Usage: used for compressing the files

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:

You might also like