0% found this document useful (0 votes)
17 views

Ubuntu

Uploaded by

prazu6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Ubuntu

Uploaded by

prazu6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Lab 1: Learning basic Linux commands OS Used:

Ubuntu (22.04 LTS)


1.1. Command Name: ls
Inside a folder you can list all the files that the folder contains using
the ls command:
 Syntax: ls [options] [file]
 Usage: used for listing directory contents
 Commands Used:
 ls -> lists all the unhidden files and directories within current director

 ls -l -> This option enables the long listing format, providing detailed
information about each file or directory.
 ls -t -> This option sorts the list by modification time, with the newest
files or directories appearing first.
 ls -r -> This option reverses the order of the sort, displaying the oldest
files or directories first.
So, "ls -ltr" will list the contents of the current directory in long format, sorted
by modification time, with the oldest files or directories appearing first.
Output:

1.2. Command Name: cd


Once you have a folder, you can move into it using
the cd command. cd means change directory. You invoke it specifying a folder
to move into. You can specify a folder name, or an entire path.
 Syntax: cd [-L|[-P [-e]] [-@]] [dir]
 Usage: used for listing directory contents
 Commands Used:
 cd .. -> get back to cc directory
 cd ../.. -> move to upper directory
 cd ~ -> move to home directory
Output:
1.3. Command Name: mkdir
You can create folders using mkdir command.
 Syntax: mkdir [option] DIRECTORY
 Usage: used for making directory
 Commands Used:
 mkdir -v -> creates directory and prints message for it
 mkdir –p -> creates directories including parent directories in a
specified path.
Output:

1.4. Command Name: rmdir


This command is designed to remove directories only if they are empty.
 Syntax: rmdir [option] DIRECTORY
 Usage: used for removing empty directory
 Commands Used:
 rmdir -v -> removes directory and prints message for it
 rmdir –p ->
Output:

1.5. Command Name: rm


This command removes the specified file from the file system.
 Syntax: rm [option] [file]
 Usage: used for removing files and directories
 Commands Used:
 rm –ri -> removes directory and files contained and prompts before
every removal
 rm –v -> removes folders and explains what is being done
Output:

1.6. Command Name: grep


Syntax: grep [option] patterns [file]

Usage: used for searching patterns in each file

Commands Used:
➢ Grep Nepal Nepal.txt -> prints the whole line of matched term “Nepal” from
the Nepal.txt file.
➢ grep -o -> prints only matched term
➢ grep -n -> prints matched content with line number
Output:

1.7. 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 (prastab)
➢ whoami => prints current user name associated with current
effective user ID
➢ sudo whoami => prints root user
➢ sudo apt-get update => resynchronizes the package index files fromtheir
sources
➢ sudo -l => list user privilege or check a specific command
Output:

1.8. 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.9. 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.10. 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
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 poem -> adds read,write and execute permissionto poem
➢ chmod -rwx poem -> removes read,write and execute
permission from poem
➢ chmod +x poem -> adds executable permission to poem file
Output:

1.12. Command Name: chown

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

Usage: used for changing the user and group ownership of file
Commands Used:
➢ chown mark Music/ -> changes ownership of Music folder to
mark.
➢ chown -v root story -> changes ownership to root and prints
diagnostics for it

Output:
1.13. Command Name: clear

Syntax: clear

Usage: used for clearing the terminal screen

Commands Used:
➢ clear -> cleans terminal screen
Output:
1.14. Command Name: passwd

Syntax: passwd [option] [login]

Usage: usef for changing the user password

Commands Used:
➢ passwd => change current user’s password
➢ sudo passwd Maharjan => change Maharjan’s password
➢ sudo passwd -d Maharjan => delete user’s password
➢ sudo passwd -e Maharjan=> immediately expires an
account’spassword
➢ sudo passwd -q => quiet mode
➢ sudo passwd -u => unlocks the password of the named
account
Output:

1.15. Comma
ndName
:Useradd
Syntax: useradd [options]

Usage: used for creating new users

Commands Used:
➢ useradd wizard -> creates a new user with the name khonshu
➢ useradd -m mark -> creates the user’s home directory
➢ useradd Life -c “Life is beautiful” -> adds short description of login

Output:

1.16. Command Name: userdel

Syntax: userdel [options]

Usage: used for removing user

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
retrievedpackage files
➢ apt-get autoremove -> removes packages that were automatically
installed to satisfy dependencies for other packages and are now
no longer needed

Output:
1.17. Command Name: apt-get
Syntax: apt-get [options]
Usage: used for handling packages
Commands Used:
 apt-get update -> resynchronizes the package index files from theirsources
 apt-get upgrade -y -> install the newest versions of all packagescurrently
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 retrievedpackage files
 apt-get autoremove -> removes packages that were automaticallyinstalled to
satisfy dependencies for other packages and are now no longer needed

Output:
1.18. 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.19. 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.20. 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 archive.tar -> creates a tar file called `archive.tar` which is the Archive of all
.html files in current directory
 tar xf archive.tar -> extracts files from Archives and make a copy of the existed file
 tar tf archive.tar -> shows all the files and folder present in the folder
Output:
1.21. Command Name: gzip
Syntax: gzip [Options] [filenames]
Usage: used for compressing files

Commands Used:
 gzip -k journel.txt -> creates compressed file of journel.txt named as journel.txt.gz
and also keeps the original file
 gzip -d journel.txt.gz -> decompress a file
 gzip -vd journel.txt.gz -> displays the name and percentage reduction for each file
decompressed

Output:
1.22. Command Name: kill

Syntax: kill [option] <pid>

Usage: used for sending a signal to a process

Commands Used:
 kill -l -> lists signal name
 kill 13986 -> process receives a kill signal

Output:

1.23. 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:
 ps aux | grep gedit ->
 kill 4947 -> kills processes for 4947
 pkill -e chromium-browse -> displays name and PID of the process being killed
(chromium-browse)
Output:

1.24. 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 pageswith
the section number in which it is found
➢ man -w pkill -> returns the location in which the manual
pageof a pkill command is present
Output:

1.25. Command Name: cp


Syntax: cp [option] source destination
Usage: used for copying files and directories
Commands Used:
➢ cp grepfilter.txt haa.txt -> copies contents of grepfilter.txt to haa.txt

➢ cp -r src web/ -> recursively copies src directory to web directory

You might also like