Important Linux/Unix
Commands
Unix is now one of the most commonly used Operating systems used
for various purposes such as Personal use, Servers, Smartphones, and
many more. It was developed in the 1970’s at AT& T Labs by two
famous personalities Dennis M. Ritchie and Ken Thompson.
• The most popular programming language C came into existence to
write the Unix Operating System.
•
• Linux is Unix-Like operating system.
• The most important part of the Linux is Linux Kernel which was
first released in early 90’s by Linus Torvalds.There are several
Linux distros available (most are open-source and free to download
and use) such as Ubuntu, Debian, Fedora, Kali, Mint, Gentoo, Arch
and much more.
• Now coming to the Basic and most usable commands of
Linux/Unix part. (Please note that all the linux/unix commands are
run in the terminal of a linux system.Terminal is like command
prompt as that of in Windows OS)
• Linux/Unix commands are case-sensitive i.e Hello is different
from hello.
Basic unix commands:
1. who : The ‘$ who’ command displays all the users who have
logged into the system currently.As shown above on my system I am
the only user currently logged in.The thing tty2 is terminal line the
user is using and the next line gives the current date and time
$ who
Output: harssh tty2 2017-07-18 09:32 (:0)
2. pwd : The ‘$pwd’ command stands for ‘print working directory’
and as the name says,it displays the directory in which we are
currently (directory is same as folder for Windows OS users).
In the output we are harssh directory(folder for Windows OS that are
moving to Linux),which is present inside the home directory
$ pwd
Output: /home/harssh
3. mkdir : The ‘$ mkdir’ stands for ‘make directory’ and it creates a
new directory.We have used ‘$ cd’ (which is discussed below) to get
into the newly created directory and again on giving ‘$ pwd’
command,we are displayed with the new ‘newfolder’ directory.
$ mkdir newfolder
$ cd newfolder
$ pwd
Output: /home/harssh/newfolder
4. rmdir : The ‘$ rmdir’ command deletes any directory we want to
delete and you can remember it by its names ‘rmdir’ which stands for
‘remove directory’.
$ rmdir newfolder
5. cd : The ‘$ cd’ command stands for ‘change directory’ and it
changes your current directory to the ‘newfolder’ directory.You can
understand this a double-clicking a folder and then you do some stuff
in that folder.
$ cd newfolder (assuming that there is a
directory named 'newfolder' on your system)
6. ls : The ‘ls’ command simply displays the contents of a
directory.
$ ls
Output: Desktop Documents Downloads Music
Pictures Public Scratch Templates Videos
7. touch : The ‘$ touch’ command creates a file(not directory) and
you can simple add an extension such as .txt after it to make it a Text
File.
$ touch example
$ ls
Output: Desktop Documents Downloads Music
Pictures Public Scratch Templates Videos
example
Note: It is important to note that according to the Unix File structure,
Unix treats all the stuff it has as a ‘file’, even the directories(folders)
are also treated as a file.You will get to know more about this as you
will further use Linux/Unix based OS
8. cp : This ‘$ cp ‘ command stands for ‘copy’ and it simply
copy/paste the file wherever you want to.In the above example, we
are copying a file ‘file.txt’ from the directory harssh to a new
directory new.
$ cp /home/harssh/file.txt /home/harssh/new/
9. mv : The ‘$ mv’ command stands for ‘move’ and it simply move a
file from a directory to anothe directory.In the above example a file
named ‘file.txt’ is being moved into a new directory ‘new’
$ mv /home/harssh/file.txt /home/harssh/new
10. rm : The ‘$ rm ‘ command for remove and the ‘-r’ simply
recursively deletes file. Try ‘$ rm filename.txt’ at your terminal
$ rm file.txt
11. chmod : The ‘$ chmod’ command stands for change mode
command.As there are many modes in Unix that can be used to
manipulate files in the Unix environment.Basically there are 3 modes
that we can use with the ‘chmod’ command
1. +w (stands for write and it changes file permissions to write)
2. +r (stands for read and it changes file permissions to read)
3. +x (generally it is used to make a file executable)
$ chmod +w file.txt
$ chmod +r file.txt
$ chmod +x file.txt
12. cal : The ‘$ cal’ means calendar and it simply display calendar on
to your screen.
$ cal
Output : July 2017
Su Mo Tu We Th Fr Sa
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
13. file : The ‘$ file’ command displays the type of file.As I
mentioned earlier Linux treats everything as a file so on executing the
command file on a directory(Downloads) it displays directory as the
output
$ ls
Output: Desktop Documents Downloads Music
Pictures Public Scratch Templates Videos
$ file Downloads
Output: Downloads: directory
14. sort : As the name suggests the ‘$ sort’ sorts the contents of the
file according to the ASCII rules.
$ sort file
15. grep : grep is an acronym for ‘globally search a regular
expression and print it’.The ‘$ grep’ command searches the specified
input fully(globally) for a match with the supplied pattern and
displays it.
In the example, this would search for the word ‘picture’ in the file
newsfile and if found,the lines containing it would be displayed on the
screen.
$ grep picture newsfile
16. man : The ‘$ man’ command stands for ‘manual’ and it can
display the in-built manual for most of the commands that we ever
need.In the above example, we can read about the ‘$ pwd’ command.
$ man pwd
17. lpr : The ‘$ lpr’ command send a file to the printer for printing.
$ lpr new.txt
18. passwd : The ‘$ passwd’ command simply changes the password
of the user.In above case ‘harssh’ is the user.
$ passwd
Output: Changing password for harssh.
(current) UNIX password:
19. clear : The ‘$ clear’ command is used to clean up the terminal so
that you can type with more accuracy
$ clear
Q 1 - What is the option to create hard link for a directory?
A - –s
B - –l
C - –f
D - None of the above.
Answer : D
Explanation
It is error to create a hard link for a directory.
Hide Answer
Q 2 - Which of the following is correct to create an alias name for 'ls' as 'list'?
A - alias list=”ls”
B - alias list “ls”
C - alias “list” as “ls”
D - alias “ls” as “list”
Answer : A
Explanation
Syntax is alias alias-name=”command”.
Hide Answer
Q 3 - Choose the option to remove write permission for group & others for a file
“a.txt”.
A - Select disable write for group and others where file=”a.txt”
B - chmod go-w a.txt
C - chmod w-go a.txt
D - chmod go=”r-x” a.txt
Answer : B
Explanation
Hide Answer
Q 4 - Which option can be used with ‘rm’ command to prompt for file removal?
A - –ask
B - –i
C - -c
D - -n
Answer : B
Explanation
By default ‘rm’ is non interactive. –i means as interactive.
Hide Answer
Q 5 - Choose the correct usage of ‘cd’ to move into parent directory.
A - cd
B - cd..
C - cd/
D - None of the above
Answer : D
Explanation
cd ..(space between cd and ..) is correct instead of cd..
Hide Answer
Q 6 - Which command can be used to create links for file/directory?
A - lk
B - ln
C - new
D - makelink
Answer : B
Explanation
ln is the command used to create hard/soft link for a file and hard link for a directory.
Hide Answer
Q 7 - Display the ‘file’ contents page wise
A - cat file|tail
B - cat file|head
C - cat file|more
D - None of the above.
Answer : C
Explanation
‘more’ holds the scrolling page wise. Hit space bar to continue reading to next page.
Hit ‘q’ to quit from ‘more’.
Hide Answer
Q 8 - Which command is used to get intermediate result in a pipeline of commands?
A - tee
B - tea
C - get
D - filter
Answer : A
Explanation
Hide Answer
Q 9 - Solaris is ___
A - HP’s UNIX
B - IBM’s UNIX
C - Sun microsystems UNIX
D - Microsoft’s UNIX
Answer : C
Explanation
Oracle Corporation took over Sun microsystems
Show Answer
Q 10 - Job number and PID are same.
A - True
B - False
Answer : B
Explanation
PID is given by OS, whereas Job number is the utility program which initiates
process.
1. The dmesg command
a) Shows user login logoff attempts
b) Shows the syslog file for info messages
c) kernel log messages
d) Shows the daemon log messages
View Answer
Answer: c
Explanation: None.
2. The command “mknod myfifo b 4 16”
a) Will create a block device if user is root
b) Will create a block device for all users
c) Will create a FIFO if user is not root
d) None of the mentioned
View Answer
Answer: a
Explanation: None.
3. Which command is used to set terminal IO characteristic?
a) tty
b) ctty
c) ptty
d) stty
View Answer
Answer: d
Explanation: None.
advertisement
4. Which command is used to record a user login session in a file
a) macro
b) read
c) script
d) none of the mentioned
View Answer
Answer: c
Explanation: None.
5. Which command is used to display the operating system name
a) os
b) unix
c) kernel
d) uname
View Answer
Answer: d
Explanation: None.
6. Which command is used to display the unix version
a) uname -r
b) uname -n
c) uname -t
d) kernel
View Answer
Answer: a
Explanation: None.
7. Which command is used to print a file
a) print
b) ptr
c) lpr
d) none of the mentioned
View Answer
Answer: c
Explanation: None.
8. Using which command you find resource limits to the session?
a) rlimit
b) ulimit
c) setrlimit
d) getrlimit
View Answer
Answer: b
Explanation: None.
9. Which option of ls command used to view file inode number
a) –l
b) -o
c) –a
d) –i
View Answer
Answer: d
Explanation: None.
10. Find / -name ‘*’ will
a) List all files and directories recursively starting from /
b) List a file named * in /
c) List all files in / directory
d) List all files and directories in / directory
View Answer
Answer: a