Wednesday, November 1, 2017
Simple Linux Questions

1. What is the name and the UID of the administrator user?
administrator user name is root and UID(user ID) is 0
Command is :~$ id username
2. How to list all files, including hidden ones, in a directory?
ls -la [file|dir]
l - list with long format
a - list all files including hidden file starting with '.'
3. What is the Unix/Linux command to remove a directory and its contents?
rm - command to remove files or directories
r - remove directories and their contents recursively
f – force remove
rm -r directory or rm -rf directory
4. Which command will show you free/used memory? Does free memory exist on Linux?
free - command to display amount of free and used memory in the system
Full command:
$ free
total used free shared buffers cached
Mem: 1551836 1048324 503512 0 324244 518224
-/+ buffers/cache: 205856 1345980
Swap: 731132 0 731132
5. How to search for the string "my konfi is the best" in files of a directory recursively?
You can use find and grep command.
Full command:
$ find ./* -type f -exec grep -H 'my konfi is the best' {} \;
$ grep -r 'my konfi is the best' ./*
6. How to connect to a remote server or what is SSH?
Secure Shell, or SSH, is a cryptographic (encrypted) network protocol to allow remote login and other network services to operate securely over an unsecured network.
To connect to remote server we can use command ssh
Full command:
$ ssh login@remote_server_ip
7. How to get all environment variables and how can you use them?
All UNIX-like operating systems such as OpenBSD, Linux, Redhat, CentOS, Debian allows you to set environment variables. When you log in on UNIX, your current shell (login shell) sets a unique working environment for you which is maintained until you log out.
printenv\env - command to print all or part of environment
Full command:
$ printenv PATH HOME
$PATH - Display lists directories the shell searches, for the commands.
$HOME - User's home directory to store files.
All environment variables you can use in scripts.
8. I get "command not found" when I run ifconfig -a. What can be wrong?
Possible causes:
1. net-tools package is not installed in your system.
2. you don`t have "/sbin" directory in your $PATH, so just write full path for command - /sbin/ifconfig -a
9. What happens if I type TAB-TAB?
It depends on where you type this.
If we are talking about shells like bash\zsh, so you type TAB-TAB it will enable built in "completion" function.
Most shells allow command completion, typically bound to the TAB key, which allow you to complete the names of commands stored upon your PATH, file names, or directory names.
This is typically used like so:
$ ls /bo[TAB]
10. What command will show the available disk space on the Unix/Linux system?
df - report file system disk space usage
Simple run command and you will see available disk space in your system
$ df -h
11. What commands do you know that can be used to check DNS records?
$ host example.com
$ nslookup example.com
$ dig example.com
$ python -c "import socket;print(socket.gethostbyname('example.com'))"
12. What Unix/Linux commands will alter a files ownership, files permissions?
chown - command to change file owner and group information.
chmod - command to change file access permissions such as read, write, and access.
13. What does chmod +x FILENAME do?
This command will set execution bit to FILENAME for everybody owner\group\other.
14. What does the permission 0750 on a file mean?
chmod 750 FILENAME
-rwxr-x--- 1 root root 24 Jan 22 18:02 FILENAME*
This permission means that owner can read\write\execute this file, also members of the group can read and execute, other users can do nothing with it.
15. What does the permission 0750 on a directory mean?
$ chmod 750 DIRECTORY
drwxr-x--- 5 root root 4.0K Nov 10 12:36 DIRECTORY
This permission means that owner can read\write\execute(see file list of directory) this directory, also members of the group can read and list, other users can do nothing with it.
16. How to add a new system user without login permissions?
You can use the -M switch (make sure it's a capital) to ensure no home directory will be created:
useradd -M subversion
then lock the account to prevent logging in:
usermod -L subversion
17. How to add/remove a group from a user?
sudo groupadd groupname(developers)
sudo cat /etc/group
developers:x:1003:
useradd -G {group-name} username
useradd -G developers tsssinfo
sudo cat /etc/group
developers:x:1003:tsssinfo
tsssinfo:x:1004:
useradd -G developers infotec
developers:x:1003:tsssinfo,infotec
gpasswd -d username groupname.
gpasswd -d tsssinfo developers
developers:x:1003:infotec
$ id infotec
uid=1003(infotec) gid=1005(infotec) groups=1005(infotec),1003(developers)
18. What is a bash alias?
A Bash alias is essentially nothing more than a keyboard shortcut, an abbreviation, a means of avoiding typing a long command sequence.
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias lm='ls -latr'
19. How do you set the mail address of the root/a user?
sudo apt-get install mailutils
sudo nano /etc/aliases – add below mail address
root: user@methisyou.net
service postfix restart
20. What does CTRL-c do?
Control+C (control character intr) sends SIGINT which will interrupt the application. Usually causing it to abort, but this is up to the application to decide.
21. What is in /etc/services?
UNIX operating systems store what's called a services file at /etc/services. It stores information about numerous services that client applications might use on the computer. Within the file is the service name, port number and protocol it uses, and any applicable aliases.
The port numbers are mapped to specific services much like the hosts file on Windows computers map a hostname to an IP address.
22. How to redirect STDOUT and STDERR in bash? (> /dev/null 2>&1)
ls good bad >/dev/null 2>&1
You have to redirect stdout first before duplicating it into stderr; if you duplicate it first, stderr will just point to what stdout originally pointed at.
In bash you can do this with &>/dev/null but that's a bash extension.
23. What is the difference between Telnet and SSH?
1. Telnet is the joint abbreviation of Telecommunications and Networks and it is a networking protocol best known for UNIX platform.
2. Telnet uses the port 23 and it was designed specifically for local area networks.
3. Telnet is not a secure communication protocol because it does not use any security mechanism and transfers the data over network/internet in a plain-text form including the passwords and so any one can sniff the packets to get that important information.
4. There are no authentication policies & data encryption techniques used in telnet causing huge security threat that is why telnet is no longer used for accessing network devices and servers over public network.
5. On a Linux system, telnet can be easily installed using yum:
Example [root@pbx2 ~]# telnet localhost 80
SSH
1. SSH stands for Secure Shell and it is now only major protocol to access the network devices and servers over the internet.
2. SSH runs on port 22 by default; however it can be easily changed.
3. SSH is a very secure protocol because it shares and sends the information in encrypted form which provides confidentiality and security of the data over an un-secured network such as internet.
4. Once the data for communication is encrypted using SSH, it is extremely difficult to decrypt and read that data, so our passwords also become secure to travel on a public network.
5. SSH also uses a public key for the authentication of users accessing a server and it is a great practice providing us extreme security.
6. SSH is mostly used in all popular operating systems like Unix, Solaris, Red-Hat Linux, CentOS, Ubuntu etc
Example ssh alternative-username@sample.ssh.com
24. Explain the three load averages and what do they indicate. What command can be used to view the load averages?
To see load averages numbers you can run commands:
$ top (see load average section)
$ cat /proc/loadavg
1.00 1.01 0.98 2/198 21533
$ uptime
18:37:28 up 4 days, 7:17, 4 users, load average: 1.00, 1.01, 0.98
The three numbers after load average - 1.00, 1.01, 0.98 - represent the 1-, 5-, and 15-minute load averages on the machine. A system load average is equal to the average number of processes in a runnable or uninterruptible state. Runnable processes are either currently using the CPU or waiting to do so, and uninterruptible processes are waiting for I/O.
25. Can you name a lower-case letter that is not a valid option for GNU ls?
e, j
26. What is a Linux kernel module?
A loadable kernel module (LKM) is a mechanism for adding code to, or removing code from, the Linux kernel at run time. They are ideal for device drivers, enabling the kernel to communicate with the hardware without it having to know how the hardware works. The alternative to LKMs would be to build the code for each and every driver into the Linux kernel.
27. Walk me through the steps in booting into single user mode to troubleshoot a problem.
step 1: Power on or Reboot (if it is already running) your machine
Step 2: While booting press and hold “Shift” key, you might see the splash screen like below with the list of kernel installed. Select the recovery kernel and press Enter.
Step 3: Once the recovery kernel booted, you should see the following graphical command menu; in Ubuntu 11.10 there are two recovery menus available to recover your system, in this menu you can select any one out of four option;
Recovery Menu (limited read-only menu):
·
resume Resume normal boot
·
fsck Check all file systems (will exit
read-only mode)
· remount Remount
/ read/write and mount all other file systems
·
root Drop to root shell prompt
step 4: Once you have selected either “remount” or “fsck”; you have to press “Enter” to get normal recovery menu. Here you can select the option according to your requirement, this time file systems will be mounted read- write mode if you have selected Drop to root shell prompt or other options.
28. Walk me through the steps you'd take to troubleshoot a 404 error on a web application you administer.
1. Retry the web page by pressing F5, clicking/tapping the refresh/reload button, or trying the URL from the address bar again.
The 404 Not Found error might appear for several reasons even though no real issue exists, so sometimes a simple refresh will often load the page you were looking for.
The 404 Not Found error might appear for several reasons even though no real issue exists, so sometimes a simple refresh will often load the page you were looking for.
2. Check for errors in the URL. Often times the 404 Not Found error appears because the URL was typed wrong or the link
3. Move up one directory level at a time in the URL until you find something.
For example, if www.web.com/a/b/c.htm gave you the 404 Not Found error, move up to www.web.com/a/b/. If you get nothing here (or an error), move up to www.web.com/a/.
For example, if www.web.com/a/b/c.htm gave you the 404 Not Found error, move up to www.web.com/a/b/. If you get nothing here (or an error), move up to www.web.com/a/.
4. Search for the page at a popular search engine. It's possible that you simply have the entirely wrong URL in which case a quick Google or Bing search should get you where you want to go.
5. Clear your browser's cache if you have any indication that the 404 Not Found message might just be yours
6. Change the DNS servers used by your computer, but usually only if an entire website is giving you a 404 error, especially if the website is available to those on other networks (e.g. your mobile phone network or a friend in another city).
7. Finally, if all else fails, contact the website directly. If they've removed the page you're after then the 404 error is completely legitimate and they should be able to tell you that. If they've moved the page and are generating 404's instead of redirecting visitors to the new page, they'll be happy to hear from you so they can go fix it.
Subscribe to:
Post Comments (Atom)
Update GitLab (Omnibus based installations)
Welcome To My Blog Cash Back Shopping. Get Deals & Save Money Shop AT Ebates Try for Free!!!! ...
No comments:
Post a Comment