User:Altro971

= Command-line interpreter = In computing, a command is a directive to a computer program to perform a specific task.

It may be issued via a command-line interface, such as a shell, or as input to a network service as part of a network protocol, or as an event in a graphical user interface triggered by the user selecting an option in a menu.

= Basic Linux Commands = ● ls - Lists directory contents.

● cd - Changes the current directory.

● pwd - Displays the present working directory.

● cat - Concatenates and displays files.

● echo - Displays arguments to the screen.

● man - Displays the online manual.

● exit - Exits the shell or your current session.

● clear - Clears the screen.

Directory tree
"a directory contained inside another directory is called a sub directory. The terms parent and child are often used to describe the relationship between a sub directory and the directory in which it is cataloged, the latter being the parent. The top-most directory in such a file system, which does not have a parent of its own, is called the root directory."

Example : 1 directories, 6 files
path/to/folder/ ├── a-first.html ├── b-second.html ├── subfolder │  ├── readme.html │  ├── code.cpp │  └── code.h └── z-last-file.html

ls(list_Unix)
"ls is a command to list computer files in Unix and Unix-like operating systems"

Usage
The most common options to reveal this information or change the list of files are: ·       -l        long format, ·        -f       do not sort. Useful for directories containing large numbers of files. ·        -F       appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix. ·        -a       lists all files in the given directory, including "." (which are hidden files in Unix). ·        -R       recursively lists sub directories. The command ls -R / would therefore list all files. ·        -d       shows information about a symbolic link or directory. ·        -t       sort the list of files by modification time. ·        -h       print sizes in human readable format. (e.g., 1K, 234M, 2G, etc ·        -1       (the numeric digit one) force output to be one entry per line.

File Permission:Decoding ls -l Output
$ ls -l

-rw-rw-r-- 1 jason users 10400 Sep 27 08:52 sales.data Permissions -rw-rw-r--

Number of links 1

Owner name jason

Group name users

Number of bytes in the file 10400

Last modification time Sep 27 08:52

File name sales.data

Example:
·d  : drafts is a directory (denoted by the file descriptor d). ·rwx: the owner (user) has the right to read (r), write (w) and execute (x). ·rw-: group members (users part of the editors group) have read and write (w) permissions;execute are not permitted. ·r--: others (users aside from the owner or members of editors) have read-only permissions; write and execute are not permitted, as denoted by the hyphen characters (-).

cd (command)
The  command, also known as   (change directory)

Usage
user@wikipedia:~$ ls                                                                                                                                                                                workreports games encyclopedia text.txt                                                                                                               user@wikipedia:~$ cd games                                                                                                                                       user@wikipedia:~/games$ "A similar session in DOS (though the concept of a 'home directory' may not apply, depending on the specific version) would look like this:" C:\> dir                                                                                                                                                workreports               Wed Oct 9th   9:01                                                                                         games                     Tue Oct 8th  14:32                                                                                           encyclopedia              Mon Oct 1st  10:05                                                                                          text                txt   1903 Thu Oct10th  12:43                                                                                                                C:\> cd games                                                                                                                                                                         C:\games>

Pwd
Unix examples[edit]

= Help commands = Man is used to display documentation.

● $PATH controls your search path.

● Learn the full path to commands with which.

● Ask commands for help with --help or -h.

● Search man pages by using man -k.

Apropos (Unix) or
apropos - search the manual page names and descriptions

Sample usage
The following example demonstrates the output of the  command: $ apropos mount free (1)            - Display amount of free and used memory in the system mklost+found (8)    - create a lost+found directory on a mounted Linux second extended file system mount (8)           - mount a file system mountpoint (1)      - see if a directory is a mountpoint ntfsmount (8)       - Read/Write userspace NTFS driver. sleep (1)           - delay for a specified amount of time switch_root (8)     - switch to another filesystem as the root of the mount tree. umount (8)          - unmount file systems regexp keyword (abc.n) and a regular keyword: $ apropos abc.n xzless XTestGrabControl (3) - XTest extension functions xzless (1)          - view xz or lzma compressed (text) files

man page
A man page (short for manual page) is a form of software documentation usually found on a Unix or Unix-like operating system. Topics covered include computer programs (including library and system calls), formal standards and conventions, and even abstract concepts. A user may invoke a man page by issuing the  command.

Command usage
To read a manual page for a Unix command, a user can type: man 

= Creating and Removing Directories = mkdir [-p] directory - Create a directory.

rmdir [-p] directory - Remove a directory.

rm -rf directory - Recursively removes directory.

= Displaying the Contents of Files = Display the contents of file.

Browse through a text file.

More features than more.

Output the beginning (or top) portion of file.

Output the ending (or bottom) portion of file.

The Vi Editor
vi [file] Edit file.

vim [file] Same as vi, but more features.

view [file] Starts vim in read-only mode.

Vi Line Mode








Write and quit.



Emacs
● Emacs is Powerful editor.

● Some people prefer vi, other emacs.

● Either are great editors.

● Use what feels comfortable to you.

emacs [file] Edit file.

C- Ctrl while pressing.

M- "Meta" key (alt key) while

pressing.

M- Esc, then type

Graphical Editors
● emacs Emacs has a graphical mode too.

● gedit The default text editor for Gnome.

● gvim The graphical version of vim.

● kedit The default text editor for the KDE.

● AbiWord Microsoft Word alternative.

● LibreOffice Full office suite.

● Kate Source code editor.

Summary
● Various graphical editors exist for Linux.

● Graphical modes exist for emacs and vi.

Cat (Unix)
its function to concatenate files

Vi or Vim
"vim - Vi IMproved, a programmers text editor" It can be used to edit all kinds of plain text.It is especially useful for editing programs. SYNOPSIS vim [options] [file ..] vim [options] - vim [options] -t tag vim [options] -q [errorfile] ex gex view gvim gview vimx evim eview rvim rview rgvim rgview

example:
$ vi text.txt Press i or insert and type your text and click esc and enter :wq! for quit

caution
Another program may be editing the same file. If this is the case,be careful not to end up with two different instances of the same file when making changes.

If edit session for this file crashed use ":recover" or "vim -r text.txt"to recover the changes (see ":help recovery").If you did this already, delete the swap file ".text.txt.swp".

= Deleting, Copying, Moving, and Renaming Files = ● rm

● cp

● mv

● gzip

gzcat Concatenates compressed files.

zcat Concatenates compressed files.

● tar

Cp (Unix)
copying files and directories

Usage
Copying a file to another file: cp [-fHip][--] sourcefile targetfile Copying file(s) to a directory cp [-fHip] [--] sourcefile... targetdirectory Copying a directory to a directory (-r or -R must be used) cp -r|-R [-fHip] [--]  sourcedirectory... targetdirectory

Examples
Creating a copy of a file in the current directory: cp prog.c prog.bak Copy two files in the current directory into another directory: cp jones smith /home/nick/clients Copy a file to a new file and preserve the modification date, time, and access control list associated with the source file: cp -p smith smith.jr Copy a directory, including all its files and subdirectories, to another directory: cp -R /home/nick/clients /home/nick/customers

Mv(Unix)
mv (short for move) is a Unix command that moves one or more files or directories from one place to another. SYNOPSIS mv [OPTION]... [-T] SOURCE DEST mv [OPTION]... SOURCE... DIRECTORY mv [OPTION]... -t DIRECTORY SOURCE... Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

gzip(unix)
gzip, gunzip, zcat - compress or expand named files.

Compressed files can be restored to their original form using gzip -d or gunzip or zcat.

command to zip:
gzip 

command to unzip(decompress):
gzip -d 

tar(unix) --Archive
‘ tar’  saves many files together into a single tape or disk archive, and can restore individual files from the archive.

EXAMPLES
tar -cf archive.tar foo bar # Create archive.tar from files foo and bar. tar -tvf archive.tar # List all files in archive.tar verbosely. tar -xf archive.tar # Extract all files from archive.tar. Main operation mode: -A, --catenate, --concatenate append tar files to an archive -c, --create create a new archive -d, --diff, --compare find differences between archive and file system --delete delete from the archive (not on mag tapes!) -r, --append append files to the end of an archive -t, --list list the contents of an archive --test-label test the archive volume label and exit -u, --update only append files newer than copy in archive -x, --extract, --get extract files from an archive

= Wildcards = ● A character or string used for pattern matching.

● Globbing expands the wildcard pattern into a list of files and/or directories. (paths)

● Wildcards can be used with most commands.

● * - matches zero or more characters.
○ *.txt

○ a*

○ a*.txt

● ? - matches exactly one character.
○ ?.txt

○ a?

○ a?.txt

More Wildcards - Character Classes

● [] - A character class.
○ Matches any of the characters included between the brackets. Matches exactly one character.

○ [aeiou]

○ ca[nt]*

■ can

■ cat

■ candy

■ catch

More Wildcards - Character Classes

● [!] - Matches any of the characters NOT included between the brackets. Matches exactly one character.
○ [!aeiou]*

■ baseball

■ cricket

More Wildcards - Ranges

● Use two characters separated by a hyphen to

create a range in a character class.

● [a-g]*

○ Matches all files that start with a, b, c, d, e, f, or g.

● [3-6]*

○ Matches all files that start with 3, 4, 5 or 6.

Named Character Classes
● alpha:

● alnum:

● digit:

● lower:

● space:

● upper:

Matching Wildcard patterns

● \ - escape character. Use if you want to match

a wildcard character.

○ Match all files that end with a question mark:

■ *\?

● done?

Input/Output Types
standard streams are interconnected input and output communication channels between a computer program and its environment when it begins execution.

Standard Input stdin 0
Standard input is a stream from which a program reads its input data. The program requests data transfers by use of the read operation. Not all programs require stream input.

Standard Output stdout 1
Standard output is a stream to which a program writes its output data. The program requests data transfer with the write operation. Not all programs generate output. For example, the file rename command (variously called mv, move, or ren) is silent on success.

Standard Error stderr 2
Standard error is another output stream typically used by programs to output error messages or diagnostics. It is a stream independent of standard output and can be redirected separately.

Redirection
Redirects standard output to a file.

Overwrites (truncating) existing contents. >> Redirects standard output to a file. Appends to any existing contents.

Redirects input from a file to a command.

Used with redirection to signal that a file descriptor is being used.

Combine stderr and standard output.

Redirect standard error to a file.

The Null Device
>/dev/null Redirect output to nowhere. $ ls here not-here 2> /dev/null here $ ls here not-here > /dev/null 2>&1

= Comparing the Contents of Files = diff file1 file2 Compare two files.

sdiff file1 file2 Side-by-side comparison.

vimdiff file1 file2 Highlight differences in vim.

= Searching in Files and Using Pipes = ● grep

● file

● cut

● tr

● column

● more

● less

● Pipes

Grep(unix)
is a command-line utility for searching plain-text data sets for lines that match a regular expression.

command g/re/p (globally search for a regular expression and print matching lines) It searches files for specified words or patterns

The grep command is case sensitive

To ignore upper/lower case distinctions, use the -i option, i.e. type

Sample usage
The following example demonstrates the output of the  command given different arguments $ grep -i science science.txt

recursive grep
Contains Doesn't Contain Find Occurrences and output to CSV Find Occurrences and output to CSV with prepended string

agrep (approximate grep)
"agrep (approximate grep) matches even when the text only approximately fits the search pattern."This following invocation finds net masks in file my file, but also any other word that can be derived from it, given no more than two substitutions. agrep -2 netmasks myfile This example generates a list of matches with the closest, that is those with the fewest, substitutions listed first. The command flag B means best: agrep -B netmasks myfile

file (command)-- determine file type
''file tests each argument in an attempt to classify it. There are three sets of tests, performed in this order:'' file system tests, magic tests, language tests."Classifies the named files according to the type of data they contain."

Examples
$ To report on all files in your home directory $file * LinkSource.txt: ASCII text, with CRLF line terminators Loc1:          directory copytext.txt:  ASCII text, with no line terminators

$ file file.c file.c: C program text

$ file program program: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), stripped

$ file /dev/hda1 /dev/hda1: block special (0/0)

$ file -s /dev/hda1 /dev/hda1: Linux/i386 ext2 filesystem

More (command)
  is a command to view (but not modify) the contents of a text file one screen at a time.

Usage(Unix)
more [options] [file_name] If no file name is provided,  looks for input from standard input.

Less (Unix)
  used to view (but not change) the contents of a text file one screen at a time. It is similar to, but has the extended capability of allowing both forward and backward navigation through the file.

Users should realize that less provides more emulation plus extensive enhancements.

Usage
less [options] [file_name]

Frequently used options[edit]

 * : Highlight just the current match of any searched string.
 * : Search case-insensitively.
 * : Show more detailed prompt, including file position.
 * : Show line numbers (useful for viewing source code).
 * : Set tabstops (the number of columns per hard tab character) to the specified number (3, in this example) (useful for viewing source code).
 * : Disable line wrapping ("chop long lines"). Long lines can be seen by side-scrolling.
 * : Leave file contents on screen when less exits.
 * : Show help.
 * : Follow mode, for log files that get replaced while being viewed

Examples
less -M readme.txt          # Read "readme.txt" less +F /var/log/mail.log   # Follow mode for log file * | less               # Easier file analysis less -I -g void *.c         # Case insensitive search for "void" in all .c files

= Copying Files over the Network = ● SCP - Secure copy

● SFTP - SSH file transfer protocol

● PuTTY Secure Copy client - pscp.exe

● PuTTY Secure File Transfer client - psftp.exe

Graphical SCP/SFTP Clients

● Cyberduck

● FileZilla

● WinSCP

scp / sftp command line utilities
scp source destination

Copy source to destination.

sftp host

Start a secure file transfer session with host.

sftp jason@host

ftp Command Line Utility

ftp host

Start a file transfer session with host.

Summary
● Transfer files using a client.

● Command line clients: scp, sftp, ftp.

● Graphical clients: Cyberduck, FileZilla.

● Use scp or sftp over ftp when possible.

= Process Management = sudo

Top

Ps

sar

iostat

free

kill

who

df

du

id

sort

link

sudo(Unix)
security privileges of another user, by default the superuser

It originally stood for "superuser do"

Usage example
sudo su - wladmin ---> super user as web logic admin Running ssh command: sudo su - wladmin -c '/apps/xxx/xxx/xxxxxxx.cmd'

top(table of processes)
top (table of processes) is a task manager program, found in many Unix-like operating systems, that displays information about CPU and memory utilization.

SYNOPSIS top -hv|-bcHiOSs -d secs -n max -u|U user -p pid -o fld -w [cols]

The traditional switches `-' and white space are optional. When operating top, the two most important keys are the help (h or ?)  key and quit ('q') key. Alternatively, you could simply use the traditional interrupt key (^C) when you're done.

Startup Defaults
''items shown with an asterisk (`*') could be overridden through the command-line. All are explained in detail in the sections that follow.''

Global-defaults
Global-defaults A - Alt display     Off (full-screen) * d - Delay time      1.5 seconds * H - Threads mode    Off (summarize as tasks) I - Irix mode       On  (no, `solaris' smp) * p - PID monitoring  Off (show all processes) * s - Secure mode     Off (unsecured) B - Bold enable     On  (yes, bold globally)

Summary-Area-defaults
l - Load Avg/Uptime On  (thus program name) t - Task/Cpu states On  (1+1 lines, see `1') m - Mem/Swap usage  On  (2 lines worth) 1 - Single Cpu      Off (thus multiple cpus)

Task-Area-defaults
b - Bold hilite     Off (use `reverse') * c - Command line    Off (name, not cmdline) * i - Idle tasks      On  (show all tasks) J - Num align right On  (not left justify) j - Str align right Off (not right justify) R - Reverse sort    On  (pids high-to-low) * S - Cumulative time Off (no, dead children) * u - User filter     Off (show euid only) * U - User filter     Off (show any uid) V - Forest view     On  (show as branches) x - Column hilite   Off (no, sort field) y - Row hilite      On  (yes, running tasks) z - color/mono      On  (show colors)

---use manual command for info

Ps - (short for "process status")
"ps displays information about a selection of the active processes.  If you want a repetitive update of the selection and the displayed information, use top(1) instead."

EXAMPLES
To see every process on the system using standard syntax: ps -e ps -ef ps -eF ps -ely "To print a process tree:" ps -ejH                                                                                                                                        ps axjf Users can also utilize the  command in conjunction with the   command to find information about a single process, such as its id: $ # Trying to find the PID of `firefox-bin` which is 2701 $ ps -A | grep firefox-bin 2701 ?       22:16:04 firefox-bin The use of  simplifies the syntax and avoids potential race conditions: $ pgrep -l firefox-bin 2701 firefox-bin To see every process running as root in user format: USER  PID  %CPU %MEM    VSZ   RSS TT  STAT STARTED        TIME COMMAND root    1   0.0  0.0   9436   128  -  ILs  Sun00AM     0:00.12 /sbin/init --
 * 1) ps -U root -u

sar (Unix)
System Activity Report :Collect, report, or save system activity information. "sar command is used to get the usage history of system resource such as CPU, RAM, SWAP, IO etc. /var/log/sa/ directory contains the information of system usage for the specified number of days as per OS configuration."

Syntax
sar [-flags] [ -e time ] [ -f filename ] [-i sec ] [ -s time ]


 * -f
 * filename Uses filename as the data source for sar. The default is the current daily data file /var/adm/sa/sadd.


 * -e
 * time Selects data up to time. The default is 18:00.


 * -i
 * sec Selects data at intervals as close as possible to sec seconds.

Example
[user@localhost]$ sar # Displays current CPU activity.

pgrep, pkill
pgrep, pkill - look up or signal processes based on name and other attributes" pgrep  looks  through  the currently running processes and lists the process IDs which match the selection criteria to stdout. All the criteria have to match.  pkill will send the specified signal (by default SIGTERM) to each process instead of listing them on stdout. "

example;
$ pgrep -u root sshd will only list the processes called sshd AND owned by root. On the other hand, $ pgrep -u root,daemon will list the processes owned by root OR daemon.

iostat
iostat (input/output statistics) is a computer system monitor tool used to collect and show operating system storage input and output statistics.

''The iostat command is used for monitoring system input/output device loading by observing the time the devices are active in  relation to their average transfer rates. The iostat command generates reports that can be used to change system configuration to better balance the input/output load between physical disks.''

Syntax and availability
displays output where each line (row) gives numerical data for one device.

iostat -x 30 - It is best to run  specifying a time interval in seconds

iostat –En -To check san storage external disk iostat [ -c ] [ -d ] [ -h ] [ -k | -m ] [ -N ] [ -t ] [ -V ] [ -x ] [ -y ] [ -z ] [ -j { ID | LABEL | PATH | UUID | ... } ]         [ [ -T] -g group_name ] [ -p [ device [,...] | ALL ] ] [ device [...] | ALL ] [ interval [ count ] ]

The iostat command generates two types of reports, the CPU Utilization report and the Device Utilization report.

Free (unix)
free - Display amount of free and used memory in the system "free  displays  the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel. The information is gathered by parsing /proc/meminfo."

example
wladmin@user# free -g total       used        free      shared  buff/cache   available Mem:            15          11           1           0           2           3 Swap:            7           0           7

Usage: free [options] Options: -h, --human        show human-readable output --si           use powers of 1000 not 1024 -l, --lohi         show detailed low and high memory statistics -t, --total        show total for RAM + swap -s N, --seconds N  repeat printing every N seconds -c N, --count N    repeat printing N times, then exit -w, --wide         wide output -V, --version output version information and exit

Kill (command)
"kill - terminate a process The  command kill sends the specified signal to the specified process or process group.If no signal is specified, the TERM signal is sent.The TERM signal will kill processes which do not catch this signal.  For other processes, it may be necessary to use  the KILL (9) signal, since this signal cannot be caught." kill -9

Swap(Unix)

 * 1) swap -s To view the summary of the current swap space allocation total:                                                               106256k bytes allocated + 8512k reserved = 114768k used, 587512k available

/dev/dsk/c0t0d0s1 136,1 16 1206736 1084736 /export/data/swapfile -16 40944 40944
 * 1) swap –l --- To list details of the system’s virtual swap space: swapfile dev swaplo blocks free

Who (Unix)
w ho - show who is logged on

Print information about users who are currently logged in.
-a, --all same as -b -d --login -p -r -t -T -u -b, --boot time of last system boot -d, --dead print dead processes -H, --heading print line of column headings

Df (Unix)
df (abbreviation for disk free) is a standard Unix command used to display the amount of available disk space for file systems

Example
The following is an example of the output of the df command. $ df Filesystem   1024-blocks      Free %Used    Iused %Iused Mounted on /dev/hd4            32768     16016   52%     2271    14% / /dev/hd2         4587520   1889420   59%    37791     4% /usr /dev/hd9var        65536     12032   82%      518     4% /var /dev/hd3          819200    637832   23%     1829     1% /tmp /dev/hd1          524288    395848   25%      421     1% /home /proc                  -         -    -         -     -  /proc /dev/hd10opt       65536     26004   61%      654     4% /opt

du (Unix):  summarize disk usage
(abbreviated from disk usage) is a standard Unix program used to estimate file space usage—space used under a particular directory or files on a file system.

Usage
takes a single argument, specifying a path name for du to work; if it is not specified, the current directory is used

Examples
du [OPTION]... [FILE]... du [OPTION]... --files0-from=F

[OPTION] -S, --separate-dirs ->for directories do not include size of sub directories -s, --summarize ->display only a total for each argument

disk usage of all sub directories and files including hidden files within the current directory (sorted by reverse file size) :               $ du -sk .[!.]* *| sort -nr

id
Return user identity

To check for user present are not id -a :  gives the details of the uid, gid, groups

id   : gives the details of the uid, gid

sort (Unix)
prints the lines of its input or concatenation of all files listed in its argument list in sorted order

Syntax
sort [OPTION]... [FILE]... With no, or when   is  , the command reads from standard input.

passwd
passwd is used to change a user's password

An example record may be:
jsmith:x:1001:1000:Joe Smith,Room 1007,(234)555-8910,(234)555-0044,email:/home/jsmith:/bin/sh The fields, in order from left to right, are:

1. : User name

2. : Information used to validate a user's password;

3. : user identifier number, used by the operating system for internal purposes. It need not be unique.

4. : group identifier number, which identifies the primary group of the user

5. : Gecos field, commentary that describes the person or account.

6. : Path to the user's home directory.

7. : Program that is started every time the user logs into the system.

link (Unix)
link - call the link function to create a link to a file link FILE1 FILE2 link OPTION

Ln (Unix)
ln - make links between files-Create hard link by default. ln [OPTION]... [-T] TARGET LINK_NAME  (1st form)--create a link to TARGET with the name LINK_NAME ln [OPTION]... TARGET                 (2nd form)--create a link to TARGET in the current directory. ln [OPTION]... TARGET... DIRECTORY    (3rd form)--create links to each TARGET in DIRECTORY ln [OPTION]... -t DIRECTORY TARGET... (4th form)--create links to each TARGET in DIRECTORY

symbolic Link
-s, --symbolic make symbolic links instead of hard links

pushd and popd
The  command saves the current working directory in memory so it can be returned to at any time, optionally changing to a new directory.

Syntax
pushd [path | ..] This optional command-line argument specifies the directory to make the current directory. If  is omitted, the path at the top of the directory stack is used, which has the effect of toggling between two directories.

Popd
popd

Bourne shell
The Bourne shell is a shell command-line interpreter for computer operating systems.

—which will be the Bourne shell, or a symbolic link or hard link to a compatible shell—even when other shells are used by most users.

IO Redire­ction
{| class="wikitable"

File Permission Numbers

 * }

1 – SYSTEM INFORMATION
uname -a uname -r cat /etc/redhat-release uptime hostname hostname -I last reboot date cal w whoami
 * 1) Display Linux system information
 * 1) Display kernel release information
 * 1) Show which version of redhat installed
 * 1) Show how long the system has been running + load
 * 1) Show system host name
 * 1) Display the IP addresses of the host
 * 1) Show system reboot history
 * 1) Show the current date and time
 * 1) Show this month's calendar
 * 1) Display who is online
 * 1) Who you are logged in as

2 – HARDWARE INFORMATION
dmesg cat /proc/cpuinfo cat /proc/meminfo free -h lspci -tv lsusb -tv dmidecode hdparm -i /dev/sda hdparm -tT /dev/sda badblocks -s /dev/sda
 * 1) Display messages in kernel ring buffer
 * 1) Display CPU information
 * 1) Display memory information
 * 1) Display free and used memory ( -h for human readable, -m for MB, -g for GB.)
 * 1) Display PCI devices
 * 1) Display USB devices
 * 1) Display DMI/SMBIOS (hardware info) from the BIOS
 * 1) Show info about disk sda
 * 1) Perform a read speed test on disk sda
 * 1) Test for unreadable blocks on disk sda

3 – PERFORMANCE MONITORING AND STATISTICS
top htop mpstat 1 vmstat 1 iostat 1 tail 100 /var/log/messages tcpdump -i eth0 tcpdump -i eth0 'port 80' lsof lsof -u user free -h watch df -h
 * 1) Display and manage the top processes
 * 1) Interactive process viewer (top alternative)
 * 1) Display processor related statistics
 * 1) Display virtual memory statistics
 * 1) Display I/O statistics
 * 1) Display the last 100 syslog messages  (Use /var/log/syslog for Debian based systems.)
 * 1) Capture and display all packets on interface eth0
 * 1) Monitor all traffic on port 80 ( HTTP )
 * 1) List all open files on the system
 * 1) List files opened by user
 * 1) Display free and used memory ( -h for human readable, -m for MB, -g for GB.)
 * 1) Execute "df -h", showing periodic updates

4 – USER INFORMATION AND MANAGEMENT
id last who w groupadd test useradd -c "John Smith" -m john userdel john usermod -aG sales john
 * 1) Display the user and group ids of your current user.
 * 1) Display the last users who have logged onto the system.
 * 1) Show who is logged into the system.
 * 1) Show who is logged in and what they are doing.
 * 1) Create a group named "test".
 * 1) Create an account named john, with a comment of "John Smith" and create the user's home directory.
 * 1) Delete the john account.
 * 1) Add the john account to the sales group

5 – FILE AND DIRECTORY COMMANDS
ls -al pwd mkdir directory rm file rm -r directory rm -f file rm -rf directory cp file1 file2 cp -r source_directory destination mv file1 file2 ln -s /path/to/file linkname touch file cat file less file head file tail file tail -f file
 * 1) List all files in a long listing (detailed) format
 * 1) Display the present working directory
 * 1) Create a directory
 * 1) Remove (delete) file
 * 1) Remove the directory and its contents recursively
 * 1) Force removal of file without prompting for confirmation
 * 1) Forcefully remove directory recursively
 * 1) Copy file1 to file2
 * 1) Copy source_directory recursively to destination. If destination exists, copy source_directory into destination, otherwise create destination with the contents of source_directory.
 * 1) Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2
 * 1) Create symbolic link to linkname
 * 1) Create an empty file or update the access and modification times of file.
 * 1) View the contents of file
 * 1) Browse through a text file
 * 1) Display the first 10 lines of file
 * 1) Display the last 10 lines of file
 * 1) Display the last 10 lines of file and "follow" the file as it grows.

6 – PROCESS MANAGEMENT
ps ps -ef ps -ef | grep processname top htop kill pid killall processname program & bg fg fg n
 * 1) Display your currently running processes
 * 1) Display all the currently running processes on the system.
 * 1) Display process information for processname
 * 1) Display and manage the top processes
 * 1) Interactive process viewer (top alternative)
 * 1) Kill process with process ID of pid
 * 1) Kill all processes named processname
 * 1) Start program in the background
 * 1) Display stopped or background jobs
 * 1) Brings the most recent background job to foreground
 * 1) Brings job n to the foreground

7 – FILE PERMISSIONS
PERMISSION      EXAMPLE U   G   W         rwx rwx rwx     chmod 777 filename rwx rwx r-x     chmod 775 filename rwx r-x r-x     chmod 755 filename rw- rw- r--     chmod 664 filename rw- r-- r--     chmod 644 filename LEGEND U = User G = Group W = World r = Read w = write x = execute - = no access
 * 1) NOTE: Use 777 sparingly!

8 – NETWORKING
ifconfig -a ifconfig eth0 ethtool eth0 ping host whois domain dig domain dig -x IP_ADDRESS host domain hostname -i hostname -I wget http://domain.com/file netstat -nutlp
 * 1) Display all network interfaces and ip address
 * 1) Display eth0 address and details
 * 1) Query or control network driver and hardware settings
 * 1) Send ICMP echo request to host
 * 1) Display whois information for domain
 * 1) Display DNS information for domain
 * 1) Reverse lookup of IP_ADDRESS
 * 1) Display DNS ip address for domain
 * 1) Display the network address of the host name.
 * 1) Display all local ip addresses
 * 1) Download http://domain.com/file
 * 1) Display listening tcp and udp ports and corresponding programs

9 – ARCHIVES (TAR FILES)
tar cf archive.tar directory tar xf archive.tar tar czf archive.tar.gz directory tar xzf archive.tar.gz tar cjf archive.tar.bz2 directory tar xjf archive.tar.bz2
 * 1) Create tar named archive.tar containing directory.
 * 1) Extract the contents from archive.tar.
 * 1) Create a gzip compressed tar file name archive.tar.gz.
 * 1) Extract a gzip compressed tar file.
 * 1) Create a tar file with bzip2 compression
 * 1) Extract a bzip2 compressed tar file.

10 – INSTALLING PACKAGES
yum search keyword yum install package yum info package rpm -i package.rpm yum remove package tar zxvf sourcecode.tar.gz cd sourcecode ./configure make make install
 * 1) Search for a package by keyword.
 * 1) Install package.
 * 1) Display description and summary information about package.
 * 1) Install package from local file named package.rpm
 * 1) Remove/uninstall package.
 * 1) Install software from source code.

11 – SEARCH
grep pattern file grep -r pattern directory locate name find /home/john -name 'prefix*' find /home -size +100M
 * 1) Search for pattern in file
 * 1) Search recursively for pattern in directory
 * 1) Find files and directories by name
 * 1) Find files in /home/john that start with "prefix".
 * 1) Find files larger than 100MB in /home

12 – SSH LOGINS
ssh host ssh user@host ssh -p port user@host
 * 1) Connect to host as your local username.
 * 1) Connect to host as user
 * 1) Connect to host using port

13 – FILE TRANSFERS
scp file.txt server:/tmp scp server:/var/www/*.html /tmp scp -r server:/var/www /tmp rsync -a /home /backups/ rsync -avz /home server:/backups/
 * 1) Secure copy file.txt to the /tmp folder on server
 * 1) Copy *.html files from server to the local /tmp folder.
 * 1) Copy all files and directories recursively from server to the current system's /tmp folder.
 * 1) Synchronize /home to /backups/home
 * 1) Synchronize files/directories between the local and remote system with compression enabled

14 – DISK USAGE
df -h df -i fdisk -l du -ah du -sh
 * 1) Show free and used space on mounted filesystems
 * 1) Show free and used inodes on mounted filesystems
 * 1) Display disks partitions sizes and types
 * 1) Display disk usage for all files and directories in human readable format
 * 1) Display total disk usage off the current directory

15 – DIRECTORY NAVIGATION
cd .. cd cd /etc
 * 1) To go up one level of the directory tree.  (Change into the parent directory.)
 * 1) Go to the $HOME directory
 * 1) Change to the /etc directory

= Q & A =

How to search the file for specified word or keywords?