User Tools

Site Tools


faq:unix

UNIX FAQ

A list of Frequently asked questions and answers to them.

Lab46/putty

Q: How do I connect to lab46 on with my laptop or home computer?
A: Install PuTTy then for Host Name type: lab46.corning-cc.edu. Then click open.
If you want to save the session, you would click save before you click open.

Q: Where can i get putty to install it?
A: The easiest way is to go to lab46.corning-cc.edu and click the link provided on the right.

Q: Why I can't I see my password when I am connecting to Lab46?
A: Because if you can see your password so could any one else that my be able to see your password. [jbrant]

Q: What are some quick keys?
A: all the control keys with do much of the things you want a lot quick for example: cntrl-l will clear the screen.

Q: Is there a quickier way than typing out the whole name of a file?
A: Start to type out the name of the file and when a enough of character are different from any other file hit tab.

Q: I forgot the name of a command, how can I find it?
A: If you know just the start of the letter for the command you can hit the tab twice and it will give you all the commands under that letter. Use the mans to find what you are looking for.

Q: What is the purpose of SSH?
A: SSH is typically used to log into a remote machine and execute commands, putty.

Q: What port is Lab46?
A: Port 22.

Q: IS there an easier way to log into your Lab46 without having to type in the lab46.corning-cc.edu each time, then typing your username, then your password?
A: Yes, you can either type lab46.corning-cc.edu and hit the save button, or type (yourusername)@lab46.corning-cc.edu and save it. Once saved you can just click on it, hit open, and type either your username then password, or just password depending on what you saved.

The UNIX philosophy

Q: What is the UNIX philosophy?
A:

1.Small is beautiful.\\
2.Make each program do one thing well.\\
3.Build a prototype as soon as possible.\\
4.Choose portability over efficiency.\\
5.Store data in flat text files.\\
6.Use software leverage to your advantage.\\
7.Use shell scripts to increase leverage and portability.\\
8.Avoid captive user interfaces.\\
9.Make every program a filter.\\
                    ~Brandon Kennedy\\

UNIX/Linux Administration

Q. How do I add a user on a *nix system?

A. (HINT: There's a newer utility to do this very same thing)

Assuming that you're not root, and that you're listed in the sudoers file, adding users requires the following command:

matt@lab46:~$ sudo useradd -gadm -gunix -pxxxx -d/home/<username> -m <username>

(where <username> is your desired username) The above command adds a user to the groups (-g) adm and unix. You can also add yourself to groups manually by directly editing the file etc/group. However, since most users don't have root access, this again requires sudo:

matt@lab46:~$ sudo vi etc/group

Once open, find the adm and unix entries and add your new user's name to the end of the list. (no points for being first)

Using the -p option of the useradd command doesn't encrypt your password in the etc/shadow file. Additionally, if the password is not encrypted, the system doesn't like to let you authenticate. To see what I mean, issue the following command: (you may want to pipe this to less)

matt@lab46:~$ sudo cat etc/shadow | less

Scroll through the file and see that the password you entered with the -p option of the useradd command is there in plain text for all to see (well at least those in the sudoers file). Whoops. Now, attempt to authenticate with the following command:

matt@lab46:~$ su <username>

You will be prompted for your password. No dice huh? To fix this, as ROOT, issue the following command:

matt@lab46:~$ sudo passwd <username>

Again, substitute <username> with your new user's name. You will then be prompted for the new password, and, once complete, the NEW password will be hashed.

Q. How do I add a user to a group?

A.

First, create a new group if it doesn't already exist: (sudo it…)

matt@lab46:/$ sudo groupadd foobar

After that, add the user to the group:

matt@lab46:/$ sudo usermod -G foobar bill

List the user's groups to verify:

matt@lab46:/$ id -nG bill 
foobar

Q. How do I remove a user from a group?

A.

Begin by finding the user's current group membership:

matt@lab46:~$ id -nG matt

(-n prints a name instead of a user id, and -G (uppercase) prints out the user's groups.)

After the user's groups have been listed, remove them from specific groups with the following syntax (omitting the groups that the user is to be removed from):

usermod -G {groupname1,groupname2,...} {username}

In practice, if the user's name is william:

matt@lab46:/$ id -nG william 
lab46 unix hpc william

This user is a member of the lab46, unix and hpc groups, as well as the group named 'william'. (Each user on a *nix system is a member of their own group.)

To remove the user from the hpc group:

matt@lab46 :~$ usermod -G {unix, hpc}{william}

Using Screen

Q. How do I manage multiple screen sessions?

A. The screen utility allows you to name your screen sessions, making it easier to reattach. Simply name your screen session when you start it:

matt@lab46:~$ screen -S <name>

(where <name> is the actual name you want to give the session.) Then, once you have multiple sessions open, you can list them using:

matt@lab46:~$ screen -ls

This command will provide you with a list of screen session in the form of <process id>.<name>. This allows you to restore your session by name:

matt@lab46:~$ screen -r <process id>.<name>

For example:

matt@lab46:~$ screen -S irc

… do things with the session …

This provides a list of open sessions:

matt@lab46:~$ screen -ls 
There is a screen on: 
	12082.irc	(Detached) 
1 Socket in /var/run/screen/S-matt. 

Next, resume the session:

matt@lab46:~$ screen -r 12082.irc

Questions on VI

Q. What is nano?

A. A lower level text editor, much like VI, with the exception of many powerful text editing tools.

Q. What are the command mode keys for vi?

A.

Cursor movement—h, j, k, l (left, down, up, and right) 
Delete character—x
Delete line—dd
Mode toggle—Esc, Insert (or i) 
Quit—:q
Quit without saving—:q!
Run a shell command—:sh (use 'exit' to return) 
Save file—:w
Text search—/

Q: How do you enter the editor 'VI' in read-only mode? [jbrant]
A: vi -R file
A: Also by using 'view' you will enter vi in read_only as well.[jbrant]

Q: How do you Exit the editor 'VI'
A: :q - exits; :wq - saves and exits

Q: What are the two modes in VI and how do you switch between them?
A: Insert mode which you can get to by hitting the 'I' key
A: Command mode which you can get to by hitting the escape key if you're in Insert mode. By default, you'll be in command mode upon entering 'VI'.

Q: How do you get to the extended command mode in VI?
A: Hit the ':' key

Q: How turn line numbering on in VI?
A: type the command :set number

Q: How to moving in VI without using the arrow keys? A: using h,j,k,l to get left, down, up, right

Q: What are some other useful movement keys? A: 0,$ First nonblank char. of next line. H key top line of the screen M for middle line of the sceen and L for last line of the sceen.

Q: How do you search in VI? A:/pattern for search forward and ?pattern for backward.

Q: What are the different types of exits? A: :w and :x and :wq all write and quit file

 :w! save and overriding protection 
 :q quit
 :q! overriding protection 
 :e! return to version of current file at time of last write
 :e # edit alternate file

Q: What are the Etended Regular Expressions? A: \+ Matches ine or more

 \= matches zero or one 
 \{n,m} matches n to m
 

Q: Am I able to add comments to my scripts?
A: Yes, by using # you are able to add comments without it interfering.

Q: Where is the only correct place to put a curly brace when programming in the ONLY REAL text editor? jhammo13
A: After the function on the NEXT line. NEVER on the same. jhammo13

Q:Is it possible to work with multiple files at the same time in VI? dschoeff
A:Yes. You can split the screen allowing you to work with multiple files at the same time. dschoeff

Q: How might I go about so this? dschoeff
A: When in VI on the command line enter :sp filename. This will split the screen horizontally. To split it vertically enter :vsp filename dschoeff

Q: Once I have multiple files open how do I switch between them? dschoeff
A: hold down CTRL and hit ww. dschoeff

Q: Is it possible to copy and paste in VI? dschoeff
A: Yes. When in command mode just hit yy to copy the current line. If you would like to copy more than one line specify how many before hitting yy (exa. to copy 5 lines hit 5 yy). Once you have those line copied into the buffer go to the desired line you wish to paste and hit p. dschoeff

Q: What is the easiest way to delete content in VI? dschoeff
A: In command mode to delete the current line hit dd. To delete multiple line specify how many before hitting dd. dschoeff

Q: How do I add/remove line numbers in VI? dschoeff
A: In command mode type :set number to add line numbers. To remove them type :set nonumber(useful when copying text). dschoeff

Unix Packages

Q: Is it hard to install packages within unix?

A. No, for most all packages a how to is accessible online.

Q. What is the most common download method?

A. In most cases ftp is primarily used to download packages onto your system.

Q. Do I need any special privelages to install a package?

A. Yes you will be to be the super user of the system to do so.

Q. How do I become this, "super user"?

A. To do so simply enter su at the promtp along with your username, you will be prompted for the su passwords, once entered correctly you are a super user.

Q. Do these packages cost money?

A. No, most all unix packages, just as with the OS are free open source pieces of software.

Q. Where can I find how-to guides?

A. Once you have decided on a package you would like simply do a google search for the package along with the os you will be installing on.

Q. Where should I download my packages to?

A. You should create a speciied area where you would like to download your packages, other than your main home directory.

Q. Should I install packages directly in my home directory.

A. As good practice it is recommended to install packages into predefined directories that relate to the package in question.

Questions by Jon Share

Using Ytalk

Q: What is ytalk?
A: A multi-user chat program. ~emorris4

Q: How do I use yalk? A: on your command-line type ytalk (username you wish to ytalk with). Once they respond with the same command, ytalk (your username), you just type. You can either erase your text each time r hit enter for a new line.

Q: My friend openned a bash session in ytalk, how do i do that? A: while in a ytalk session you press ESC then s. This opens a normal bash command line right in your ytalk session.

Q: is there a quicker to talk to people? what if i just want to say one thing real quick?
A: A faster way to say something to someone would be to type: mesg (username), then you will see something like this: lab46:~$ mesg bkenne11

(this is where you will type a message and then hit enter)

this will quickly send a message to whatever username you put in, as lng as their mesg is on y, not n.

Q: How do i turn my mesg on or off?
A:to turn it on you type mesg y. to turn it off you type mesg n

Questions about basic Unix Commands

Brian Nichols

Q: Where can I find information about Unix/Linux commands?
A: If you know the command you want to find information about, you could easily just type man blank (fill in blank with your command) in the terminal.

Q: If you don't know what the exact command is that you want to search for, how might you search the man pages?
A: Use the command apropos [word], where word is the desired command or effect of the command. (ex. apropos moon to find the command to display the current phase of the moon.)

Q: How do I change directories?
A: Type cd command (change directory)
Example: cd src/Data
Example: cd /usr/games

Q: How do I make new directories?
A: Type mkdir [name]
Example: mkdir doggy
(This makes a doggy directory)

Q: What about a calendar Mr. knowitall?
A: Type cal at the prompt and it will show a calendar.

Q: What about a calculator?
A: Type bc at the prompt, and it will bring up the binary calculator
(also, if you type obase=2, this makes input turn into Binary)
(also, if you type obase=16, this makes input turn into Hex)

Q: What symbol is used to indicate home directory? [jbrant]
A: ~
Q: How do I know what files are in this directory?
A: Type ls (means to list), to list out what is in the file

Q: How do I know what file type this file is?
A: Type file in-front of the file, then it will show what kind of file it is

Q: How do you list any hidden files in a directory when using the 'ls' command? [jbrant]
A: ls -a

Q: How would you find out what process you have running? [jbrant]
A: Type the command ps aux | grep $USER

Q: How would you gain root like privileges? [jbrant]
A: sudo followed by what ever command you need to run as root. [jbrant]

Q: What is the symbol '|' called? [jbrant]
A: A Pipe [Marc Brigham]

Q: How can you view the continent of a file without opening it? [jbrant]
A: less filename [Marc Brigham|

Q: How would you search a file to find a line that contains a specific word?
A: use the grep command cat [filename] | grep [the word you're looking for]

Q: Show an example of an absolute path
A: /usr/games [jbrant]

Q: Show an example of a relative path
A: cd dir/dir [jbrant]

Q: What is the command to show you what directory you're currently in?
A: type the command 'pwd'

Q: I just used a command and wish to use it again, do I have to retype it again?
A: By using the up and down arrows one may see the previous commands which were entered.

Q: What is grep used for?
A: Grep is a command line text search utility, it searches files or input for lines matching a given regular expression, and prints them to the standard output.

Q: What is sed?
A: Sed is a stream editor, it takes input and sends the output to screen or redirected file. You can use the sed command to change all of one string to another within a file, just like a search-and-replace feature, usefull in decoding something. The sed command can also delete a range of lines from a file.

Q: What is the purpose of awk?
A: Awk is a combination of grep and sed. You may substitue words from an input file or perform calculation within a file.

Q: How can I see today's date?
A: using the date command tells you the current date and time.

Q: How can you look at the logins to lab46 of all the users for the current month? jhammo13
A: Use the 'last' command by itself. jhammo13

Server Questions

Marc Brigham

Q: How do you install LAMP?
A:

Q: What is the difference between hardware virtualization and paravirtualization?
A: Hardware virtualization is like running an OS on top of an OS. Paravirtualization is like the OS resources are shared.

Q: How would I statically change my IP address?
A: ifconfig eth0 10.70.0.66 netmask 255.255.252.0

Q: How would I update and upgrade my server through the command line?
A: sudo apt-get update
sudo apt-get upgrade

Q: Why do you have to type sudo to upgrade your system?
A: You have to be the root user.

Q: How do you copy files?
A: cp file1 file2

Q: How do you find a word count on a file?
A: wc file

Q: Ho do you change the number of shell commands in the history?
A: Find the file with the extension of .cshrc file and then find and set history = 100. 100 is the default value. To see if it worked just echo $history.

Section Heading J

Bash Scripting

Q: How do you make your script executable?
A: type the command chmod u+x [filename]

Q: How would you change ownership of a file? [jbrant]
A: chown newowner filename [jbrant]

Q: When writing a bash script want would the first line look like?
A: #!/bin/bash

Q: Can show an example of a wildcard? [jbrant]
A: ls -l file* where * is the wildcard [jbrant]

Q: How do I end a If then statement?
A: You may end a If then by typing fi.

Q: How can you loop through a text file and use the next line as a variable? jhammo13
A: for example in `cat examptxt.txt` where example is your variable and examptxt is the text file. jhammo13

Q: How do you get input from the user and store to a variable? jhammo13
A: Use the 'read' command followed by whatever variable you want. jhammo13

Q: How can you output to a file in a script? jhammo13
A: Follow whatever you want your file to be to '> filename' where filename is whatever you want your file to be named. jhammo13

Q: How do you refer back to a variable you declared? jhammo13
A: Put a dollar sign immediately followed by whatever your variable was named. jhammo13

Q: How can you output the contents of a variable to standard output? jhammo13
A: Use the echo command. In example echo “$yourVariable” where yourVariable is whatever your variable is. jhammo13

Q: How can you set a variable equal to a series of piped commands? jhammo13
A: Put yourVariable = `your commands`. where your commands is in back tics not quotes. jhammo13

Q: What is the purpose for each type of quotations in scripting?
A: ” - does variable expansion (echo “I am $USER”)
' - a literal quote, no expansion takes place (echo 'I am $USER')
` - for command expansion (echo “There are `who|wc-l` users on the system”)

Questions about ports

Q: How can you use ncat to listen to a given port. [jbrant]
A: ncat -l [host] [port] :
Where host is a hostname or ip which can be omitted and it will bind to all local interfaces. and port is the port number to listen on. The port number used is grater that 10000. If you omitted it then is will uses the default 31337. [jbrant]

Section Heading M

Random Questions

1. How does one save in VI? :w

2. How does one exit VI? :q

3. How does one apply a GUI to a Unix OS?

4. If something important is deleted, is there any way to restore it? Nope. Before you delete something make sure you want to delete it!

5. What is that text web browser called? elink ~emorris4

6. What is the most popular Unix distro?

7. How is a zombie file created?

8. Has anyone ever gotten a virus in Unix or ran a malicious script?

9. Q: What is Mosquito?

 A: Most likely one of the best movies you will ever see in your life.
 

10. Q: how can I see who is currently logged onto lab46? dschoeff

  A: users    

11. Q: how can I see then current processes I have running? dschoeff

  A: ps     

grep

1. How do I match characters at the beginning of the line?

A. ^ or </ for beginning of words

emorris4/

2. How do I only match a specific amount of characters?

A. To match 3 characters you would use brackets i.e [a-z][a-z][a-z]

emorris4/

3. How do I match only ONE character?

A. Use brackets and insert the character you wish to view. ie [a]

emorris4

4. How do I match characters at the end of the line?

A. Use $, to match end of words use \>

emorris4

5. How do I match zero or more characters?

A. Use .

emorris4

6. How do I match all characters?

a. Use *

emorris4

7. How would I list the files in my home directory that start with h and end with t?

a.

8. How would I list the above files, sort them alphabetically, and move them to a new file?

a.

Section Heading P

faq/unix.txt · Last modified: 2011/05/19 00:19 by dherman3