Basic Linux Command

You might also like

Download as pdf
Download as pdf
You are on page 1of 9
Basic Linux "| RPM- a) stands for Red Hat Package Manager b) is used to install, uninstall, and manage packages c) is used to keep track of the users d) assigns a dynamic IP address Ans: a 6. Which of the following is not a part of default Red Hat Linux email system? a) Pine b) The MTA c) The MUA d) procmail A Pine is a freeware, text-based email client which was developed at the University of ton. Source code was available for only the Unix version. Pine is no longer under development, and has been replaced by the Alpine client, which is available under the Apache License. ra Note Some important Linux Commands ‘pwd’ Command: Linux pwd (print working directory) command displays location currently working on. It will give the whole path starting from the root ending to the directory. = pwd ‘ed' Command: Linux cd command is used to change the current working directory (i.e., in which the current user is working). The "cd" stands for ‘change directory.’ It is one of the most frequently used commands in the Linux terminal. ~ cdkdirnamed| © Tochange our current working directory, execute the command as follows: ~cdkcurrent directory>] Kspecified directory>| * To change the directory to home directory from the current working directory, execute the command as follows: sed~ * To change to the previous directory from the current working directory, execute the command as follows: > cd- © To change the directory to parent directory of the current working directory, execute the command as follows: > ed. © To navigate directory to entire system's root directory from current working directory, execute the command as follows: + cd/ © We can change the directory from the current working directory to a user's home directory by executing the command as follows: ced Fusernam © Tochange the directory that has spaces in its name, surround the path with quotes ('") or use the backslash (\) character with it, Execute the command as follows: ed |'Dir name with space' ed [Dir\ name\ with\ space] COMPACT IT Preliminary Page | 603 Basic Linux © We can change directory up to multiple sub-directories by separating directories by a forward slash ()) as follows: ed [Dirl/Dir2/Dir3 ‘ ‘Is' command: The Is is the list command in Linux. Just type Is and press the enter key. The whole content will be shown. 1s Is option Description Tn Linux, hidden files start with . (dot) symbol and they are not visible in the 1s -a | regular directory. The (Is -a) command will enlist the whole list of the current directory including the hidden files. Is -1 _ | Iwill show the list in a long list format, 1s -1i_| This command prints the index number if file is in the first column. Tis used to identify the directory easily by marking the directories with a slash (/) line sign. Is =r _| Itis used to print the list in reverse order. Is -R_ | Iwill display the content of the sub-directories also. Is -1x_| It will group the files with same extensions together in the list. 1s -p ‘mkdir command: The mkdir stands for ‘make directory’. Just type "mkdir , in place of type the name of new directory, I want to create and then press enter. + medi edi enanes ‘rmdir’ Command: This command is used to delete a directory. But will not be able to delete a directory including a sub-directory. It means, a directory has to be empty to be deleted. > mdi rkdirname>| ‘my! command: The ‘mv’ command is a multi-purpose command, It is not just limited to move files and directories, but it can also be used for renaming the files and directories. ~ mv Pld foldex| New foldex| ‘touch’ Command: The touch command is used to create empty files. We can create multiple empty files by executing it once. ~ touch Kfile name>] touch kfilel> ...4 ‘eat’ Command: The cat command is a multi-purpose utility in the Linux system. It can be used to create a file, display content of the file, copy the content of one file to another file and more. — cat [[OPTION]... [FILE]. © Tocreate a file, execute it as follows: ~cat> {file name: © Press "CTRL+ D" keys to save the file. To display the content of the file, execute it as follows: cat COMPACT IT Preliminary Page | 604 Basic Linux ‘ep’ Command: The cp command is used to copy a file or directory. To copy in the same directory: cp Kexisting file name> Knew file name>} ‘rename! Command: The rename command is used to rename files. It is useful for renaming a large group of files. — rename ['s/old-name/new-name/' files| ‘head' Command: The head command is used to display the content of a file. It displays the first 10 lines of a file. head kfile name>] ‘tail’ Command: The tail command is similar to the head command. The difference between both commands is that it displays the last ten lines of the file content, It is useful for reading the error message. tail Kfile name> ‘tac’ Command: The tac command is the reverse of cat command, as its name specified. It displays the file content in reverse order (from the last line). tac Kfile name>] ‘passwd’ Command: The passwd command is used to create and change the password for a user. ~ passwd Kusername’ ‘cat' Command: The cat command is also used as a filter. To filter a file, it is used inside pipes. ~ cat KfileName>] | cat or tac | cat or tac | ‘cut' Command: The cut command is used to select a specific column of a file. The ‘-d’ option is used as a delimiter, and it can be a space (‘'), a slash (/), a hyphen (-), or anything else. And, the '-P option is used to specify a column number. cut -d(delimiter)] -f[(columnNumber)] kfileName: ‘te' Command: The tr command is used to translate the file content like from lower case to upper case, + command|tr K'old'> <'new'>| ‘we! Command: The we command is used to count the lines, words and characters in a file. we {file name>| ‘gzip| Command: The gzip command is used to truncate the file size. It is a compressing tool. It replaces the original file by the compressed file having ‘ga’ extension. gzip kkfilel> ... ‘zeat' Command: The zcat command is used to display the compressed files. ~zeat kfile name: ‘ip! Command: Linux ip command is an updated version of the ipconfig command. It is used to assign an IP address, initialize an interface, disable an interface. ip a or ip addr COMPACT IT Preliminary Page | 605 Basic Linux ‘sh’ Command: Linux ssh command is used to create a remote connection through the ssh protocol. ssh [user name@host (IP/Domain name)]

‘ping’ Command: The ping command is used to check the connectivity between two nodes, that is whether the server is connected. It is a short form of “Packet Internet Groper." ping Kdestination>] host Command: The host command is used to display the IP address for a given domain name and vice versa. It performs the DNS lookups for the DNS Query. host Kdomain name> or ] Y useradd: create new user account Vv usexdel: delete user account Y dé: show disk space usage Y find: search for files in a directory hierarchy (find file! txt) Y echo: display a line of text Y scp: secure copy (remote file copy program) Y reboot: reboot the system (Usage: reboot [OPTION]) Y powerof¢: power off the system (poweroff [OPTION]) Y ps: display your currently active processes Y top: display all running processes Y chmod: change the permissions of file Y¥ cal: The cal command print a calendar on the standard output. Y cksum README. txt]: cksum command is used to display the CRC checksum and byte count of an input file. ¥ cmp [Eilel £i1e2| cmp performs a byte-by-byte comparison of two files. v df —h: dfcommand is used to show file system disk space usage as follows. Y env: env command lists all the current environment variables and used to set them as well. Y ipconfig: © $ ifconfig © §$ sudo ifconfig ethO up © §$ sudo ifconfig eth0 down © § sudo ifconfig ethO [172.16.25.125| ifconfig command is used to configure a Linux systems network interfaces. It is used to configure, view and control network interfaces. Key Board Shortcuts © Ctrl+C- halts the current command COMPACT IT Preliminary Page | 606 Basic Linux + Cirl+Z- stops the current command, resume with fg in the foreground or bg in the background © Ctrl+D- log out of current session, similar to exit © Ctrl+W- erases one word in the current line © Cul+U- erases the whole line © Ctrl#R- type to bring up a recent command © Exit~log out of current sessi < > 1. Assume that you want to improve database performance and willing to see the amount of swap space. Which command you can use in LINUX OS environment? (S81, J8ADB 2021) a) Lsps—a b) Swapinfo -m ¢) Swapon -s d) Swap -1 and Swap -s Ans: € 2. Which UNIX/Linux command is used to make all files and sub-directories in the directory “progs” executable by all users? Combined Bank, SO (IT) 2021} (a) chmod -R a#x progs (b) chmod -R 222 progs (c) chmod -X a+x progs (d) chmod -X 222 progs Ans: a 3. Which of the following Linux command has incorrect syntax? (Combined Bank, SO (17) 2021) (a) cat sample.txt | grep =v a | sort =r (b) chown:group3 File | (c) chmodatrx viewer.sh (d) None of the above Ans: b 4, In UNIX, the login prompt can be changed by changing the content of the file- /s#z. JBL O(ITACT) 2019} A) gettydefs B) contrab C) initab D) init Ans: A 5. What command is used to remove files UNIX? /8R£8 AJE 2019) A)dm B)rm C) delete D) erase Ans: B 6. Which of the following UNIX commands allows scheduling a program to be executed at specifies time? (S81, JBL O(/T/ICT) 2019) A) nice B) cron C) date and time D) schedule Ans: B Cricec@ >> 1. What command is used to remove the directory? a) rdir b) remove c) rd d) rmdir Ans: d 2, What command do you use to create Linux file systems? a) fdisk b) mkfs c) fsck d) mount Ans: b 3. What command is not used to list the files chap01, chap02 and chap04? a) 1s chap* b) 1s chap[124) c) ls - x chap0[124] d) ls chap0[124} Ans: b 4, What command is used with vi editor to save file and remain in the editing mode? a) x bq! ©) sw dq Ans: ¢ COMPACT IT Preliminary Page | 607 Basic Linux 5. What command is used with vi editor to move back to the beginning of a word? aw be oa db Ans: d 6. What command is used with vi editor to search a pattern in the forward direction? a) 2? by // o? a/ Ans: d 7. What command is used to add printing jobs to the queue? a) Ipd b) Ipr. c) Ipg d) Ipe Ans: b 8 What command is used to copy directory structures in and out? a) copy b)ep - p c)cpio dcp Ans: 9. What command is used to remove jobs from the print queue? a) Ipq b) Ipr ©) Iprm d) pe Ans: ¢ 10. How can you navigate around virtual consoles? a) Alt+Funetion Key b) Cirl+Function Key ©) Curl+AltsDel d) Alt+a+w+Function Key Ans: a \) \ Model Test 1. What hardware architectures are not supported by Red-Hat? a) SPARC b) IBM-compatible c) Alpha d) Macintosh, 2. Which of the following command is used to create a Linux installation hoot floppy? a) mkboot disk b) boot fp disk ¢) wwand rawwrite d) dd and rewrite 3. How can you add Amit, a new user, to your system? a) Using useradd b) Using adduser c) Using linuxconf d) All of the above 4. Which of the following command is used to see the services running in NFS server? a) rpcinfo b) serverinfo ©) NFSinfo d) infserv 5. In which tep_wrappers file can you specify to allow all connections from all hosts? a) /etc/hosts.allow b) /etc/hosts.deny ¢) fetcfhosts d) fete/tep.cont 6. What command is used to list contents of directories? a) tar b) dir c) Ip d) Is 7. Which prograr on the system? is used to schedule particular jobs or programs at particular times a) vi b) Outlook c) Scheduler d) cron 8. Which command can force all buffers to disk? a) save b) sync c) edbuff d) flush COMPACT IT Preliminary Page | 608 Basic Linux 9. What command is used to sort the lines of data in a file in ‘alphabetical order? a)sort - 5 b) st c) sh d) sort 10. What is the maximum size of a file allowed in Linux with the following data Block Size = 4KB, inode data pointer size = 4 byte? (a) 1 TB (b) Less than 4TB (c) 2TB+2GB+2MB+64KB (d) More than 4 TB Model Test Answer: 1 2 (13 |4 |5 |6 {7 |8 {9 |10 d a a_|d {d |b |d [b Website Based Practice MCQ 1. What command is used to count the total number of lines, words and characters contained in a file? a) countw b) weount cc) we d) count p Ans: ¢ Note: The command t to count the je sically means “word count” and with different optional parameters one iber of lines, words, and characters in a text file. used to remove files? a) dm b) rm c) delete d)erase e Ans: b Note: Use the rm command to remove files you no longer need. The rm command removes the entries for a specified file, group of files, or certain Select files froma list within a directory, 3. What file specifies the order in which to use specified name services? a) letc/services b) fete/nsorder ¢) fete/nsswiteh.cont d) fetchhosts Ans: € 4, How many primary partitions can exist on one drive? a) 16 by 2 at Ans: b 5. In which directory can you store system user default files used for creating user directories? a) /ust/tmp b) /ete/default c)/etciskel —_d) /etclusers Ans: ¢ Note: The /etc/skel directory contains files and directories that are automatically copied over to a new user's home directory when such user is created. 6. Which of the following is a valid format for mounting a CD-ROM drive? a) mount -t is09660 /dev/cdrom / mnt/cdrom 'b) mount /dev/edrom ¢) mount /mnt/edrom d) All of the above 7. Which of the following command can you execute to count the number of line: a) le b) we-1 ce) cl d) count ‘cis used for word count which will result all the details like number of words line numbers specifies that we only want the ine count COMPACT IT Preliminary Page | 609 Basic Linux 8. Which of the following is not a communication command? a) grep b) mail ce) mesg — sd) write Ans: a Note: The "grep ' command i 9. What command is used to display the characteristics of a process? a) au b) ps c) du d) pid Ans: b Note: “ps’ command is used to find the current process running in the system. 10, What command is used with vi editor to replace text from cursor to right used for pattern searching, not for communication. aS b)s c)R dr Ans:¢ 11, What sign is used to back up over typing errors in vi? a)! b)s o# o@ Ans: e 12. What sign is used to erase or kill an entire line you have typed and start you are on a new line (but not display a new prompt)? a)! bs o# ae Ans: d 13. Which of the following command is used to access an SMB share on a Linux system? a)NFS_—_b) SMD c) smbclient 4) smbserver Ans: ¢ Note: smbclient is samba client with an "ftp like” interface. It is a useful tool to test connectivity to a Windows share. It can be used to transfer files, or to look at share names. In addition, it has a nifty ability to ‘tar' (backup) and restore files from a server to a client and vice versa. 14, What project is currently developing X server support? a) XFree86 Project, Inc b) RHAD Labs c) GNOME Project d) All of the above Ans: a 15, What X-based tool is available for configuring the X Window system? a) XConfigurator b) XFR86Setup c) xf86config d) All of the above Ans: b 16. What port does squid listen, by default? a) 4322 b) 2314 ©) 7334 4) 3128 Ans: d Note: Squid is a caching and forwarding web proxy. It is most often used in conjunction with a nal LAMP stack (Linux, Apache, MySQL, PHP). 17. Which of the following is the main Apache configuration file? a) /etc/apache)conf b) /etc/httpd/config. ini ¢) /etc/httpd/conf/httpd.conf d) confd./ete/srm.conf Ans: ¢ 18. Which of the following server is used with the BIND package? a) httpd b) shutp, c) dns. d) named Ans: d Note: BIND (Berkeley Internet name domain) package is to provide DNS service and the ‘named’ is a daemon service of it. 19. What command is used with vi editor to append text at end of line? a) bi ca QA Ans: d COMPACT IT Preliminary Page | 610 Basic Linux 20. What command is used to save the standard output in a file, as well as display it on the terminal? a) tee b) grep ©) cat a) more Ans: a 21. What command is used to count just the number of lines contained in a file? a) wo-r b) we-w ©) we-c d) we-1 Ans: d 22. What type of addressing format is used by Class A network. a) Net.Net.Net.Node b) Net.Net.Node.Node c) Net.Node.Net.Node d) Net.Node.Node.Node Ans: d 23. What command is used to query for a specific package with RPM? a) rpm -q b) rpm -a ©) rpm -d d) rpm -1 Ansa Note: RPM has a powerful query feature that allows you to find out what packages are installed on your system, the files associated with a package, or the package that owns a particular file. Use the -q flag to tell RPM to display the package name, version number, and release number of a package. 24, What script is run for setting bash global defaults for all users? a) etch profile _b) /ete/-bashre e)letellog —_d) /etelprofile Ans: d 25, ___ tool allows you to change your default X Window desktop. a) utilinux b)cempre —_¢) switehdesk 4) window Ans: 26. How many extended partitions can exist on one drive? a) 16 bya 22 al Ans: d Note: There can be 3 primary partitions and 1 extended primary partition on a single hard disk. 27. For you to create a swap partition by using fdisk, what must the partition's system ID type be? a) 83 b) 82 5 a4 Ans: b 28. What file contains the list of port numbers (and associated names) monitored by inetd? a) fetc/services b) /etc/nsorder ©) /etc/nsswitch.conf/ d) fetchhosts Ans: a 29. The location of some system configuration and system administrator executable files, is: a) /home b) /proce) /var d) /sbin €) None of the above Ans: d COMPACT IT Preliminary Page | 611

You might also like