Linux Command Knowledge Base
Use this page to post research on Linux commands. Weekly command list for 3/31/2010 -
Information needed:
Description:
Man Pages:
Special Conditions:
Link to Web Resources:
Sample Code:
appropos
arp
autconf
bash
chmod
gcc
groupmod
groupadd
crontab
mdir
find
grep
users
who
whois
whoami
mount
kill
ls
cat
passwd
lsmod
finger
ftp
dig
ifconfig
Who command – Show who is logged into the system. With no options, list the names of users currently logged in, their terminal, the time they have been logged in.
Man Pages- 1,3,5,8
Link- http://en.wikipedia.org/wiki/Who_%28Unix%29#Manual_pages
Special Conditions- If FILE is not specified, use /var/run/utmp. /var/log/wtmp as FILE is common. If ARG1 ARG2 given, -m presumed: `am i’ or `mom likes’ are usual.
Sample- This sample output was produced at 8 a.m. on April 17:
$ who -uH NAME LINE TIME IDLE PID COMMENTS Earvin ttyp3 Apr 16 08:14 16:25 2240 Larry ttyp0 Apr 17 07:33 . 15182
Since Earvin has been idle since yesterday afternoon (16 hours), it appears that he isn’t at work yet. He simply left himself logged in. Larry’s terminal is currently in use.
Whois command- is a query/response protocol that is widely used for querying databases in order to determine the registrant or assignee of Internet resources, such as a domain name, an IP address block, or an autonomous system number.
Man Pages- 1,2,3,5
Link- http://www.nirsoft.net/utils/whoiscl.html
http://linuxmanpages.com/man1/whois.1.php
Special Conditions- On a firewall, you should allow outgoing connections to port 43
Sample- whois computerhope.com – doing a whois on computerhope.com, for example, will list information similar to the following.
Whois Server Version 1.3
Domain names in the .com, .net, and .org domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.
Domain Name: COMPUTERHOPE.COM
Registrar: NETWORK SOLUTIONS, INC.
Whois Server: whois.networksolutions.com
Referral URL: http://www.networksolutions.com
Name Server: NS.XMISSION.COM
Name Server: NS2.XMISSION.COM
Name Server: NS1.XMISSION.COM
Updated Date: 21-jun-2000
>>> Last update of whois database: Thu, 22 Feb 2001 07:49:41 EST <<<
The Registry database contains ONLY .COM, .NET, .ORG, .EDU domains and
Registrars.
LSMOD
description = program to show the status of modules in the Linux Kernel
Man Pages = lsmod page 8 (line 1/23)
limk = http://www.oreillynet.com/linux/cmd/cmd.csp?path=l/lsmod
special conditions = If the module controls its own unloading via a can_unload routine then the user count displayed by lsmod is always -1, irrespective of the real use count.
Sample of Command = type lsmod from the command line and it will list the “module” – “size” – “used by” information
Kill
Description: Cancels a job..
Man Pages: 1, 2,
Special Conditions: When running the kill command you may receive the error “Operation not permitted”, this is often encountered when you’re killing the wrong group id (often 1,2,3 or low number jobs) that you don’t have permission to kill. If you wish to see the group id of the background task run jobs -l
Link to Web Resources: http://www.computerhope.com/unix/ukill.htm
Sample Code: Kill 4582
ftp
•description:
-user interface to the Internet standard File Transfer Protocol, program allows a user to transfer files to and from a remote network site.
•available man pages:
-1, 3, 4, 8
•links:
-http://www.computerhope.com/software/ftp.htm
•special conditions:
-the FTP specification specifies many parameters which may affect a file transfer. The type may be one of ascii, image (binary), ebcdic, and local byte size (for PDP -10′s and PDP -20′s mostly). Ftp supports the ascii and image types of file transfer, plus local byte size 8 for tenex mode transfers. Ftp supports only the default values for the remaining file transfer parameters: mode form and struct.
•sample: ftp> help
-this lists the commands that you can use to show the directory contents, transfer files, and delete files.
Linux / Unix ifconfig command
The “ifconfig” command allows the operating system to setup network interfaces and allow the user to view information about the configured network interfaces.
Manual Page 8
Link – http://www.computerhope.com/unix/uifconfi.htm
Special Condition – User must be logged on as a “Super User”
Syntax
ifconfig [-L] [-m] interface [create] [address_family] [address[/prefixlength] [dest_address]] [parameters]
ifconfig interface destroy
ifconfig -a [-L] [-d] [-m] [-u] [address_family]
ifconfig -l [-d] [-u] [address_family]
ifconfig [-L] [-d] [-m] [-u] [-C]
Examples
ifconfig -a
The mount command
Description= the mount command is used to mount a file system, ex. hard disk, cd rom, etc..
Man Pages= 2 and 8
Special Conditions= Must be root to mount devices, Only the user that mounted a filesystem can unmount it again,
Web Resource=:http://linux.die.net/man/8/mount, http://linux.about.com/od/commands/l/blcmdl8_mount.htm
Sample code= mount [-l] [-t type]
(lists all mounted file systems (of type type). The option -l adds the (ext2, ext3 and XFS) labels in this listing. See below.)
1. apropos – search help manual pages files in unix and unix-like operating systems.(man -k)
2. manual page bash(1) line 1
3. http://www.ss64.com/bash/ , http://www.mediacollege.com , http://www.publib.boulder.ibm.com
4. apropos searches a set of database files containing short description of system commands for keywords and displays.
5. the apropos command shows the manual sections that contain any of the keywords specified by the keyword parameter in their title
TOP command
description = Linux command useful for system administrators, as it shows which users and processes are consuming the most system resources at any given time.
It is also possible to redirect the output of top to a text file.
Man Pages = top 1 (line 1)
limk = http://linux.die.net/man/1/top
special conditions = When operating top, the two most important keys are help (‘h’ or ‘?’) and quit (‘q’) key. Alternatively, you could simply use the traditional interrupt key (‘^C’) when you’re done.
Sample of Command = type top from the command line and it will list the “PID”, “USER”, %CPU USAGE” and various other headings that will ontinually be running and hanging as the omputer is running.
1.ARP is a tCP/IP command that is used to clear, add, or dump the Kernel’s Adress Resolution Protocol Cache. It can be used to translate a protocol adress to a hardware interface address. By modifying the ARP cahce you can change which interface handles certain requests. It is primarily only used by the user to configure it or display current information.
2.Information for it can be found using the manual command man 7 arp
3. http://www.oreillynet.com/linux/cmd/cmd.csp?path=a/arp
4. ARP is primarily only used during a configuration otherwise it provides a ser?vice for other protocols in the kernel.
Need to have root access in order to use the command
5. sample code: arp -a
You need to be logged in with root in order to use this command
this command should display the current connections including the ip address associated with it as well as the physical address
bash
• Primary interface to Linux. Accepts, interprets and executes your
commands, and provides you with the building blocks for shell scripting
and automated task execution.
• “man bash”
• http://articles.techrepublic.com.com/5100-10878_11-5827311.html
• no special conditions, able to run as user
• bash> alias ls = ”ls -l”
dig
• Used to query DNS servers
• Manual page 1 “man 1 dig”
• http://linux.die.net/man/1/dig
• no special conditions, able to run as user
• dig +qr http://www.isc.org any -x 127.0.0.1 isc.org ns +noqr
“WHOAMI” — This command prints the user name associated with the current effective user id.
This command can be found in man page “1″
Good resource—– Linuxconfig.org
This command can be used with no special conditions and run from the terminal.
Sample command —- whoami
— This command will give u the user name–
Information found in etc/issue
When you first boot up your new LFS system, the logon screen will be nice and plain (as it should be in a bare-bones system). Many people however, will want their system to display some information in the logon message. This can be accomplished using the file /etc/issue.
The /etc/issue file is a plain text file which will also accept certain escape sequences (see below) in order to insert information about the system. There is also the file issue.net which can be used when logging on remotely. ssh however, will only use it if you set the option in the configuration file and will not interpret the escape sequences shown below.
One of the most common things which people want to do is clear the screen at each logon. The easiest way of doing that is to put a “clear” escape sequence into /etc/issue. A simple way of doing this is to issue the command clear > /etc/issue. This will insert the relevant escape code into the start of the /etc/issue file. Note that if you do this, when you edit the file, you should leave the characters (normally ‘^[[H^[[2J’) on the first line alone.
GREP
1. Grep searches the named input FILEs (or standard input if no files are named, or the file name – is given) for lines containing a match to the given PATTERN. By default, grep prints the matching lines.
2. grep.1.man
3. http://linuxreviews.org/man/grep/index.html.en#toc1
4. command line utilty for user.
5. This command searches for all occurrences of the text string joe within all files of the current directory:
grep ‘joe’ *
The * wildcard matches all files in the current directory. (More accurately, it matches all files in the current directory that don’t begin with a decimal character, and it will also match any subdirectories in the current directory, but that usually isn’t much of a problem.)
FIND
1. The find command is used to locate files on a Unix or Linux system. find will search any set of directories you specify for files that match the supplied search criteria. You can search for files by name, owner, group, type, permissions, date, and other criteria. The search is recursive in that it will search all subdirectories too.
2. find.1.man find.9.man
3. http://linuxreviews.org/man/find/index.html.en#toc1
4. command line utilty for user.
5. find / -name game
Looks for a file named “game” starting at the root directory (searching all directories including mounted filesystems). The `-name’ option makes the search case sensitive. You can use the `-iname’ option to find something regardless of case.
MKDIR:
DESCRIPTION
Create the DIRECTORY(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options too.
-m, –mode=MODE
set file mode (as in chmod), not a=rwx – umask
-p, –parents
no error if existing, make parent directories as needed
-v, –verbose
print a message for each created directory
-Z, –context=CTX
set the SELinux security context of each created directory to CTX
MAN PAGE: mkdir(1)(2)(1p)(3p)
LINKS:
http://linuxreviews.org/man/mkdir/#toc1
http://linuxreviews.org/man/mkdir/#toc2
EXAMPLE:
mkdir bobby_diggs
Passwd~
Passwd command is used for changing a logon accounts password.
Man Pages: 1 and 5
Special Permissions: Must be logged on as super user.
Website Link: http://www.computerhope.com/unix/upasswor.htm
Sample Command:
Brandon-ET06-BMG:~> passwd
Changing password for brandon.
Old Password:
New Password:
Password has been changed.
groupadd – Create a new group
Synopsis
standard: groupadd [-g gid [-o]] group
Red Hat: groupadd [-g gid [-o]] [-r] [-f] group
Description
The groupadd command creates a new group account using the values specified on the command line and the default values from the system. The new group will be entered into the system files as needed. The options which apply to the groupadd command are
-g gid The numerical value of the group’s ID. This value must be unique, unless the -o option is used.
Red Hat Linux only:
-r This flag instructs groupadd to add a system account. The first available gid lower than 499 will be automatically selected unless the -g option is also given on the command line.
-f This is the force flag. This will cause groupadd to exit with an error when the group about to be added already exists on the system.
Man page = man groupadd(8)
Files
/etc/group – group account information
/etc/gshadow – secure group account information
Links:
http:// linux.about.com/od/commands/l/blcmdl8_groupad.htm
http:// linux.die.net/man/8/groupadd
See Also
chfn(1), chsh(1), passwd(1), groups(1), groupdel(8), groupmod(8), useradd(8), userdel(8), usermod(8)
Special Notes and conditions:
This command is normally not on the search path for executables, so you may need to use whereis to find it.
This command usually requires root access.
A system account is generally an account that isn’t logged into or used by users. Examples are audio, video, cdrom, dialout, scanner, staff, etc. It’s not clear exactly what special handling these accounts may be receiving with Red Hat; see Questions.
Examples
/usr/bin/groupadd newgrp
Creates group newgrp
Christopher Henry
Linux
03/31/2010
Linux Command Finger
Description-the finger utility displays information about local and remote system users. By default, the following information is displayed about each user currently logged-in to the local host.
- Login name
- Users full name
- Associated terminal name
- Idle time
- Login time
- From where
Man Page- Manual Page finger(1) line 7
Special Conditions- the names of terminals for which write permission is denied are prepended with an asterisk (`*’).
Web Page-http://linux.about.com/library/cmd/blcmdl1_finger.htm
When typing man:command in konqueror you get the following output;
“If man:command is not a typo you can run the following command to lookup the package that contains the binary;
command-not-found man:command\bash: man:command: command not found
Runlevels
Linux utilizes what is called “runlevels”. A runlevel is a software configuration of the system that allows only a selected group of processes to exist. Init can run the system in one of eight runlevels. These runlevels are 0-6 and S or s. The system runs in only one of these runlevels at a time. Typically these runlevels are used for different purposes. Runlevels 0, 1, and 6 are reserved. For Redhat Linux version 6, the runlevels are:
0 - halt
1 - Single user mode
2 - Multiuser, without NFS (The same as 3, if you don’t have networking)
3 - Full multiuser mode
4 - unused
5 - X11
6 - Reboot
autoconf – http://www.oreillynet.com/linux/cmd/cmd.csp?path=a/autoconf
autoconf [options] [template_file] –
Generate a configuration script from m4 macros defined in template_file, if given, or in a configure.ac or configure.in file in the current working directory. The generated script is almost invariably called configure.
Options
-d, –debug
Don’t remove temporary files.
-f, –force
Replace files generated previously by autoconf.
-h, –help
Print help message, then exit.
-i, –initialization
When tracing calls with the -t option, report calls made during initialization.
-o file, –output=file
Save output to file.
-t macro, –trace=macro
Report the list of calls to macro.
CHMOD
: Changes the permission of a file. There are 5 possible characters in the permission fields; r=read, w=write, x=execute, s=setuid. the characters to select who it applys to are; u=user, g=group, o=other users, a=allthe the above.
: man pages in terminal -1, 2, 1p,& 3p
: http://www.computerhope.com/unix/uchmod.htm#01
http://www.comptechdoc.org/os/linux/usersguide/linux_ugfilesp.html
: must specify pathname.
: chmod u+rw filename
Linux: Linux / Unix Command: cat
Command Library
NAME
cat – Allows you to look, modify or combine a file
Man Pages:
Manpages 1
Link:
http://www.linuxmanpages.com/man1
http://www.computerhope.com/unix/ucat.htm
Special Condition:
N/A
Sample Command:
Type the following command:
cat /etc/passwd
Summary of what command provides:
To Quickly View File With cat
————————————————————————————
Command : LS
Description:The Linux ls (list) command is a very popular Linux command that is used to show a listing of directories and files
Man Pages:
Man Page 1
Link:
http://searchwarp.com/swa211426.htm
http://en.wikipedia.org/wiki/Ls
Special condition:
N/A
Sample command:
ls -s: [--sIZE]
Summary of what command provides:
Prints the size of each file in block format [For example [X=4, Y=4, and Z=4]
1.
A. Top – The top program provides a dynamic real-time view of a running system. it can display system summary information as well as a list of task currently being managed by the linux kernel.
B. Free displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel.
C. Vmstat – reports information about processes, memory, paging, block IO, traps, and cpu activity.
2.
A. etc/issue – Is a text file which contains a message or system indentification to be printed before to login promt.
B. etc/motd – are displayed by login(1) after a successful login but just before it executes the login shell.
C. etc/passwd – file lists information about each of the users that may login to the system
3. command : kde page viewer
4. Runlevel 0 is reserved for the “shutdown” phase. Entering init 0 from the shell prompt will shutdown the system and usually power off the machine.
Runlevel 1 is usually for very basic commands. This is the equivalent to “safe mode” used by Windows. This level is usually only used to asses repairs or maintenance to the system. This is a single-user mode and does not allow other users to login to the machine.
Runlevel 2 is used to start most of the machines services. However, it does not start the network file sharing service (SMB, NFS). This will allows multiple users to login to the machine.
Runlevel 3 is commonly used by servers. This loads all services except the X windows system. This means the system will boot to the equivalent of DOS. No GUIs (KDE, Gnome) will start. This level allows multiple users to login to the machine.
Runlevel 4 is usually a “custom” level. By default it will start a few more services than level 3. This level is usually only used under special circumstances.
Runlevel 5 is everything! This will start any GUIs, extra services for printing, and 3rd party services. Full multi-users support also. This runlevel is generally used on by workstations.
Runlevel 6 is reserved for “reboot” only. Be carefully when running this command. Once you have entered init 6, there is no stopping it!
groupmod modifies a group entry using the values specified on the command line.
Options:
-D binddn Use dn “binddn” to bind to the LDAP directory
-g gid Change the group id to the given number
-k skeldir Specify an alternative skel directory
-n name Change group name.
-o Allow duplicate (non-unique) UID
-P path Search passwd, shadow and group file in “path”
-p password Encrypted password as returned by crypt(3)
-A user Add the user to the group entry
-R user Remove the user from the group entry
-r service Use nameservice ‘service’
–help Give this help list
–usage Give a short usage message
-v, –version Print program version
Valid services for -r are: files, ldap
man page 8
I didn’t find any special conditions
Link for info on groupmod on Novell’s site:
http://www.novell.com/support/php/search.do?cmd=displayKC&docType=kc&externalId=feature-16145html&sliceId=&docTypeID=DT_ARTIC
LES_TIPS_1_1&dialogID=69746861&stateId=0%200%20132746299
work:/home/scott # groupmod -n suseuser groupwise
work:/home/scott # groups jsmith
jsmith : users video suseuser
work:/home/scott #
The above command line set changes the group name.
1. 1. Provide KB information for:
A. Top – The top program provides a dynamic real-time view of a running system. it can display system summary information as well as a list of task currently being managed by the linux kernel.
B. Free displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel.
C. Vmstat – reports information about processes, memory, paging, block IO, traps, and cpu activity.
2. What infomation is found in:
A. etc/issue – Is a text file which contains a message or system indentification to be printed before to login promt.
B. etc/motd – are displayed by login(1) after a successful login but just before it executes the login shell.
C. etc/passwd – file lists information about each of the users that may login to the system
3.What output in Konqueror does man:command provide?
command : kde page viewer
4: What are the different run levels in Linux?
A. Runlevel 0 is reserved for the “shutdown” phase. Entering init 0 from the shell prompt will shutdown the system and usually power off the machine.
B. Runlevel 1 is usually for very basic commands. This is the equivalent to “safe mode” used by Windows. This level is usually only used to asses repairs or maintenance to the system. This is a single-user mode and does not allow other users to login to the machine.
C. Runlevel 2 is used to start most of the machines services. However, it does not start the network file sharing service (SMB, NFS). This will allows multiple users to login to the machine.
D. Runlevel 3 is commonly used by servers. This loads all services except the X windows system. This means the system will boot to the equivalent of DOS. No GUIs (KDE, Gnome) will start. This level allows multiple users to login to the machine.
E. Runlevel 4 is usually a “custom” level. By default it will start a few more services than level 3. This level is usually only used under special circumstances.
F. Runlevel 5 is everything! This will start any GUIs, extra services for printing, and 3rd party services. Full multi-users support also. This runlevel is generally used on by workstations.
G. Runlevel 6 is reserved for “reboot” only. Be carefully when running this command. Once you have entered init 6, there is no stopping it!
SCP
Information needed:
Description:scp copies files between hosts on a network. It uses ssh(1) for data transfer, and uses the same authentication and provides the same security as ssh(1). Unlike rcp(1), scp will ask for passwords or passphrases if they are needed for authentication.
Man Pages:1
Special Conditions:-c cipher
Selects the cipher to use for encrypting the data transfer. This option is directly passed to ssh(1).
-i identity_file
Selects the file from which the identity (private key) for RSA authentication is read. This option is directly passed to ssh(1).
-p
Preserves modification times, access times, and modes from the original file.
-r
Recursively copy entire directories.
-v
Verbose mode. Causes scp and ssh(1) to print debugging messages about their progress. This is helpful in debugging connection, authentication, and configuration problems.
-B
Selects batch mode (prevents asking for passwords or passphrases).
-q
Disables the progress meter.
-C
Compression enable. Passes the -C flag to ssh(1) to enable compression.
-F ssh_config
Specifies an alternative per-user configuration file for ssh This option is directly passed to ssh(1).
-P port
Specifies the port to connect to on the remote host. Note that this option is written with a capital `P’ because -p is already reserved for preserving the times and modes of the file in rcp(1).
-S program
Name of program to use for the encrypted connection. The program must understand ssh(1) options.
-o ssh_option
Can be used to pass options to ssh in the format used in ssh_config5. This is useful for specifying options for which there is no separate scp command-line flag. For example, forcing the use of protocol version 1 is specified using scp -oProtocol=1
-4
Forces scp to use IPv4 addresses only.
-6
Forces scp to use IPv6 addresses only.
Link to Web Resources: http://linux.about.com/od/commands/l/blcmdl1_scp.htm
Sample Code:Copy the local file user.server1.pub to the remote system server2, putting it in james’s home directory:
$ scp user.server1.pub james@server2:/home/james/
DISCOVERY EXERCISES
1: NAVIGATING THE FILE SYSTEM:
A: srw-rw-rw- 1 root root 0 2010-04-05 08:52 /dev/log
2: EXPLORING THE /dev DIRECTORY
A: ET06:/home/eugene # ls -l /dev/fd0 /dev/fd1
ls: cannot access /dev/fd1: No such file or directory
brw-rw—- 1 root floppy 2, 0 2010-04-05 08:52 /dev/fd0
3: VIEWING AND TESTING HIDDEN ENVIRONMENTAL FILES:
A: The hidden files have filenames that start with a period.
B: /sbin/yast2
su root
display=:0 xcalc -g 400×450-300+300 &
/var/log/XFree86.0.log file
init 3
su
root
su
root
dvd
su
su
touch new_file
su
exit
su
ls -l tmp
ls -l /tmp
su
type ll
whereis -m find
which kfind
kfind &
grep”" /usr/share/doc/release-notes/RELEASE-NOTES.en.html
grep “” /usr/share/doc/release-notes/RELEASE-NOTES.en.html
grep “”/usr/share/doc/release-notes/RELEASE-NOTES.en.html
/bin
su
C: eugene@ET06:~> echo “echo Welcome to your Login Shell”>>.profile
eugene@ET06:~> tail .profile
# Some people don’t like fortune. If you uncomment the following lines,
# you will have a fortune each time you log in
#if [ -x /usr/bin/fortune ] ; then
# echo
# /usr/bin/fortune
# echo
#fi
echo Welcome to your Login Shell
4: exploring the more command to view /PROC
A:
Discovery Questions
1) cd /etc/sysconfig then ls /etc/sysconfig
2) cd /directory
3) cd /var/lib directory
4) cd /etc/sysconfig directory
5) . .
6) ls -l /dev/config file