Skip to content

Instantly share code, notes, and snippets.

@vd89
Created March 31, 2020 06:11
Show Gist options
  • Save vd89/dc6dda9bc75e73f372a9ce58f8324a0c to your computer and use it in GitHub Desktop.
Save vd89/dc6dda9bc75e73f372a9ce58f8324a0c to your computer and use it in GitHub Desktop.
Linux Question and Answer Assignment
Section 1
1. Expand Bash.
Ans:
bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file. bash also incorporates useful features from the Korn and C shells (ksh and csh).
bash is intended to be a conformant implementation of the Shell and Utilities portion of the IEEE POSIX specification (IEEE Standard 1003.1). bash can be
configured to be POSIX-conformant by default.
2. Explain all types of Shell Expansion.
Ans:
Expansion is performed on the command line after it has been split into tokens. There are seven kinds of expansion performed:
brace expansion
tilde expansion
parameter and variable expansion
command substitution
arithmetic expansion
word splitting
filename expansion
3. what is the usage of the man command?
Ans:
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 and SEE ALSO.
4. Write a command to display the current working directory.
Ans:
pwd is the command to displau the current worrking directory
5. Write a command to change the directory path to a certain directory.
Ans:
cd is the command to change the directory path to a certain directory
6. Write a command to get into the home directory.
Ans:
cd ~ or cd is the command to navigate to home directory
7. Write a command to get into the parent directory.
Ans:
cd .. is the command to navigate to the parent directory
8. Write a command to go to the previous directory.
Ans:
cd- is the command to previous directory
9. Define the absolute path.
Ans:
An absolute path refers to the complete details needed to locate a file or folder, starting from the root element and ending with the other subdirectories. Absolute paths are used in websites and operating systems for locating files and folders. An absolute path is also known as an absolute pathname or full path.
10. Define the relative path.
Ans:
Relative path is defined as the path related to the present working directly(pwd). It starts at your current directory and never starts with a / .
11. Write command to make a directory.
Ans:
mkdir is to make a new directory
12. Write command to remove a directory.
Ans:
rm -r is the command for non-empty directory to remove
13. Write command to remove the empty directory.
Ans:
rmdir is the command to remove a empty directory
14. Write a command to remove all the files and sub-directories present in the directory.
Ans:
rm -rfv is the command followed by the directory name is the command
15. Write the usage of the pushd command.
Ans:
The pushd command is used to save the current directory into a stack and move to a new directory.
16. Write the usage of the popd command.
Ans:
popd can be used to return back to the previous directory that is on top of the stack.
17. Write a command to list all the files in the current directory
Ans:
ls is the command to list all files in the current
18. Write command to know the type of any given file.
Ans:
file is the command to get the type of given file
19. Write about the magic file in the Unix file system.
Ans:
20. Write the usage of file command for the special files as a parameter.
Ans:
file command in Linux with examples. file command is used to determine the type of a file. .file type may be of human-readable(e.g. 'ASCII text') or MIME type(e.g. 'text/plain; charset=us-ascii'). This command tests each argument in an attempt to categorize it.
21. Write a command to create the file.
Ans:
touch fileName is the command to create a file
22. Write a command to copy the file without a change in timestamps.
Ans:
cp -p oldfile newfile is the command that do without a change in timestamps
23. Write a command to modify the access time of a file.
Ans :
touch -m fileName will only change the time of the file
24. list all the options available for the touch command.
Ans:
Touch Command Options
-a, change the access time only
-c, if the file does not exist, do not create it
-d, update the access and modification times
-m, change the modification time only
-r, use the access and modification times of file
-t, creates a file using a specified time
25. Write command to remove a file from a directory.
Ans:
rm fileName is the command to remove file from a directory
26. Write about ​ 'rm -i​ ' command.
Ans:
rm -i will prompt removal of file
27. Write a command to copy the file.
Ans:
cp is the command to copy the file
28. Define about the recursive copy.
Ans:
cp -R is the command
You can use cp to copy entire directory structures from one place to another using the -R option to perform a recursive copy.
29. Write about the usage of head command.
Ans:
The head command is a command-line utility for outputting the first part of files given to it via standard input. It writes results to standard output. By default head returns the first ten lines of each file that it is given.
30. Write about the usage of the tail command.
Ans:
The tail command is a command-line utility for outputting the last part of files given to it via standard input. It writes results to standard output. By default tail returns the last ten lines of each file that it is given. It may also be used to follow a file in real-time and watch as new lines are written to it.
31. Write a command to view the file content.
Ans:
cat is the command to get the file content
32. Write the usage of cat command to copy the file.
Ans:
cat file.txt > newFile.txt
Read the contents of file.txt and write them to newfile.txt, overwriting anything newfile.txt previously contained. If newfile.txt does not exist, it will be created.
cat file.txt >> newFile.txt
Read the contents of file.txt and append them to the end of another-file.txt. If another-file.txt does not exist, it will be created.
33. Write the usage of cat command to create the file
Ans:
cat > file.txt
To create a new file, use the cat command followed by the redirection operator (>) and the name of the file you want to create.
34. Write command to concatenate the file contents.
Ans:
cat fileFirst.txt fileSecond.txt
When passing two or more file names as arguments to the cat command the contents of the files will be concatenated. cat reads the files in the sequence given in its arguments and displays the file’s contents in the same sequence.
35. Write a command to copy files using mv command
Ans:
mv fileFirst fileSecond
36. Write command to move the files.
Ans:
mv fileFirst.txt /home/backup
37. Write the usage of tac command.
Ans:
tac command in Linux is used to concatenate and print files in reverse. This command will write each FILE to standard output, the last line first. When no file is specified then this command will read the standard input. Example: It will print files in reverse
38. Write briefly about the chmod command.
Ans:
In Unix and Unix-like operating systems, chmod is the command and system call which is used to change the access permissions of file system objects (files and directories). It is also used to change special mode flags. The request is filtered by the umask. The name is an abbreviation of change mode
39. Write a command to change the mode a file as universal Writable/readable.
Ans:
chmod 777 is command for the universal writeable readable
40. Write a command to change the file as executable/Writable/rea
Ans:
chmod 777 is command for the executable writeable readable
41. Write all the file permissions possible.
Ans :
In this mode, file permissions are not represented as characters but a three-digit octal number.
The table below gives numbers for all for permissions types.
Number Permission types Symbol
0 No Permission ---
1 Execute --x
2 Write -w-
3 Execute + Write -wx
4 Read r--
5 Read + Execute r-x
6 Read +Write rw-
7 Read + Write +Execute rwx
42. Write about umask command.
Ans:
On Linux and Unix operating systems, all new files are created with a default set of permissions. The umask utility allows you to view or to set the file mode creation mask, which determines the permissions bits for newly created files or directories
43. Write the usage of 'chown' command.
Ans:
chown command is used to change the file Owner or group. Whenever you want to change ownership you can use chown command.
44. Write a command to make the files and directories to have all permissions to you and only readable to others
Ans:
chmod 744 fileFirst.txt is the command to change the permissions
45. Write a command to print output in stdout and in file.
Ans:
46. Write about the grep command.
Ans:
Grep is an acronym that stands for Global Regular Expression Print. Grep is a Linux / Unix command-line tool used to search for a string of characters in a specified file. The text search pattern is called a regular expression. When it finds a match, it prints the line with the result.
47. Write a command to print the top and bottom n lines
Ans:
head -n 5 fileName.txt | tail -10
48. Write briefly about the' tr' command
Ans:
tr is a very useful UNIX command. It is used to transform string or delete characters from the string. Various type of transformation can be done by using this command, such as searching and replacing text, transforming string from uppercase to lowercase or vice versa, removing repeated characters from the string etc.
49. Write a command to print word count in a given file.
Ans:
wc [options] fileName
wc -l : Prints the number of lines in a file.
wc -w : prints the number of words in a file.
wc -c : Displays the count of bytes in a file.
wc -m : prints the count of characters from a file.
wc -L : prints only the length of the longest line in a file.
50. explain sort command usage to sort the file numeric wise.
Ans:
SORT command is used to sort a file, arranging the records in a particular order. By default, the sort command sorts file assuming the contents are ASCII. Using options in sort command, it can also be used to sort numerically. SORT command sorts the contents of a text file, line by line.
51. Write about the sed command briefly.
Ans:
sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file, or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. But it is sed's ability to filter text in a pipeline which particularly distinguishes it from other types of editors.
52. sort the file contents using PIPE
53. Write command to display the IP address of the host
Ans:
ifconfig for linux
ipconfig for Windows
54. Write about IP command.
Ans:
ip command in Linux is present in the net-tools which is used for performing several network administration tasks. IP stands for Internet Protocol. This command is used to show or manipulate routing, devices, and tunnels. It is similar to ifconfig command but it is much more powerful with more functions and facilities attached to it. ifconfig is one of the deprecated commands in the net-tools of Linux that has not been maintained for many years. ip command is used to perform several tasks like assigning an address to a network interface or configuring network interface parameters.
It can perform several other tasks like configuring and modifying the default and static routing, setting up tunnel over IP, listing IP addresses and property information, modifying the status of the interface, assigning, deleting and setting up IP addresses and routes.
55. create an alias to display your city name.
Ans:
alias Rj ='Rajkot'
56. explain about 'which' command
Ans:
Which command is very small and simple command to locate executables in the system. It allows user to pass several command names as arguments to get their paths in the system. “which” commands searches the path of executable in system paths set in $PATH
57. Write a command to display the exit code of the previous command.
58. execute the pwd command twice using a single command.
Ans:
pwd ; pwd
59. Execute a command to sleep your system for 10 seconds.
Ans:
sleep 10
60. Write about the environmental variables.
Ans:
Environment variables or ENVs basically define behavior of the environment. They can affect the processes ongoing or the programs that are executed in the environment.
61. Write a command to display all the environmental variables in the system
Ans:
printenv is the command to see all the env variables
62. Export a Myvar shell variable using export command.
Ans:
export Myvar is the command to export
63. Write a command to display all the files ending with .txt
Ans:
ls *.txt is the command
64. Write about the file globbing.
Ans:
File globbing is a feature provided by the UNIX/Linux shell to represent multiple filenames by using special characters called wildcards with a single file name. A wildcard is essentially a symbol which may be used to substitute for one or more characters.
65. Interpret the command 'echo *'.
Ans:
this command will print all files/folders, similar to ls command .
66. Exhibit the command 'ls [a-z]*.txt'.
Ans:
To combine with [] we can list only files which has extension sh and txt but "." ( dot )is preceded by any character but number.
67. Write a command to display the file which has alphabets in octal order.
Ans:
68. Write a command to display all removed duplicate columns in a file.
Ans:
uniq [-option] is the command
69. Write the usage of a find command.
Ans:
Find command is used to search and locate the list of files and directories based on conditions you specify for files that match the arguments. Find can be used in a variety of conditions like you can find files by permissions, users, groups, file type, date, size, and other possible criteria.
70. Write the utility usage of date.
Ans:
date command is used to display the system date and time. date command is also used to set date and time of the system. By default the date command displays the date in the time zone on which unix/linux operating system is configured.You must be the super-user (root) to change the date and time.
71. Compress the file a.txt using the gzip command.
Ans:
gzip a.txt is the command
72. Write a command to unzip the file using gunzip.
Ans:
gunzip [file1] [file2] is the command
73. Explain briefly about catzip command.
74. Write about bzip,bunzip,bzcat commands.
Ans:
75. explain the difference between bzip and gzip commands.
76. Write about the 'w' command.
Ans:
The command w on many Unix-like operating systems provides a quick summary of every user logged into a computer, what each user is currently doing, and what load all the activity is imposing on the computer itself. The command is a one-command combination of several other Unix programs: who, uptime, and ps -a.
77. Write about who command.
Ans:
The standard Unix command who displays a list of users who are currently logged into the computer. The who command is related to the command w , which provides the same information but also displays additional data and statistics.
78. Write about the id command.
Ans:
id command in Linux is used to find out user and group names and numeric ID's (UID or group ID) of the current user or any other user in the server. This command is useful to find out the following information as listed below: User name and real user id.
79. Write about the Sudo command.
Ans:
On Unix-like operating systems, the sudo command (sudo stands for "superuser do") allows a user with proper permissions to execute a command as another user, such as the superuser.
80. Write about the /etc/passwd file.
Ans:
The /etc/passwd File. /etc/passwd is a text file that contains the attributes of (i.e., basic information about) each user or account on a computer running Linux or another Unix-like operating system. Each line in /etc/passwd represents a single user.
81. Write a command to create a user.82. Write a command to delete the user 'user5'
Ans:
to create user
sudo adduser user.82 ; sudo passwd user.82
to delete user
sudo deluser user5
83. change the user description using usermod command.
84. Write briefly about the /etc/skel command.
Ans:
The /etc/skel directory contains files and directories that are automatically copied over to a new user's when it is created from useradd command. This will ensure that all the users gets same intial settings and environment.
85. Write a command to change the shell of a prescribed user.
Ans:
usermod --shell /bin/bash user
86. Write a command to change your shell to the Korn shell.
Ans:
chsh -s /bin/ksh
87. Write a command passwd command
Ans:
passwd is the command
88. what is the use of /etc/passwd file.
Ans:
Traditionally, the /etc/passwd file is used to keep track of every registered user that has access to a system. The /etc/passwd file is a colon-separated file that contains the following information: User name. Encrypted password.
89. create a user using a command useradd with OpenSSL function
90. Write briefly about the /etc/login.defs
Ans:
The /etc/login. defs file provides default configuration information for several user account parameters. The useradd, usermod, userdel, and groupadd commands, and other user and group utilities take default values from this file. Each line consists of a directive name and associated value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment