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

2 - Familiarisation of Linux Commands

The document provides descriptions of 25 common Linux commands: 1. man - displays manual pages for commands to view usage and help documentation. 2. who - shows who is logged into the system. 3. cat - concatenates and displays file contents. 4. cd - changes the current working directory. 5. cp - copies files and directories. 6. ps - displays currently running processes.

Uploaded by

Dilna Sebastian
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)
143 views

2 - Familiarisation of Linux Commands

The document provides descriptions of 25 common Linux commands: 1. man - displays manual pages for commands to view usage and help documentation. 2. who - shows who is logged into the system. 3. cat - concatenates and displays file contents. 4. cd - changes the current working directory. 5. cp - copies files and directories. 6. ps - displays currently running processes.

Uploaded by

Dilna Sebastian
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/ 6

Linux Internals

Familiarisation of Linux Commands


Experiment: 01
Date: 04-05-2021

PROBLEM DEFINITION
Study of Unix/Linux general purpose utility command list obtained from (man, who, cat, cd, cp, ps,
ls, mv, rm, mkdir, rmdir, echo, more, date, time, kill, history, chmod, chown, finger, pwd, cal,
logout, shutdown, grep, mount)commands.

Basic linux commands


1. man - an interface to the on-line reference manuals
man is the system's manual pager. Each page argument given to man is normally the
name of a program, utility or function. The manual page associated with each of these
arguments is then found and displayed. man command in Linux is used to display the user
manual of any command that we can run on the terminal. It provides a detailed view of the
command which includes NAME, SYNOPSIS, DESCRIPTION, OPTIONS, EXIT
STATUS, RETURN VALUES, ERRORS, FILES, VERSIONS, EXAMPLES, AUTHORS,
etc.

2. who - show who is logged on


Print information about users who are currently logged in.
-a, --all
same as -b -d --login -p -r -t -T -u
-b, --boot
time of last system boot
-d, --dead
print dead processes

3. cat - concatenate files and print on the standard output


cat file1 #lists file 1 to screen
cat file1 file2 > outfile #adds contents of both file into outfile
cat *.txt > outfile #add all txt files to outfile

-A, --show-all
equivalent to -vET
-b, --number-nonblank
number nonempty output lines, overrides -n
-e equivalent to -vE
-E, --show-ends
display $ at end of each line
-n, --number
number all output lines

4. cd -
The cd (“change directory”) command is used to change the current working directory in
Linux and other Unix-like operating systems.The current working directory is the directory
(folder) in which the user is currently working in. Each time you interact with your
command prompt, you are working within a directory.

cd [OPTIONS] directory
The command accepts only two options that are rarely used.
−L, Follow symbolic links . By default, cd behaves as if -L option is specified.
−P, Don’t follow symbolic links. In other words, when this option is specified, and you try to
navigate to a symlink that points to a directory, cd will change into the directory.

cd .. - to change the current working directory to previous folder to the CWD


cd - # go to last directory you were in

5. cp - copy files and directories


Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
cp file1 file2 # copy file1 to file2

cp file1 directory # copy file1 into directory

cp file1 file2 file3 ... directory # copy files into directory

cp -R dir1 dir2/ # copy dir1 into dir2 including subdirectries

cp -pR dir1 dir2/ # copy directory, preserving permissions

6. ps - report a snapshot of the current processes


ps command is used to list the currently running processes and their PIDs along with some
other information depends on different options. It reads the process information from the
virtual files in /proc file-system. /proc contains virtual files, this is the reason it's referred as
a virtual file system.

7. ls - list directory contents


The ls command - the list command - functions in the Linux terminal to show all of the
major directories filed under a given file system.

For example, the command:

ls /applications
will show the user all of the folders stored in the overall applications folder. The lscommand
is used for viewing files, folders and directories.

8. mv - move (rename) files


mv stands for move. mv is used to move one or more files or directories
from one place to another in a file system like UNIX. It has two distinct
functions:
(i) It renames a file or folder.
(ii) It moves a group of files to a different directory.

9. rm - remove files or directories


This manual page documents the GNU version of rm. rm removes each specified file.
By default, it does not remove directories.the rm command will remove both files and
directories with files in it. This said, the rm command carries more weight than the rmdir
command and should be used with more specificity.
Eg. rm file1.text

10. mkdir - make directories


Create the DIRECTORY(ies), if they do not already exist. Just like making a new directory
within a PC or Mac desktop environment, the mkdir command makes new directories in a
Linux environment.

Eg. mkdir Lab_2

11. rmdir - remove empty directories


The rmdir - remove directory - command allows the user to remove an existing command
using the Linux CLI.

Eg. rmdir testdirectory

12. echo - display a line of text


echo command in linux is used to display line of text/string that are passed as an argument .
This is a built in command that is mostly used in shell scripts and batch files to output status
text to the screen or a file.

Eg. echo hello

13. more - file perusal filter for crt viewing


more is a filter for paging through text one screenful at a time.
More command is used to view the text files in the command prompt,
displaying one screen at a time in case the file is large (For example log
files). The more command also allows the user do scroll up and down
through the page. The syntax along with options and command is as
follows.

14. date - print system date and time


$ date
Sat May 8 00:21:33 IST 2021

15. time - run programs and summarize system resource usage


The time command is used to determine how long a given command
takes to run. It is useful for testing the performance of your scripts and
commands.
16. kill - send a signal to a process
kill command in Linux (located in /bin/kill), is a built-in command which is
used to terminate processes manually. kill command sends a signal to a
process which terminates the process. If the user doesn’t specify any
signal which is to be sent along with kill command then default TERM
signal is sent that terminates the process.

kill {-signal | -s signal} pid

17. history - GNU History Library


Many programs read input from the user a line at a time. The GNU
History library is able to keep track of those lines, associate arbitrary
data with each line, and utilize information from previous lines in
composing new ones.

18. chmod - change file mode bits


chmod changes the file mode bits of each given file according to mode,
which can be either a symbolic representation of changes to make, or
an octal number representing the bit pattern for the new mode bits.

To view the permissions we use:


ls -l

chmod [reference][operator][mode] file...

Eg. chmod 777 file1

Reference Class Description


u owner file's owner
g group users who are members of the file's
group
o others users who are neither the file's
owner nor members of the file's group
a all All three of the above, same as ugo

19. chown - change file owner and group


chown changes the user and/or group ownership of each given file. If only
an owner (a user name or numeric user ID) is given, that user is made
the owner of each given file, and the files' group is not changed. If the
owner is followed by a colon and a group name (or numeric group ID),
with no spaces between them, the group ownership of the files is
changed as well.

20. Finger command is a user information lookup command which gives details of all
the users logged in. This tool is generally used by system administrators. It provides
details like login name, user name, idle time, login time, and in some cases their
email address even.
21. pwd - print name of current/working directory
Print the full filename of the current working directory.
-L, --logical
use PWD from environment, even if it contains symlinks
-P, --physical
avoid all symlinks

22. cal, ncal — displays a calendar and the date of Easter


The cal utility displays a simple calendar in traditional format and ncal offers an
alternative layout, more options and the date of Easter. The new format is a little
cramped but it makes a year fit on a 25x80 terminal. If arguments are not specified,
the current month is displayed.

23. login, logout - write utmp and wtmp entries


The utmp file records who is currently using the system. The wtmp file records all
logins and logouts.
The function login() takes the supplied struct utmp, ut, and writes it to both the
utmp and the wtmp file.

The function logout() clears the entry in the utmp file again.

24. shutdown - Halt, power-off or reboot the machine


shutdown may be used to halt, power-off or reboot the machine. The first argument
may be a time string (which is usually "now"). Optionally, this may be followed by a
wall message to be sent to all logged-in users before going down.

The following options are understood:


--help
Print a short help text and exit.
-H, --halt
Halt the machine.
-P, --poweroff
Power-off the machine (the default).
-r, --reboot
Reboot the machine.

25. grep, egrep, fgrep, rgrep - print lines matching a pattern


grep searches for PATTERN in each FILE. A FILE of “-” stands for standard
input. If no FILE is given, recursive searches examine the working directory, and
nonrecursive searches read standard input. By default, grep prints the matching
lines.

In addition, the variant programs egrep, fgrep and rgrep are the same as grep -E,
grep -F, and grep -r, respectively. These variants are deprecated, but are provided
for backward compatibility.
Options Description
-c : This prints only a count of the lines that match a
pattern
-h : Display the matched lines, but do not display the
filenames.
-i : Ignores, case for matching
-l : Displays list of a filenames only.
-n : Display the matched lines and their line numbers.
-v : This prints out all the lines that do not matches the
pattern
-e exp : Specifies expression with this option. Can use
multiple times.
-f file : Takes patterns from file, one per line.
-E : Treats pattern as an extended regular expression (ERE)
-w : Match whole word
-o : Print only the matched parts of a matching line,
with each such part on a separate output line.
-A n : Prints searched line and nlines after the result.
-B n : Prints searched line and n line before the result.
-C n : Prints searched line and n lines after before the
result.
$grep -i "UNix" geekfile.txt
The -i option enables to search for a string case
insensitively in the give file. It matches the words like
“UNIX”, “Unix”, “unix”.

26. mount - mount a filesystem


All files accessible in a Unix system are arranged in one big tree, the file hierarchy, rooted
at /. These files can be spread out over several devices. The mount command serves to
attach the filesystem found on some device to the big file tree. Conversely, the umount(8)
command will detach it again. The filesystem is used to control how data is stored on the
device or provided in a virtual way by network or another services.

The standard form of the mount command is:


mount -t type device dir

Conclusion
Study of various Unix/Linux general purpose utility command has been done and exapmples of the
same commands are used successfully.

You might also like